[DEV] start rework of the vector with size_t

This commit is contained in:
Edouard DUPIN 2013-06-30 20:00:00 +02:00
parent 01cc09e87d
commit 553c97bc87
2 changed files with 194 additions and 201 deletions

View File

@ -59,11 +59,11 @@ extern const int32_t constConvertionTableSize;
void DisplayElem(const etk::Vector<etk::UniChar>& _data, int32_t _start=0, int32_t _stop=0x7FFFFFFF); void DisplayElem(const etk::Vector<etk::UniChar>& _data, int32_t _start=0, int32_t _stop=0x7FFFFFFF);
char * levelSpace(int32_t _level); char * levelSpace(int32_t _level);
int32_t GetLenOfPTheseElem(const etk::Vector<etk::UniChar>& _data, int32_t _startPos); size_t GetLenOfPTheseElem(const etk::Vector<etk::UniChar>& _data, int32_t _startPos);
int32_t GetLenOfPThese(const etk::Vector<etk::UniChar>& _data, int32_t _startPos); size_t GetLenOfPThese(const etk::Vector<etk::UniChar>& _data, int32_t _startPos);
int32_t GetLenOfBracket(const etk::Vector<etk::UniChar>& _data, int32_t _startPos); size_t GetLenOfBracket(const etk::Vector<etk::UniChar>& _data, int32_t _startPos);
int32_t GetLenOfBrace(const etk::Vector<etk::UniChar>& _data, int32_t _startPos); size_t GetLenOfBrace(const etk::Vector<etk::UniChar>& _data, int32_t _startPos);
int32_t GetLenOfNormal(const etk::Vector<etk::UniChar>& _data, int32_t _startPos); size_t GetLenOfNormal(const etk::Vector<etk::UniChar>& _data, int32_t _startPos);
bool ParseBrace(const etk::Vector<etk::UniChar>& _data, int32_t& _min, int32_t& _max); bool ParseBrace(const etk::Vector<etk::UniChar>& _data, int32_t& _min, int32_t& _max);

View File

@ -58,66 +58,60 @@ namespace etk
{ {
// Private data : // Private data :
private: private:
int32_t m_current; //!< curent Id on the vector size_t m_current; //!< curent Id on the vector
Vector<MY_TYPE>* m_vector; //!< Pointer on the curent element of the vectorBin Vector<MY_TYPE>* m_vector; //!< Pointer on the curent element of the vectorBin
public: public:
/** /**
* @brief Basic itarator constructor with no link with an etkVector * @brief Basic itarator constructor with no link with an etkVector
*/ */
Iterator(): Iterator(void):
m_current(-1), m_current(0),
m_vector(NULL) m_vector(NULL)
{ {
// nothing to do ... // nothing to do ...
} }
/** /**
* @brief Recopy constructor on a specific etkVector. * @brief Recopy constructor on a specific etkVector.
* @param[in] otherIterator The Iterator that might be copy * @param[in] _otherIterator The Iterator that might be copy
*/ */
Iterator(const Iterator & otherIterator): Iterator(const Iterator & _otherIterator):
m_current(otherIterator.m_current), m_current(_otherIterator.m_current),
m_vector(otherIterator.m_vector) m_vector(_otherIterator.m_vector)
{ {
// nothing to do ... // nothing to do ...
} }
/** /**
* @brief Asignation operator. * @brief Asignation operator.
* @param[in] otherIterator The Iterator that might be copy * @param[in] _otherIterator The Iterator that might be copy
* @return reference on the curent Iterator * @return reference on the curent Iterator
*/ */
Iterator& operator=(const Iterator & otherIterator) Iterator& operator=(const Iterator & _otherIterator)
{ {
m_current = otherIterator.m_current; m_current = _otherIterator.m_current;
m_vector = otherIterator.m_vector; m_vector = _otherIterator.m_vector;
return *this; return *this;
} }
/** /**
* @brief Basic destructor * @brief Basic destructor
*/ */
~Iterator() ~Iterator(void)
{ {
m_current = -1; m_current = 0;
m_vector = NULL; m_vector = NULL;
} }
/** /**
* @brief basic boolean cast * @brief basic boolean cast
* @return true if the element is present in the etkVector size * @return true if the element is present in the etkVector size
*/ */
operator bool () operator bool (void)
{ {
if( 0 <= m_current return (m_current < m_vector->Size());
&& m_current < m_vector->Size() )
{
return true;
} else {
return false;
}
} }
/** /**
* @brief Incremental operator * @brief Incremental operator
* @return Reference on the current iterator incremented * @return Reference on the current iterator incremented
*/ */
Iterator& operator++ () Iterator& operator++ (void)
{ {
if( NULL != m_vector if( NULL != m_vector
&& m_current < m_vector->Size() ) && m_current < m_vector->Size() )
@ -130,9 +124,9 @@ namespace etk
* @brief Decremental operator * @brief Decremental operator
* @return Reference on the current iterator decremented * @return Reference on the current iterator decremented
*/ */
Iterator& operator-- () Iterator& operator-- (void)
{ {
if (m_current >= 0) { if (m_current > 0) {
m_current--; m_current--;
} }
return *this; return *this;
@ -161,24 +155,24 @@ namespace etk
* @brief Get reference on the current Element * @brief Get reference on the current Element
* @return the reference on the current Element * @return the reference on the current Element
*/ */
MY_TYPE & operator-> () const MY_TYPE & operator-> (void) const
{ {
TK_CHECK_INOUT(m_current >= 0 && m_current < m_vector->Size()); TK_CHECK_INOUT(m_current < m_vector->Size());
return &m_vector->Get(m_current); return &m_vector->Get(m_current);
} }
/** /**
* @brief Get reference on the current Element * @brief Get reference on the current Element
* @return the reference on the current Element * @return the reference on the current Element
*/ */
MY_TYPE & operator* () const MY_TYPE & operator* (void) const
{ {
TK_CHECK_INOUT(m_current >= 0 && m_current < m_vector->Size()); TK_CHECK_INOUT(m_current < m_vector->Size());
return m_vector->Get(m_current); return m_vector->Get(m_current);
} }
private: private:
Iterator(Vector<MY_TYPE> * obj, int32_t pos): Iterator(Vector<MY_TYPE> * _obj, int32_t _pos):
m_current(pos), m_current(_pos),
m_vector(obj) m_vector(_obj)
{ {
// nothing to do ... // nothing to do ...
} }
@ -187,28 +181,28 @@ namespace etk
private: private:
MY_TYPE* m_data; //!< pointer on the curetn table of Data MY_TYPE* m_data; //!< pointer on the curetn table of Data
int32_t m_size; //!< nb Element in the buffer size_t m_size; //!< nb Element in the buffer
int32_t m_allocated; //!< Current allocated size size_t m_allocated; //!< Current allocated size
public: public:
/** /**
* @brief Create an empty vector * @brief Create an empty vector
* @param[in] count Minimum request size of the Buffer * @param[in] _count Minimum request size of the Buffer
*/ */
Vector(int32_t count = 0): Vector(int32_t _count = 0):
m_data(NULL), m_data(NULL),
m_size(0), m_size(0),
m_allocated(0) m_allocated(0)
{ {
ChangeAllocation(count); ChangeAllocation(_count);
} }
/** /**
* @brief Re-copy constructor (copy all needed data) * @brief Re-copy constructor (copy all needed data)
* @param[in] obj Vector that might be copy * @param[in] _obj Vector that might be copy
*/ */
Vector(const etk::Vector<MY_TYPE>& obj) Vector(const etk::Vector<MY_TYPE>& _obj)
{ {
m_allocated = obj.m_allocated; m_allocated = _obj.m_allocated;
m_size = obj.m_size; m_size = _obj.m_size;
m_data = NULL; m_data = NULL;
//TK_DEBUG("USE Specific vector allocator ... Evb.m_size=" << Evb.m_size << " Evb.m_increment=" << Evb.m_increment); //TK_DEBUG("USE Specific vector allocator ... Evb.m_size=" << Evb.m_size << " Evb.m_increment=" << Evb.m_increment);
// allocate all same data // allocate all same data
@ -218,9 +212,9 @@ namespace etk
return; return;
} }
// Copy all data ... // Copy all data ...
for(int32_t iii=0; iii<m_allocated; iii++) { for(size_t iii=0; iii<m_allocated; iii++) {
// copy operator ... // copy operator ...
m_data[iii] = obj.m_data[iii]; m_data[iii] = _obj.m_data[iii];
} }
} }
/** /**
@ -237,49 +231,49 @@ namespace etk
} }
/** /**
* @brief Swap the data of 2 Vectors * @brief Swap the data of 2 Vectors
* @param[in] obj second vector to swap data. * @param[in] _obj second vector to swap data.
*/ */
void Swap(etk::Vector<MY_TYPE>& obj) void Swap(etk::Vector<MY_TYPE>& _obj)
{ {
// avoid Swap of itself // avoid Swap of itself
if(this != &obj) { if(this != &_obj) {
MY_TYPE* tmpData = m_data; MY_TYPE* tmpData = m_data;
int32_t tmpAllocated = m_allocated; size_t tmpAllocated = m_allocated;
int32_t tmpSize = m_size; size_t tmpSize = m_size;
m_data = obj.m_data; m_data = _obj.m_data;
m_allocated = obj.m_allocated; m_allocated = _obj.m_allocated;
m_size = obj.m_size; m_size = _obj.m_size;
obj.m_data = tmpData; _obj.m_data = tmpData;
obj.m_allocated = tmpAllocated; _obj.m_allocated = tmpAllocated;
obj.m_size = tmpSize; _obj.m_size = tmpSize;
} }
} }
/** /**
* @brief Re-copy operator * @brief Re-copy operator
* @param[in] obj Vector that might be copy * @param[in] _obj Vector that might be copy
* @return reference on the curent re-copy vector * @return reference on the curent re-copy vector
*/ */
Vector& operator=(const etk::Vector<MY_TYPE> & obj) Vector& operator=(const etk::Vector<MY_TYPE> & _obj)
{ {
//TK_DEBUG("USE RECOPY vector ... Evb.m_size=" << Evb.m_size << " Evb.m_increment=" << Evb.m_increment); //TK_DEBUG("USE RECOPY vector ... Evb.m_size=" << Evb.m_size << " Evb.m_increment=" << Evb.m_increment);
if( this != &obj ) // avoid copy to itself if( this != &_obj ) // avoid copy to itself
{ {
if (NULL!=m_data) { if (NULL!=m_data) {
delete[] m_data; delete[] m_data;
m_data = NULL; m_data = NULL;
} }
// Set the new value // Set the new value
m_allocated = obj.m_allocated; m_allocated = _obj.m_allocated;
m_size = obj.m_size; m_size = _obj.m_size;
// allocate all same data // allocate all same data
m_data = new MY_TYPE[m_allocated]; m_data = new MY_TYPE[m_allocated];
if (NULL==m_data) { if (NULL==m_data) {
TK_CRITICAL("Vector : Error in data allocation ... might nor work corectly anymore"); TK_CRITICAL("Vector : Error in data allocation ... might nor work corectly anymore");
return *this; return *this;
} }
for(int32_t iii=0; iii<m_allocated; iii++) { for(size_t iii=0; iii<m_allocated; iii++) {
// copy operator ... // copy operator ...
m_data[iii] = obj.m_data[iii]; m_data[iii] = _obj.m_data[iii];
} }
} }
// Return the curent pointer // Return the curent pointer
@ -288,20 +282,20 @@ namespace etk
/** /**
* @brief Add at the Last position of the Vector * @brief Add at the Last position of the Vector
* @param[in] obj Element to add at the end of vector * @param[in] _obj Element to add at the end of vector
*/ */
Vector& operator+= (const etk::Vector<MY_TYPE> & obj) Vector& operator+= (const etk::Vector<MY_TYPE> & _obj)
{ {
int32_t nbElememt = obj.Size(); size_t nbElememt = _obj.Size();
int32_t idx = m_size; size_t idx = m_size;
Resize(m_size+nbElememt); Resize(m_size+nbElememt);
if (m_size<=idx) { if (m_size<=idx) {
TK_CRITICAL("allocation error"); TK_CRITICAL("allocation error");
return *this; return *this;
} }
for(int32_t iii=0; iii<nbElememt; iii++) { for(size_t iii=0; iii<nbElememt; iii++) {
// copy operator ... // copy operator ...
m_data[idx+iii] = obj.m_data[iii]; m_data[idx+iii] = _obj.m_data[iii];
} }
// Return the curent pointer // Return the curent pointer
return *this; return *this;
@ -310,7 +304,7 @@ namespace etk
* @brief Get the number of element in the vector * @brief Get the number of element in the vector
* @return The number requested * @return The number requested
*/ */
int32_t Size(void) const size_t Size(void) const
{ {
return m_size; return m_size;
} }
@ -318,18 +312,18 @@ namespace etk
* @brief Get the number of element in the vector * @brief Get the number of element in the vector
* @return The number requested * @return The number requested
*/ */
void ReSize(int32_t newSize, const MY_TYPE& basicElement) void ReSize(size_t _newSize, const MY_TYPE& _basicElement)
{ {
int32_t idx = m_size; size_t idx = m_size;
Resize(newSize); Resize(_newSize);
if (m_size != newSize) { if (m_size != _newSize) {
TK_CRITICAL("error to resize vector"); TK_CRITICAL("error to resize vector");
return; return;
} }
if (newSize > idx) { if (_newSize > idx) {
// initialize data ... // initialize data ...
for(int32_t iii=idx; iii<newSize; iii++) { for(size_t iii=idx; iii<_newSize; iii++) {
m_data[iii] = basicElement; m_data[iii] = _basicElement;
} }
} }
} }
@ -337,100 +331,99 @@ namespace etk
* @brief Get the Allocated size in the vector * @brief Get the Allocated size in the vector
* @return The size of allocation * @return The size of allocation
*/ */
int32_t AllocatedSize() const size_t AllocatedSize(void) const
{ {
return m_allocated; return m_allocated;
} }
/** /**
* @brief Get a current element in the vector * @brief Get a current element in the vector
* @param[in] pos Desired position read * @param[in] _pos Desired position read
* @return Reference on the Element * @return Reference on the Element
*/ */
MY_TYPE& Get(int32_t pos) MY_TYPE& Get(size_t _pos)
{ {
// NOTE :Do not change log level, this generate error only in debug mode // NOTE :Do not change log level, this generate error only in debug mode
#if DEBUG_LEVEL > 2 #if DEBUG_LEVEL > 2
if( pos>m_size if(_pos>m_size){
|| pos<0){ TK_CRITICAL("[CRITICAL] Access to an unexistant data in vector : " << _pos << "/ " << m_size);
TK_CRITICAL("[CRITICAL] Access to an unexistant data in vector : " << pos << "/ " << m_size);
} }
#endif #endif
return m_data[pos]; return m_data[_pos];
} }
/** /**
* @brief Get an copy Element an a special position * @brief Get an copy Element an a special position
* @param[in] pos Position in the vector that might be get [0..Size()] * @param[in] _pos Position in the vector that might be get [0..Size()]
* @return An reference on the copy of selected element * @return An reference on the copy of selected element
*/ */
MY_TYPE& operator[] (int32_t pos) MY_TYPE& operator[] (size_t _pos)
{ {
return Get(pos); return Get(_pos);
} }
/** /**
* @brief Get an Element an a special position * @brief Get an Element an a special position
* @param[in] pos Position in the vector that might be get [0..Size()] * @param[in] _pos Position in the vector that might be get [0..Size()]
* @return An reference on the selected element * @return An reference on the selected element
*/ */
const MY_TYPE& operator[] (int32_t pos) const const MY_TYPE& operator[] (size_t _pos) const
{ {
// NOTE :Do not change log level, this generate error only in debug mode // NOTE :Do not change log level, this generate error only in debug mode
#if DEBUG_LEVEL > 2 #if DEBUG_LEVEL > 2
if( pos>m_size if( _pos>m_size
|| pos<0){ || _pos<0){
TK_CRITICAL("[CRITICAL] Access to an unexistant data in vector : " << pos << "/ " << m_size); TK_CRITICAL("[CRITICAL] Access to an unexistant data in vector : " << _pos << "/ " << m_size);
} }
#endif #endif
return m_data[pos]; return m_data[_pos];
} }
/** /**
* @brief Add at the First position of the Vector * @brief Add at the First position of the Vector
* @param[in] item Element to add at the end of vector * @param[in] _item Element to add at the end of vector
*/ */
void PushFront(const MY_TYPE& item) void PushFront(const MY_TYPE& _item)
{ {
Insert(0, &item, 1); Insert(0, &_item, 1);
} }
/** /**
* @brief Add at the Last position of the Vector * @brief Add at the Last position of the Vector
* @param[in] item Pointer on a list of Element to add at the start of vector * @param[in] _item Pointer on a list of Element to add at the start of vector
* @param[in] nbElement Number of element to add. * @param[in] _nbElement Number of element to add.
*/ */
void PushFront(const MY_TYPE * item, int32_t nbElement) void PushFront(const MY_TYPE * _item, size_t _nbElement)
{ {
Insert(0, item, nbElement); Insert(0, _item, _nbElement);
} }
/** /**
* @brief Add at the Last position of the Vector * @brief Add at the Last position of the Vector
* @param[in] item Element to add at the end of vector * @param[in] _item Element to add at the end of vector
*/ */
void PushBack(const MY_TYPE& item) void PushBack(const MY_TYPE& _item)
{ {
int32_t idx = m_size; size_t idx = m_size;
Resize(m_size+1); Resize(m_size+1);
if (idx < m_size) { if (idx < m_size) {
m_data[idx] = item; m_data[idx] = _item;
} else { } else {
TK_ERROR("Resize does not work corectly ... not added item"); TK_ERROR("Resize does not work corectly ... not added item");
} }
} }
/** /**
* @brief Add at the Last position of the Vector * @brief Add at the Last position of the Vector
* @param[in] item Pointer on a list of Element to add at the end of vector * @param[in] _item Pointer on a list of Element to add at the end of vector
* @param[in] nbElement Number of element to add. * @param[in] _nbElement Number of element to add.
*/ */
void PushBack(const MY_TYPE * item, int32_t nbElement) void PushBack(const MY_TYPE * _item, size_t _nbElement)
{ {
if (NULL == item) { if (NULL == _item) {
return; return;
} }
int32_t idx = m_size; size_t idx = m_size;
Resize(m_size+nbElement); Resize(m_size+_nbElement);
if (idx > m_size) { if (idx > m_size) {
TK_ERROR("Resize does not work corectly ... not added item"); TK_ERROR("Resize does not work corectly ... not added item");
return; return;
} }
for (int32_t iii=0; iii<nbElement; iii++) { for (size_t iii=0; iii<_nbElement; iii++) {
m_data[idx+iii] = item[iii]; m_data[idx+iii] = _item[iii];
} }
} }
/** /**
@ -453,107 +446,107 @@ namespace etk
} }
/** /**
* @brief Insert N element in the Vector. * @brief Insert N element in the Vector.
* @param[in] pos Position to add the elements. * @param[in] _pos Position to add the elements.
* @param[in] item Pointer on a table of the elements to add. * @param[in] _item Pointer on a table of the elements to add.
* @param[in] nbElement Number of element to add in the Vector * @param[in] _nbElement Number of element to add in the Vector
*/ */
void Insert(int32_t pos, const MY_TYPE * item, int32_t nbElement) void Insert(size_t _pos, const MY_TYPE * _item, size_t _nbElement)
{ {
if (pos>m_size) { if (_pos>m_size) {
TK_WARNING(" can not insert Element at this position : " << pos << " > " << m_size << " add it at the end ... "); TK_WARNING(" can not insert Element at this position : " << _pos << " > " << m_size << " add it at the end ... ");
PushBack(item, nbElement); PushBack(_item, _nbElement);
return; return;
} }
int32_t idx = m_size; size_t idx = m_size;
// Request resize of the current buffer // Request resize of the current buffer
Resize(m_size+nbElement); Resize(m_size+_nbElement);
if (idx>=m_size) { if (idx>=m_size) {
TK_ERROR("Resize does not work corectly ... not added item"); TK_ERROR("Resize does not work corectly ... not added item");
return; return;
} }
// move curent data (after the position) // move curent data (after the position)
int32_t sizeToMove = (idx - pos); size_t sizeToMove = (idx - _pos);
if ( 0 < sizeToMove) { if ( 0 < sizeToMove) {
for (int32_t iii=1; iii<=sizeToMove; iii++) { for (size_t iii=1; iii<=sizeToMove; iii++) {
m_data[m_size-iii] = m_data[idx-iii]; m_data[m_size-iii] = m_data[idx-iii];
} }
} }
// affectation of all input element // affectation of all input element
for (int32_t iii=0; iii<nbElement; iii++) { for (size_t iii=0; iii<_nbElement; iii++) {
m_data[pos+iii] = item[iii]; m_data[_pos+iii] = _item[iii];
} }
} }
/** /**
* @brief Insert one element in the Vector at a specific position * @brief Insert one element in the Vector at a specific position
* @param[in] pos Position to add the elements. * @param[in] _pos Position to add the elements.
* @param[in] item Element to add. * @param[in] _item Element to add.
*/ */
void Insert(int32_t pos, const MY_TYPE& item) void Insert(size_t _pos, const MY_TYPE& _item)
{ {
Insert(pos, &item, 1); Insert(_pos, &_item, 1);
} }
/** /**
* @brief Remove N element * @brief Remove N element
* @param[in] pos Position to remove the data * @param[in] _pos Position to remove the data
* @param[in] nbElement number of element to remove * @param[in] _nbElement number of element to remove
*/ */
void EraseLen(int32_t pos, int32_t nbElement) void EraseLen(size_t _pos, size_t _nbElement)
{ {
if (pos>m_size) { if (_pos>m_size) {
TK_ERROR(" can not Erase Len Element at this position : " << pos << " > " << m_size); TK_ERROR(" can not Erase Len Element at this position : " << _pos << " > " << m_size);
return; return;
} }
if (pos+nbElement>m_size) { if (_pos+_nbElement>m_size) {
nbElement = m_size - pos; _nbElement = m_size - _pos;
} }
int32_t idx = m_size; size_t idx = m_size;
// move curent data // move curent data
int32_t sizeToMove = (idx - (pos+nbElement)); size_t sizeToMove = (idx - (_pos+_nbElement));
if ( 0 < sizeToMove) { if ( 0 < sizeToMove) {
for (int32_t iii=0; iii<sizeToMove; iii++) { for (size_t iii=0; iii<sizeToMove; iii++) {
m_data[pos+iii] = m_data[pos+nbElement+iii]; m_data[_pos+iii] = m_data[_pos+_nbElement+iii];
} }
} }
// Request resize of the current buffer // Request resize of the current buffer
Resize(m_size-nbElement); Resize(m_size-_nbElement);
} }
/** /**
* @brief Remove one element * @brief Remove one element
* @param[in] pos Position to remove the data * @param[in] _pos Position to remove the data
*/ */
inline void Erase(int32_t pos) inline void Erase(size_t _pos)
{ {
EraseLen(pos, 1); EraseLen(_pos, 1);
} }
/** /**
* @brief Remove one element * @brief Remove one element
* @param[in] pos Position to remove the data * @param[in] _pos Position to remove the data
*/ */
inline void Remove(int32_t pos) inline void Remove(size_t _pos)
{ {
EraseLen(pos, 1); EraseLen(_pos, 1);
} }
/** /**
* @brief Remove N elements * @brief Remove N elements
* @param[in] pos Position to remove the data * @param[in] _pos Position to remove the data
* @param[in] posEnd Last position number * @param[in] _posEnd Last position number
*/ */
void Erase(int32_t pos, int32_t posEnd) void Erase(size_t _pos, size_t _posEnd)
{ {
if (pos>m_size) { if (_pos>m_size) {
TK_ERROR(" can not Erase Element at this position : " << pos << " > " << m_size); TK_ERROR(" can not Erase Element at this position : " << _pos << " > " << m_size);
return; return;
} }
if (posEnd>m_size) { if (_posEnd>m_size) {
posEnd = m_size; _posEnd = m_size;
} }
int32_t nbElement = m_size - pos; size_t nbElement = m_size - _pos;
int32_t tmpSize = m_size; size_t tmpSize = m_size;
// move curent data // move curent data
int32_t sizeToMove = (tmpSize - (pos+nbElement)); size_t sizeToMove = (tmpSize - (_pos+nbElement));
if ( 0 < sizeToMove) { if ( 0 < sizeToMove) {
for (int32_t iii=0; iii<sizeToMove; iii++) { for (size_t iii=0; iii<sizeToMove; iii++) {
m_data[pos+iii] = m_data[pos+nbElement+iii]; m_data[_pos+iii] = m_data[_pos+nbElement+iii];
} }
} }
// Request resize of the current buffer // Request resize of the current buffer
@ -561,24 +554,24 @@ namespace etk
} }
/** /**
* @brief extract data between two point : * @brief extract data between two point :
* @param[in] posStart start position to extract data * @param[in] _posStart start position to extract data
* @param[in] posEnd End position to extract data * @param[in] _posEnd End position to extract data
* @return the extracted vector * @return the extracted vector
*/ */
Vector<MY_TYPE> Extract(int32_t posStart = 0, int32_t posEnd=0x7FFFFFFF) const Vector<MY_TYPE> Extract(size_t _posStart = 0, size_t _posEnd=0x7FFFFFFF) const
{ {
Vector<MY_TYPE> out; Vector<MY_TYPE> out;
if (posStart < 0) { if (_posStart < 0) {
posStart = 0; _posStart = 0;
} else if (posStart >= Size() ) { } else if (_posStart >= Size() ) {
return out; return out;
} }
if (posEnd < 0) { if (_posEnd < 0) {
return out; return out;
} else if (posEnd >= Size() ) { } else if (_posEnd >= Size() ) {
posEnd = Size(); _posEnd = Size();
} }
out.PushBack(&m_data[posStart], posEnd-posStart); out.PushBack(&m_data[_posStart], _posEnd-_posStart);
return out; return out;
} }
/** /**
@ -591,12 +584,12 @@ namespace etk
} }
/** /**
* @brief Get an iterator an an specific position * @brief Get an iterator an an specific position
* @param[in] pos Requested position of the iterator in the vector * @param[in] _pos Requested position of the iterator in the vector
* @return The Iterator * @return The Iterator
*/ */
Iterator Position(int32_t pos) Iterator Position(size_t _pos)
{ {
return Iterator(this, pos); return Iterator(this, _pos);
} }
/** /**
* @brief Get an Iterator on the start position of the Vector * @brief Get an Iterator on the start position of the Vector
@ -617,37 +610,37 @@ namespace etk
private: private:
/** /**
* @brief Change the current size of the vector * @brief Change the current size of the vector
* @param[in] newSize New requested size of element in the vector * @param[in] _newSize New requested size of element in the vector
*/ */
void Resize(int32_t newSize) void Resize(size_t _newSize)
{ {
// Reallocate memory // Reallocate memory
if (newSize > m_allocated) { if (_newSize > m_allocated) {
ChangeAllocation(newSize); ChangeAllocation(_newSize);
} }
m_size = newSize; m_size = _newSize;
} }
/** /**
* @brief Change the current allocation to the corect one (depend on the current size) * @brief Change the current allocation to the corect one (depend on the current size)
* @param[in] newSize Minimum number of element needed * @param[in] _newSize Minimum number of element needed
*/ */
void ChangeAllocation(int32_t newSize) void ChangeAllocation(size_t _newSize)
{ {
// set the minimal size to 1 // set the minimal size to 1
if(newSize <= 0) { if(_newSize == 0) {
newSize = 1; _newSize = 1;
} }
if (m_allocated<0) { if (m_allocated<0) {
m_allocated = 0; m_allocated = 0;
} }
int32_t requestSize = m_allocated; size_t requestSize = m_allocated;
// set the size with the corect chose type : // set the size with the corect chose type :
if (newSize == requestSize) { if (_newSize == requestSize) {
return; return;
} else if (newSize < requestSize) { } else if (_newSize < requestSize) {
// we did not remove data ??? // we did not remove data ???
} else { } else {
while(newSize > requestSize) { while(_newSize > requestSize) {
if (0 == requestSize) { if (0 == requestSize) {
requestSize = 1; requestSize = 1;
} else { } else {
@ -679,8 +672,8 @@ namespace etk
return; return;
} }
// copy data in the new pool // copy data in the new pool
int32_t nbElements = etk_min(requestSize, m_allocated); size_t nbElements = etk_min(requestSize, m_allocated);
for(int32_t iii=0; iii<nbElements; iii++) { for(size_t iii=0; iii<nbElements; iii++) {
m_dataTmp[iii] = m_data[iii]; m_dataTmp[iii] = m_data[iii];
} }
// switch pointer: // switch pointer:
@ -698,22 +691,22 @@ namespace etk
/***************************************************** /*****************************************************
* == operator * == operator
*****************************************************/ *****************************************************/
bool operator== (const Vector<MY_TYPE>& obj) const bool operator== (const Vector<MY_TYPE>& _obj) const
{ {
// check if it was the same pointer // check if it was the same pointer
if( this == &obj ) { if( this == &_obj ) {
return true; return true;
} }
// fiist step : check the size ... // fiist step : check the size ...
if (m_size!=obj.m_size) { if (m_size!=_obj.m_size) {
return false; return false;
} }
if( NULL==m_data if( NULL==m_data
|| NULL==obj.m_data) { || NULL==_obj.m_data) {
return false; return false;
} }
for (int32_t iii=0; iii<m_size; iii++) { for (size_t iii=0; iii<m_size; iii++) {
if (m_data[iii]!=obj.m_data[iii]) { if (m_data[iii]!=_obj.m_data[iii]) {
return false; return false;
} }
} }
@ -722,22 +715,22 @@ namespace etk
/***************************************************** /*****************************************************
* != operator * != operator
*****************************************************/ *****************************************************/
bool operator!= (const Vector<MY_TYPE>& obj) const bool operator!= (const Vector<MY_TYPE>& _obj) const
{ {
// check if it was the same pointer // check if it was the same pointer
if( this == &obj ) { if( this == &_obj ) {
return false; return false;
} }
// fiist step : check the size ... // fiist step : check the size ...
if (m_size!=obj.m_size) { if (m_size!=_obj.m_size) {
return true; return true;
} }
if( NULL==m_data if( NULL==m_data
|| NULL==obj.m_data) { || NULL==_obj.m_data) {
return false; return false;
} }
for (int32_t iii=0; iii<m_size; iii++) { for (size_t iii=0; iii<m_size; iii++) {
if (m_data[iii]!=obj.m_data[iii]) { if (m_data[iii]!=_obj.m_data[iii]) {
return true; return true;
} }
} }