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 <algorithm>
#include <assert.h>
#include <vcg/entries_allocation_table.h>
#include <vcg/container/entries_allocation_table.h>
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<ENTRY_TYPE>::iterator CATEntry<STL_CONT,ENTRY_TYPE>::
FindBase(const VALUE_TYPE * pt)
{
std::list<ENTRY_TYPE>::iterator
ite = AT().begin(),curr_base;
std::list<ENTRY_TYPE>::iterator ite,curr_base,_;
ite = AT().begin();
curr_base = AT().end();
std::list<ENTRY_TYPE> 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<ENTRY_TYPE>::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 <class STL_CONT, class 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;
}
@ -212,21 +226,30 @@ Remove(VALUE_TYPE * pt)
lower_ite = FindBase(pt);
AT().erase(lower_ite);
UTD() = false;
}
template <class STL_CONT, class ENTRY_TYPE>
void CATEntry<STL_CONT, ENTRY_TYPE>::
Insert( STL_CONT & c )
Insert( STL_CONT & c,bool cond )
{
ENTRY_TYPE entry(c);
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->Reserve(c.capacity());
lower_ite->Resize(c.size());
UTD() = false;
}
template <class STL_CONT, class ENTRY_TYPE>
ENTRY_TYPE & CATEntry<STL_CONT, ENTRY_TYPE>::
GetEntry(STL_CONT::value_type*pt){
@ -250,7 +273,6 @@ Curr()->Push_back(n);
template <class STL_CONT,class ATTR_TYPE>
class CAT:public CATEntry<STL_CONT, EntryCAT<STL_CONT,ATTR_TYPE> >{
public:
typedef typename EntryCAT<STL_CONT,ATTR_TYPE> EntryType;
static ATTR_TYPE & Get(STL_CONT::value_type * pt);
};
//---------------------- CAT: implementation---------------------------------------------------

View File

@ -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<WrapBase * >::iterator ite;
for(ite = data.begin(); ite != data.end(); ++ite)

View File

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