107 lines
2.2 KiB
C++
107 lines
2.2 KiB
C++
|
|
#include "ftvector.hpp"
|
|
|
|
#define COPLIEN_COLOR B_CYAN
|
|
|
|
/*********************************************
|
|
* CONSTRUCTORS
|
|
*********************************************/
|
|
|
|
ftvector::ftvector()
|
|
: _size(0)
|
|
, _space(0) {
|
|
// std::cout << COPLIEN_COLOR "ftvector constructor" RESET "\n";
|
|
_allocator = std::allocator<int>();
|
|
return;
|
|
}
|
|
|
|
ftvector::ftvector( ftvector const & src ) {
|
|
// std::cout << COPLIEN_COLOR "ftvector copy constructor" RESET "\n";
|
|
*this = src;
|
|
return;
|
|
}
|
|
|
|
/*********************************************
|
|
* DESTRUCTORS
|
|
*********************************************/
|
|
|
|
ftvector::~ftvector() {
|
|
// std::cout << COPLIEN_COLOR "ftvector destructor" RESET "\n";
|
|
return;
|
|
}
|
|
|
|
/*********************************************
|
|
* OPERATORS
|
|
*********************************************/
|
|
|
|
ftvector & ftvector::operator=( ftvector const & rhs ) {
|
|
// Base::operator=(rhs);
|
|
if ( this != &rhs )
|
|
{
|
|
_size = rhs.size();
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
//std::ostream & operator<<(std::ostream & o, ftvector const & rhs)
|
|
//{
|
|
// o << rhs.getFoo();
|
|
// return (o);
|
|
//}
|
|
|
|
/*********************************************
|
|
* ACCESSORS
|
|
*********************************************/
|
|
|
|
unsigned int ftvector::size() const {return _size;}
|
|
|
|
/*********************************************
|
|
* PUBLIC MEMBER FUNCTIONS
|
|
*********************************************/
|
|
|
|
void ftvector::push_back(const int & element) {
|
|
if (_size == _space)
|
|
hold_space(1);
|
|
_allocator.construct(&_mem_ptr[_size], element);
|
|
_size++;
|
|
|
|
for (unsigned int i = 0; i < _size; i++)
|
|
std::cout << _mem_ptr[i] << "\n";
|
|
std::cout << "\n";
|
|
|
|
}
|
|
|
|
/*********************************************
|
|
* PRIVATE MEMBER FUNCTIONS
|
|
*********************************************/
|
|
|
|
void hold_space(std::size_t add_space) {
|
|
|
|
if (add_space == 0)
|
|
return ;
|
|
|
|
int * tmp_ptr;
|
|
|
|
if (_space > 0 && add_space == 1)
|
|
{
|
|
add_space = _space * 2;
|
|
}
|
|
|
|
tmp_ptr = _allocator.allocate(add_space);
|
|
// _mem_ptr = _allocator.allocate(add_space);
|
|
}
|
|
|
|
/*********************************************
|
|
* NESTED CLASS
|
|
*********************************************/
|
|
|
|
//void ftvector::Class::function() {}
|
|
|
|
/*********************************************
|
|
* STATICS
|
|
*********************************************/
|
|
|
|
//std::string const ftvector::_bar = "bar";
|
|
|
|
|