From 882cc0a02e7798000867d428218ebaf72d5c1aaf Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 16 Nov 2014 03:20:16 +0100 Subject: [PATCH] Revert "Try to rewrite ptr_vector" This reverts commit 0966f30fe999a4d11e47275f47c12ca86346e477. --- src/utils/ptr_vector.hpp | 104 ++++++++++++++++++++++++++++++--------- 1 file changed, 82 insertions(+), 22 deletions(-) diff --git a/src/utils/ptr_vector.hpp b/src/utils/ptr_vector.hpp index d0aa94fc0..4231c0a1c 100644 --- a/src/utils/ptr_vector.hpp +++ b/src/utils/ptr_vector.hpp @@ -39,9 +39,12 @@ enum VECTOR_TYPE template -class PtrVector : public AlignedArray +class PtrVector { + public: + AlignedArray m_contents_vector; + PtrVector() { } // PtrVector @@ -53,31 +56,59 @@ public: if(type == HOLD) clearAndDeleteAll(); } // ~PtrVector + // ------------------------------------------------------------------------ + + void push_back(TYPE* t) + { + m_contents_vector.push_back(t); + } // push_back + + // ------------------------------------------------------------------------ + void swap(int ID1, int ID2) + { + assert(ID1 > -1); + assert((unsigned int)ID1 < m_contents_vector.size()); + assert(ID2 > -1); + assert((unsigned int)ID2 < m_contents_vector.size()); + + + TYPE* temp = m_contents_vector[ID2]; + + m_contents_vector[ID2] = m_contents_vector[ID1]; + m_contents_vector[ID1] = temp; + } // swap + // ------------------------------------------------------------------------ TYPE* get(const int ID) { assert(ID > -1); - assert((unsigned int)ID < (unsigned int)size()); + assert((unsigned int)ID < (unsigned int)m_contents_vector.size()); - return (*this)[ID]; + return m_contents_vector[ID]; } // get // ------------------------------------------------------------------------ const TYPE* get(const int ID) const { assert(ID > -1); - assert((unsigned int)ID < (unsigned int)size()); + assert((unsigned int)ID < (unsigned int)m_contents_vector.size()); - return (*this)[ID]; + return m_contents_vector[ID]; } // get + // ------------------------------------------------------------------------ + unsigned int size() const + { + return (int) m_contents_vector.size(); + } // size + // ------------------------------------------------------------------------ void erase(const int ID) { assert(ID > -1); - assert((unsigned int)ID < (unsigned int)size()); + assert((unsigned int)ID < (unsigned int)m_contents_vector.size()); - delete (TYPE *)(*this)[ID]; + delete ( TYPE *) m_contents_vector[ID]; #ifdef USE_ALIGNED const unsigned int amount = (unsigned int)m_contents_vector.size(); for(unsigned int i=ID; i::erase(this->begin() + ID); + m_contents_vector.erase(m_contents_vector.begin()+ID); #endif } // erase @@ -94,9 +125,9 @@ public: TYPE* remove(const int ID) { assert(ID > -1); - assert((unsigned int)ID < (unsigned int)size()); + assert((unsigned int)ID < (unsigned int)m_contents_vector.size()); - TYPE* out = (*this)[ID]; + TYPE* out = m_contents_vector[ID]; #ifdef USE_ALIGNED const unsigned int amount = (unsigned int)m_contents_vector.size(); for(unsigned int i=ID; i::erase(this->begin() + ID); + m_contents_vector.erase(m_contents_vector.begin()+ID); #endif return out; } // remove + // ------------------------------------------------------------------------ + bool contains( const TYPE* instance ) const + { + const unsigned int amount = (unsigned int)m_contents_vector.size(); + for (unsigned int n=0; n::erase(begin() + n); + m_contents_vector.erase(m_contents_vector.begin()+n); #endif return; } @@ -168,9 +228,9 @@ public: */ bool erase(void* obj) { - for(unsigned int n=0; n<(unsigned int)size(); n++) + for(unsigned int n=0; n<(unsigned int)m_contents_vector.size(); n++) { - TYPE * pointer = (*this)[n]; + TYPE * pointer = m_contents_vector[n]; if((void*)pointer == obj) { #ifdef USE_ALIGNED @@ -182,7 +242,7 @@ public: } m_contents_vector.pop_back(); #else - AlignedArray::erase(m_contents_vector.begin() + n); + m_contents_vector.erase(m_contents_vector.begin()+n); #endif delete pointer; return true;