diff --git a/headers/ftvector.hpp b/headers/ftvector.hpp index 155ad15..eace0eb 100644 --- a/headers/ftvector.hpp +++ b/headers/ftvector.hpp @@ -15,17 +15,92 @@ public: ~ftvector(); ftvector & operator=( ftvector const & rhs ); - unsigned int size() const; - void push_back(const int & element); + + /************* + * iterators : + *************/ + // begin +// iterator begin(); +// const_iterator begin() const; + // end +// iterator end(); +// const_iterator end() const; + // rbegin +// reverse_iterator rbegin(); +// const_reverse_iterator rbegin() const; + // rend +// reverse_iterator rend(); +// const_reverse_iterator rend() const; + + /************ + * capacity : + ************/ + // size + // TMP + unsigned int size() const; + // TMP END +// size_type size() const; + // max_size +// size_type max_size() const; + // resize +// void resize(size_type n, value_type val = value_type()); + // capacity + size_type capacity() const; + // empty +// bool empty() const; + //reserve +// void reserve(size_type n); + + /****************** + * element access : + ******************/ + // operator[] +// reference operator[](size_type n); +// const_reference operator[](size_type n) const; + // at +// reference at(size_type n); +// const_reference at(size_type n) const; + // front +// reference front(); +// const_reference front() const; + // back +// reference back(); +// const_reference back() const; + + /************* + * modifiers : + *************/ + // assign +// template +// void assign(InputIterator first, InputIterator last); +// void assign(size_type n, const value_type& val); + // push_back + // TMP + void push_back(const int & element); + // TMP END +// void push_back(const value_type& val); + // pop_back +// void pop_back(); + // insert +// iterator insert(iterator position, const value_type& val); +// void insert(iterator position, size_type n, const value_type& val); +// template +// void insert(iterator position, InputIterator first, InputIterator last); + // erase +// iterator erase(iterator position); +// iterator erase(iterator first, iterator last); + // swap +// void swap(vector& x); + // clear +// void clear(); + private: - unsigned int _size; + std::size_t _size; int * _mem_ptr; std::allocator _allocator; -// static std::string const ftvector::_bar; - }; //std::ostream & operator<<(std::ostream & o, ftvector const & rhs); diff --git a/srcs/ftvector.cpp b/srcs/ftvector.cpp index a566614..fcc3e95 100644 --- a/srcs/ftvector.cpp +++ b/srcs/ftvector.cpp @@ -1,14 +1,3 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ftvector.cpp :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: simplonco +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/06/01 15:39:26 by simplonco #+# #+# */ -/* Updated: 2022/06/01 15:39:57 by simplonco ### ########.fr */ -/* */ -/* ************************************************************************** */ #include "ftvector.hpp" @@ -18,8 +7,9 @@ * CONSTRUCTORS *********************************************/ -ftvector::ftvector() : -_size(0) { +ftvector::ftvector() +: _size(0) +, _space(0) { // std::cout << COPLIEN_COLOR "ftvector constructor" RESET "\n"; _allocator = std::allocator(); return; @@ -70,9 +60,35 @@ unsigned int ftvector::size() const {return _size;} *********************************************/ void ftvector::push_back(const int & element) { - _mem_ptr = _allocator.allocate(1); - _allocator.construct(_mem_ptr, 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); } /*********************************************