#include <DynamicArray.h>
Inherits AVRCpp::Collection::BaseArray< DataType, SizeType, DataType * >.
Public Member Functions | |
DynamicArray () | |
Constructor. | |
~DynamicArray () | |
Destructor. | |
bool | Resize (const SizeType size, const DataType &values=DataType()) |
Resize array to certain length. | |
bool | Add (const DataType &value) |
Add item to the end of array. | |
bool | Insert (const DataType &value, const SizeType pos) |
Insert item to the pos. | |
bool | Remove (const SizeType pos) |
Remove item at pos. | |
bool | Clear () |
Clear array. | |
SizeType | GetCapacity (void) |
Return array capacity. | |
bool | IsFull (void) |
Return whether the array is in full capacity or not. | |
SizeType | GetSize (void) |
Return array size. | |
bool | IsEmpty (void) |
Return whether the array is empty or not. | |
DataType & | At (SizeTypepos) |
Return reference of item at specified position NB! For speed purposes does not check constraints! | |
Protected Member Functions | |
bool | Realloc (SizeType size) |
Try resize the array. | |
Protected Attributes | |
SizeType | allocated_size |
DataType * | data |
SizeType | current_size |
Definition at line 63 of file DynamicArray.h.
AVRCpp::Collection::DynamicArray< DataType, SizeType, array_capacity, reserve_size, block_size >::DynamicArray | ( | ) | [inline] |
Constructor.
Definition at line 96 of file DynamicArray.h.
00097 { 00098 BaseArray<DataType, SizeType, DataType*>(); 00099 00100 this->data = (DataType *) malloc(reserve_size); 00101 this->allocated_size = 0; 00102 }
AVRCpp::Collection::DynamicArray< DataType, SizeType, array_capacity, reserve_size, block_size >::~DynamicArray | ( | ) | [inline] |
bool AVRCpp::Collection::DynamicArray< DataType, SizeType, array_capacity, reserve_size, block_size >::Realloc | ( | SizeType | size | ) | [inline, protected] |
Try resize the array.
Definition at line 71 of file DynamicArray.h.
00072 { 00073 // Don't allow smaller allocation than reserve size 00074 if (size < reserve_size) size = reserve_size; 00075 00076 // If current allocation equals new size then skip 00077 if (this->allocated_size == size) return true; 00078 00079 // Try reallocate 00080 DataType *newData = (DataType *) realloc(this->data, sizeof(DataType) * size); 00081 if (newData) 00082 { 00083 this->data = newData; 00084 this->allocated_size = size; 00085 return true; 00086 } 00087 00088 return false; 00089 }
bool AVRCpp::Collection::DynamicArray< DataType, SizeType, array_capacity, reserve_size, block_size >::Resize | ( | const SizeType | size, | |
const DataType & | values = DataType() | |||
) | [inline] |
Resize array to certain length.
Reimplemented from AVRCpp::Collection::BaseArray< DataType, SizeType, DataType * >.
Definition at line 115 of file DynamicArray.h.
00116 { 00117 // If new size is larger than maximum capacity then abort 00118 if (size >= array_capacity) return false; 00119 00120 if (!this->Realloc(size)) return false; 00121 00122 return BaseArray<DataType, SizeType, DataType*>::Resize(size, values); 00123 }
bool AVRCpp::Collection::DynamicArray< DataType, SizeType, array_capacity, reserve_size, block_size >::Add | ( | const DataType & | value | ) | [inline] |
Add item to the end of array.
Reimplemented from AVRCpp::Collection::BaseArray< DataType, SizeType, DataType * >.
Definition at line 128 of file DynamicArray.h.
00129 { 00130 // If new size is larger than maximum capacity then abort 00131 if (this->current_size >= array_capacity) return false; 00132 00133 // If new size is larger than allocated size then increase memory size by one block 00134 if (this->current_size >= this->allocated_size) 00135 { 00136 if (!this->Realloc(this->current_size + block_size)) return false; 00137 } 00138 00139 return BaseArray<DataType, SizeType, DataType*>::Add(value); 00140 }
bool AVRCpp::Collection::DynamicArray< DataType, SizeType, array_capacity, reserve_size, block_size >::Insert | ( | const DataType & | value, | |
const SizeType | pos | |||
) | [inline] |
Insert item to the pos.
Reimplemented from AVRCpp::Collection::BaseArray< DataType, SizeType, DataType * >.
Definition at line 145 of file DynamicArray.h.
00146 { 00147 // If new size is larger than maximum then abort 00148 if (this->current_size >= array_capacity) return false; 00149 00150 // Check constraints 00151 if (pos > this->current_size) return false; 00152 00153 // If new size is larger than allocated size then increase memory size by one block 00154 if (this->current_size >= this->allocated_size) 00155 { 00156 if (!this->Realloc(this->current_size + block_size)) return false; 00157 } 00158 00159 return BaseArray<DataType, SizeType, DataType*>::Insert(value, pos); 00160 }
bool AVRCpp::Collection::DynamicArray< DataType, SizeType, array_capacity, reserve_size, block_size >::Remove | ( | const SizeType | pos | ) | [inline] |
Remove item at pos.
Reimplemented from AVRCpp::Collection::BaseArray< DataType, SizeType, DataType * >.
Definition at line 165 of file DynamicArray.h.
00166 { 00167 if (!BaseArray<DataType, SizeType, DataType*>::Remove(pos)) return false; 00168 00169 // If current size is one block size smaller than allocated size then decrease memory size 00170 if (this->current_size <= this->allocated_size - block_size) 00171 { 00172 // No matter the realloc succeeds or not, fictios size will still be smaller 00173 this->Realloc(this->allocated_size - block_size); 00174 } 00175 00176 return true; 00177 }
bool AVRCpp::Collection::DynamicArray< DataType, SizeType, array_capacity, reserve_size, block_size >::Clear | ( | ) | [inline] |
Clear array.
Reimplemented from AVRCpp::Collection::BaseArray< DataType, SizeType, DataType * >.
Definition at line 182 of file DynamicArray.h.
00183 { 00184 if (!BaseArray<DataType, SizeType, DataType*>::Clear()) return false; 00185 00186 // No matter the realloc succeeds or not, fictios size will still be 0 00187 this->Realloc(0); 00188 00189 return true; 00190 }
SizeType AVRCpp::Collection::DynamicArray< DataType, SizeType, array_capacity, reserve_size, block_size >::GetCapacity | ( | void | ) | [inline] |
bool AVRCpp::Collection::DynamicArray< DataType, SizeType, array_capacity, reserve_size, block_size >::IsFull | ( | void | ) | [inline] |
SizeType AVRCpp::Collection::BaseArray< DataType , SizeType , DataType * >::GetSize | ( | void | ) | [inline, inherited] |
Return array size.
Definition at line 145 of file BaseArray.h.
00146 { 00147 return this->current_size; 00148 }
bool AVRCpp::Collection::BaseArray< DataType , SizeType , DataType * >::IsEmpty | ( | void | ) | [inline, inherited] |
DataType & AVRCpp::Collection::BaseArray< DataType , SizeType , DataType * >::At | ( | SizeType | pos | ) | [inline, inherited] |
Return reference of item at specified position NB! For speed purposes does not check constraints!
Definition at line 172 of file BaseArray.h.
00173 { 00174 return this->data[pos]; 00175 }
SizeType AVRCpp::Collection::DynamicArray< DataType, SizeType, array_capacity, reserve_size, block_size >::allocated_size [protected] |
Definition at line 66 of file DynamicArray.h.
DataType * AVRCpp::Collection::BaseArray< DataType , SizeType , DataType * >::data [protected, inherited] |
Definition at line 55 of file BaseArray.h.
SizeType AVRCpp::Collection::BaseArray< DataType , SizeType , DataType * >::current_size [protected, inherited] |
Definition at line 56 of file BaseArray.h.
MTÜ TTÜ Robotiklubi |