one bug corrected and other minor changes

This commit is contained in:
ganovelli 2004-03-31 22:33:38 +00:00
parent 0ede25d91c
commit c121ea989e
3 changed files with 48 additions and 22 deletions

View File

@ -29,7 +29,7 @@
#include <list> #include <list>
#include <algorithm> #include <algorithm>
#include <assert.h> #include <assert.h>
#include <vcg/entries_allocation_table.h> #include <vcg/container/entries_allocation_table.h>
namespace vcg { namespace vcg {
@ -69,8 +69,9 @@ CATEntry(){if(Id()==0){
static unsigned int Ord(VALUE_TYPE *); static unsigned int Ord(VALUE_TYPE *);
static ENTRY_TYPE & GetEntry(STL_CONT::value_type*pt); static ENTRY_TYPE & GetEntry(STL_CONT::value_type*pt);
static void Insert( STL_CONT & c ); // insert a vector to trace 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 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 static void Remove( VALUE_TYPE * v); // remove the container that contains v
virtual void Resort( VALUE_TYPE* old_start, // resort the allocation table virtual void Resort( VALUE_TYPE* old_start, // resort the allocation table
@ -133,10 +134,10 @@ std::list<ENTRY_TYPE>::iterator CATEntry<STL_CONT,ENTRY_TYPE>::
FindBase(const VALUE_TYPE * pt) FindBase(const VALUE_TYPE * pt)
{ {
std::list<ENTRY_TYPE>::iterator std::list<ENTRY_TYPE>::iterator ite,curr_base,_;
ite = AT().begin(),curr_base; ite = AT().begin();
curr_base = AT().end();
std::list<ENTRY_TYPE> tmp = AT();
for(;ite != AT().end();ite++) for(;ite != AT().end();ite++)
if( pt < (*ite).Start()) if( pt < (*ite).Start())
return curr_base; return curr_base;
@ -195,7 +196,7 @@ Remove( const STL_CONT & c )
{ {
std::list<ENTRY_TYPE>::iterator ite; std::list<ENTRY_TYPE>::iterator ite;
for(ite = AT().begin(); ite != AT().end(); ++ite) for(ite = AT().begin(); ite != AT().end(); ++ite)
if((*ite).C() == &c) if((*ite).C() == &c)
{ {
AT().erase(ite); AT().erase(ite);
break; break;
@ -206,27 +207,49 @@ UTD() = false;
template <class STL_CONT, class ENTRY_TYPE> template <class STL_CONT, class ENTRY_TYPE>
void CATEntry<STL_CONT, ENTRY_TYPE>:: void CATEntry<STL_CONT, ENTRY_TYPE>::
RemoveIfEmpty( const STL_CONT & c )
{
std::list<ENTRY_TYPE>::iterator ite;
for(ite = AT().begin(); ite != AT().end(); ++ite)
if((*ite).C() == &c)
if(!(*ite).Empty())
AT().erase(ite);
UTD() = false;
}
template <class STL_CONT, class ENTRY_TYPE>
void CATEntry<STL_CONT, ENTRY_TYPE>::
Remove(VALUE_TYPE * pt) Remove(VALUE_TYPE * pt)
{ {
std::list<ENTRY_TYPE>::iterator lower_ite; std::list<ENTRY_TYPE>::iterator lower_ite;
lower_ite = FindBase(pt); lower_ite = FindBase(pt);
AT().erase(lower_ite); AT().erase(lower_ite);
UTD() = false; UTD() = false;
} }
template <class STL_CONT, class ENTRY_TYPE> template <class STL_CONT, class ENTRY_TYPE>
void CATEntry<STL_CONT, ENTRY_TYPE>:: void CATEntry<STL_CONT, ENTRY_TYPE>::
Insert( STL_CONT & c ) Insert( STL_CONT & c,bool cond )
{ {
ENTRY_TYPE entry(c); ENTRY_TYPE entry(c);
std::list<ENTRY_TYPE>::iterator lower_ite,upper_ite; std::list<ENTRY_TYPE>::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 = AT().insert(upper_ite,entry);
lower_ite->Reserve(c.capacity()); lower_ite->Reserve(c.capacity());
lower_ite->Resize(c.size()); lower_ite->Resize(c.size());
UTD() = false; UTD() = false;
} }
template <class STL_CONT, class ENTRY_TYPE> template <class STL_CONT, class ENTRY_TYPE>
ENTRY_TYPE & CATEntry<STL_CONT, ENTRY_TYPE>:: ENTRY_TYPE & CATEntry<STL_CONT, ENTRY_TYPE>::
GetEntry(STL_CONT::value_type*pt){ GetEntry(STL_CONT::value_type*pt){
@ -250,7 +273,6 @@ Curr()->Push_back(n);
template <class STL_CONT,class ATTR_TYPE> template <class STL_CONT,class ATTR_TYPE>
class CAT:public CATEntry<STL_CONT, EntryCAT<STL_CONT,ATTR_TYPE> >{ class CAT:public CATEntry<STL_CONT, EntryCAT<STL_CONT,ATTR_TYPE> >{
public: public:
typedef typename EntryCAT<STL_CONT,ATTR_TYPE> EntryType;
static ATTR_TYPE & Get(STL_CONT::value_type * pt); static ATTR_TYPE & Get(STL_CONT::value_type * pt);
}; };
//---------------------- CAT: implementation--------------------------------------------------- //---------------------- CAT: implementation---------------------------------------------------

View File

@ -34,6 +34,7 @@ struct EntryCATBase{
EntryCATBase(STL_CONT & _c):c(_c){}; EntryCATBase(STL_CONT & _c):c(_c){};
STL_CONT::value_type * Start() const; STL_CONT::value_type * Start() const;
virtual bool Empty(){};
const STL_CONT * C(); const STL_CONT * C();
virtual void Push_back(const int &){}; virtual void Push_back(const int &){};
@ -108,6 +109,8 @@ void push_back(const int & n ){
for(ite = data.begin(); ite != data.end(); ++ite) for(ite = data.begin(); ite != data.end(); ++ite)
(*ite)->Push_back(n); (*ite)->Push_back(n);
} }
virtual bool Empty(){return data.empty();};
virtual void Reserve(const int & n){ virtual void Reserve(const int & n){
std::list<WrapBase * >::iterator ite; std::list<WrapBase * >::iterator ite;
for(ite = data.begin(); ite != data.end(); ++ite) for(ite = data.begin(); ite != data.end(); ++ite)

View File

@ -26,7 +26,7 @@
#define __VCGLIB_TRACED_VECTOR__ #define __VCGLIB_TRACED_VECTOR__
#include <vcg/container_allocation_table.h> #include <vcg/container/container_allocation_table.h>
#include <assert.h> #include <assert.h>
namespace vcg { namespace vcg {
@ -34,6 +34,7 @@ namespace vcg {
template <class VALUE_TYPE> template <class VALUE_TYPE>
class TVector: public std::vector<VALUE_TYPE>{ class TVector: public std::vector<VALUE_TYPE>{
typedef TVector<VALUE_TYPE> THIS_TYPE; typedef TVector<VALUE_TYPE> THIS_TYPE;
typedef typename CATEntry<THIS_TYPE,EntryCATMulti<THIS_TYPE> >::EntryType EntryTypeMulti;
public: public:
TVector():std::vector<VALUE_TYPE>(){reserve(1);} TVector():std::vector<VALUE_TYPE>(){reserve(1);}
~TVector(); ~TVector();
@ -69,9 +70,8 @@ public:
template <class ATTR_TYPE> template <class ATTR_TYPE>
TempData<THIS_TYPE,ATTR_TYPE> NewTempData(){ TempData<THIS_TYPE,ATTR_TYPE> NewTempData(){
//CAT<THIS_TYPE,EntryCATMulti>::Insert(*this) CATEntry<THIS_TYPE,EntryTypeMulti>::Insert(*this);
CATEntry<THIS_TYPE,EntryCATMulti<THIS_TYPE> >::EntryType EntryTypeMulti entry = CATEntry<THIS_TYPE,EntryTypeMulti >::GetEntry(&*begin());
entry = CATEntry<THIS_TYPE,EntryCATMulti<THIS_TYPE> >::GetEntry(&*begin());
entry.Data().push_back(new Wrap< ATTR_TYPE>); entry.Data().push_back(new Wrap< ATTR_TYPE>);
((Wrap<ATTR_TYPE>*)entry.Data().back())->reserve(capacity()); ((Wrap<ATTR_TYPE>*)entry.Data().back())->reserve(capacity());
@ -82,8 +82,8 @@ public:
template <class ATTR_TYPE> template <class ATTR_TYPE>
void DeleteTempData(TempData<THIS_TYPE,ATTR_TYPE> & td){ void DeleteTempData(TempData<THIS_TYPE,ATTR_TYPE> & td){
//CAT<THIS_TYPE,EntryCATMulti>::Insert(*this) CATEntry<THIS_TYPE,EntryTypeMulti >::RemoveIfEmpty(*this);
CATEntry<THIS_TYPE,EntryCATMulti<THIS_TYPE> >::EntryType EntryTypeMulti
entry = CATEntry<THIS_TYPE,EntryCATMulti<THIS_TYPE> >::GetEntry(&*begin()); entry = CATEntry<THIS_TYPE,EntryCATMulti<THIS_TYPE> >::GetEntry(&*begin());
entry.Data().remove((Wrap<ATTR_TYPE>*)td.Item()); entry.Data().remove((Wrap<ATTR_TYPE>*)td.Item());
@ -99,10 +99,11 @@ private:
template <class VALUE_TYPE> template <class VALUE_TYPE>
void TVector<VALUE_TYPE>::push_back(const VALUE_TYPE & v){ void TVector<VALUE_TYPE>::push_back(const VALUE_TYPE & v){
std::vector<VALUE_TYPE>::push_back(v); std::vector<VALUE_TYPE>::push_back(v);
Update();
std::list < CATBase<THIS_TYPE> * >::iterator ia; std::list < CATBase<THIS_TYPE> * >::iterator ia;
for(ia = attributes.begin(); ia != attributes.end(); ++ia) for(ia = attributes.begin(); ia != attributes.end(); ++ia)
(*ia)->AddDataElem(&(*(this->begin())),1); (*ia)->AddDataElem(&(*(this->begin())),1);
Update();
} }
template <class VALUE_TYPE> template <class VALUE_TYPE>
void TVector<VALUE_TYPE>::pop_back(){ void TVector<VALUE_TYPE>::pop_back(){