28 template <
typename ObjectTemplate>
33 explicit Vector(
int init_size = MIN_CAPACITY)
35 _capacity((init_size >= MIN_CAPACITY) ? init_size : MIN_CAPACITY) {
36 _object_template =
new ObjectTemplate[ _capacity ];
44 delete [] _object_template;
49 delete[] _object_template;
51 _capacity = rhs._capacity;
53 _object_template =
new ObjectTemplate[capacity()];
54 for(
int k = 0; k < size(); k++) {
55 _object_template[k] = rhs._object_template[k];
61 void resize(
int new_size) {
62 if(new_size > _capacity) {
63 reserve(new_size * 2 + 1);
68 void reserve(
int new_capacity) {
69 if(new_capacity < _size) {
72 ObjectTemplate *old_array = _object_template;
74 _object_template =
new ObjectTemplate[new_capacity];
75 for(
int k = 0; k < _size; k++) {
76 _object_template[k] = old_array[k];
78 _capacity = new_capacity;
82 ObjectTemplate & operator[](
int idx) {
83 return _object_template[idx];
86 const ObjectTemplate& operator[](
int idx)
const {
87 return _object_template[idx];
98 int capacity()
const {
102 void push_back(
const ObjectTemplate& x) {
103 if(_size == _capacity) {
104 reserve(2 * _capacity + 1);
106 _object_template[_size] = x;
118 const ObjectTemplate& back()
const {
119 return _object_template[_size - 1];
122 typedef ObjectTemplate* iterator;
123 typedef const ObjectTemplate* const_iterator;
126 return &_object_template[0];
129 const_iterator begin()
const {
130 return &_object_template[0];
134 return &_object_template[_size];
137 const_iterator end()
const {
138 return &_object_template[_size];
141 void erase(
int position) {
142 if(position < _size) {
143 for(
int k = position; k + 1 < _size; k++) {
144 _object_template[k] = _object_template[k + 1];
157 ObjectTemplate* _object_template;
162 #endif // M2M_VECTOR_H Definition: m2mvector.h:30
Namespace defined as replace for components defined under std namespace.
Definition: m2mstring.h:22