From c121ea989ec5e43348398fb8ba9c04adfe1fa572 Mon Sep 17 00:00:00 2001 From: ganovelli Date: Wed, 31 Mar 2004 22:33:38 +0000 Subject: [PATCH] one bug corrected and other minor changes --- vcg/container/container_allocation_table.h | 52 +++++++++++++++------- vcg/container/entries_allocation_table.h | 3 ++ vcg/container/traced_vector.h | 15 ++++--- 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/vcg/container/container_allocation_table.h b/vcg/container/container_allocation_table.h index a3107279..4d4bb886 100644 --- a/vcg/container/container_allocation_table.h +++ b/vcg/container/container_allocation_table.h @@ -29,7 +29,7 @@ #include #include #include -#include +#include namespace vcg { @@ -69,9 +69,10 @@ CATEntry(){if(Id()==0){ static unsigned int Ord(VALUE_TYPE *); static ENTRY_TYPE & GetEntry(STL_CONT::value_type*pt); -static void Insert( STL_CONT & c ); // insert a vector to trace -virtual void Remove( const STL_CONT & c); // remove the container c -static void Remove( VALUE_TYPE * v); // remove the container that contains v +static void Insert( STL_CONT & c,bool cond=false ); // insert a vector to trace +virtual void Remove( const STL_CONT & c); // remove the container c +static void RemoveIfEmpty( const STL_CONT & c); // remove the container c +static void Remove( VALUE_TYPE * v); // remove the container that contains v virtual void Resort( VALUE_TYPE* old_start, // resort the allocation table VALUE_TYPE* new_start); // after a container was moved @@ -133,10 +134,10 @@ std::list::iterator CATEntry:: FindBase(const VALUE_TYPE * pt) { -std::list::iterator -ite = AT().begin(),curr_base; +std::list::iterator ite,curr_base,_; +ite = AT().begin(); +curr_base = AT().end(); -std::list tmp = AT(); for(;ite != AT().end();ite++) if( pt < (*ite).Start()) return curr_base; @@ -195,11 +196,24 @@ Remove( const STL_CONT & c ) { std::list::iterator ite; for(ite = AT().begin(); ite != AT().end(); ++ite) -if((*ite).C() == &c) - { - AT().erase(ite); - break; - } + if((*ite).C() == &c) + { + AT().erase(ite); + break; + } +UTD() = false; +} + +template +void CATEntry:: + +RemoveIfEmpty( const STL_CONT & c ) +{ +std::list::iterator ite; +for(ite = AT().begin(); ite != AT().end(); ++ite) + if((*ite).C() == &c) + if(!(*ite).Empty()) + AT().erase(ite); UTD() = false; } @@ -212,21 +226,30 @@ Remove(VALUE_TYPE * pt) lower_ite = FindBase(pt); AT().erase(lower_ite); UTD() = false; + } template void CATEntry:: -Insert( STL_CONT & c ) +Insert( STL_CONT & c,bool cond ) { ENTRY_TYPE entry(c); std::list::iterator lower_ite,upper_ite; -upper_ite = std::lower_bound(AT().begin(), AT().end(), entry); +upper_ite = FindBase(&*c.begin()); +bool isIn = (upper_ite != AT().end()); +if(isIn){ + if((*upper_ite).C() != &c ) + ++upper_ite; + else + return; + } lower_ite = AT().insert(upper_ite,entry); lower_ite->Reserve(c.capacity()); lower_ite->Resize(c.size()); UTD() = false; } + template ENTRY_TYPE & CATEntry:: GetEntry(STL_CONT::value_type*pt){ @@ -250,7 +273,6 @@ Curr()->Push_back(n); template class CAT:public CATEntry >{ public: -typedef typename EntryCAT EntryType; static ATTR_TYPE & Get(STL_CONT::value_type * pt); }; //---------------------- CAT: implementation--------------------------------------------------- diff --git a/vcg/container/entries_allocation_table.h b/vcg/container/entries_allocation_table.h index 4eed0ff3..f2a8513c 100644 --- a/vcg/container/entries_allocation_table.h +++ b/vcg/container/entries_allocation_table.h @@ -34,6 +34,7 @@ struct EntryCATBase{ EntryCATBase(STL_CONT & _c):c(_c){}; STL_CONT::value_type * Start() const; +virtual bool Empty(){}; const STL_CONT * C(); virtual void Push_back(const int &){}; @@ -108,6 +109,8 @@ void push_back(const int & n ){ for(ite = data.begin(); ite != data.end(); ++ite) (*ite)->Push_back(n); } +virtual bool Empty(){return data.empty();}; + virtual void Reserve(const int & n){ std::list::iterator ite; for(ite = data.begin(); ite != data.end(); ++ite) diff --git a/vcg/container/traced_vector.h b/vcg/container/traced_vector.h index 99e0148d..05b9955b 100644 --- a/vcg/container/traced_vector.h +++ b/vcg/container/traced_vector.h @@ -26,7 +26,7 @@ #define __VCGLIB_TRACED_VECTOR__ -#include +#include #include namespace vcg { @@ -34,6 +34,7 @@ namespace vcg { template class TVector: public std::vector{ typedef TVector THIS_TYPE; + typedef typename CATEntry >::EntryType EntryTypeMulti; public: TVector():std::vector(){reserve(1);} ~TVector(); @@ -69,9 +70,8 @@ public: template TempData NewTempData(){ - //CAT::Insert(*this) - CATEntry >::EntryType - entry = CATEntry >::GetEntry(&*begin()); + CATEntry::Insert(*this); + EntryTypeMulti entry = CATEntry::GetEntry(&*begin()); entry.Data().push_back(new Wrap< ATTR_TYPE>); ((Wrap*)entry.Data().back())->reserve(capacity()); @@ -82,8 +82,8 @@ public: template void DeleteTempData(TempData & td){ - //CAT::Insert(*this) - CATEntry >::EntryType + CATEntry::RemoveIfEmpty(*this); + EntryTypeMulti entry = CATEntry >::GetEntry(&*begin()); entry.Data().remove((Wrap*)td.Item()); @@ -99,10 +99,11 @@ private: template void TVector::push_back(const VALUE_TYPE & v){ std::vector::push_back(v); + Update(); std::list < CATBase * >::iterator ia; for(ia = attributes.begin(); ia != attributes.end(); ++ia) (*ia)->AddDataElem(&(*(this->begin())),1); - Update(); + } template void TVector::pop_back(){