2004-03-31 14:40:42 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* VCGLib o o *
|
|
|
|
* Visual and Computer Graphics Library o o *
|
|
|
|
* _ O _ *
|
|
|
|
* Copyright(C) 2004 \/)\/ *
|
|
|
|
* Visual Computing Lab /\/| *
|
|
|
|
* ISTI - Italian National Research Council | *
|
|
|
|
* \ *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
|
|
|
* for more details. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
2004-04-01 00:36:44 +02:00
|
|
|
/****************************************************************************
|
|
|
|
History
|
2004-03-31 14:40:42 +02:00
|
|
|
|
2004-04-01 00:36:44 +02:00
|
|
|
$Log: not supported by cvs2svn $
|
2004-04-05 20:20:08 +02:00
|
|
|
Revision 1.3 2004/03/31 22:36:44 ganovelli
|
|
|
|
First Working Release (with this comment)
|
|
|
|
|
2004-04-01 00:36:44 +02:00
|
|
|
/****************************************************************************/
|
2004-03-31 14:40:42 +02:00
|
|
|
|
|
|
|
#ifndef __VCGLIB_TRACED_VECTOR__
|
2004-04-01 00:36:44 +02:00
|
|
|
#define __VCGLIB_TRACED_VECTOR__
|
2004-03-31 14:40:42 +02:00
|
|
|
|
|
|
|
|
2004-04-01 00:33:38 +02:00
|
|
|
#include <vcg/container/container_allocation_table.h>
|
2004-04-05 20:20:08 +02:00
|
|
|
#include <vcg/container/entries_allocation_table.h>
|
|
|
|
|
2004-03-31 14:40:42 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
namespace vcg {
|
|
|
|
|
|
|
|
template <class VALUE_TYPE>
|
|
|
|
class TVector: public std::vector<VALUE_TYPE>{
|
2004-04-05 20:20:08 +02:00
|
|
|
typedef typename TVector<VALUE_TYPE> ThisType;
|
|
|
|
|
2004-03-31 14:40:42 +02:00
|
|
|
public:
|
|
|
|
TVector():std::vector<VALUE_TYPE>(){reserve(1);}
|
|
|
|
~TVector();
|
|
|
|
|
|
|
|
|
2004-04-05 20:20:08 +02:00
|
|
|
std::list < CATBase<ThisType>* > attributes;
|
2004-03-31 14:40:42 +02:00
|
|
|
// override di tutte le funzioni che possono spostare
|
|
|
|
// l'allocazione in memoria del container
|
|
|
|
void push_back(const VALUE_TYPE & v);
|
|
|
|
void pop_back();
|
|
|
|
void resize(const unsigned int & size);
|
|
|
|
void reserve(const unsigned int & size);
|
|
|
|
|
|
|
|
template <class ATTR_TYPE>
|
|
|
|
void EnableAttribute(){
|
2004-04-05 20:20:08 +02:00
|
|
|
CAT<ThisType,ATTR_TYPE> * cat = new CAT<ThisType,ATTR_TYPE>();
|
2004-03-31 14:40:42 +02:00
|
|
|
cat->Insert(*this);
|
|
|
|
attributes.push_back(cat);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ATTR_TYPE>
|
|
|
|
void DisableAttribute(){
|
2004-04-05 20:20:08 +02:00
|
|
|
std::list < CATBase<ThisType> * >::iterator ia;
|
2004-03-31 14:40:42 +02:00
|
|
|
for(ia = attributes.begin(); ia != attributes.end(); ++ia)
|
2004-04-05 20:20:08 +02:00
|
|
|
if((*ia)->Id() == CAT<ThisType,ATTR_TYPE>::Id())
|
2004-03-31 14:40:42 +02:00
|
|
|
{
|
|
|
|
(*ia)->Remove(*this);
|
|
|
|
delete (*ia);
|
|
|
|
attributes.erase(ia);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ATTR_TYPE>
|
2004-04-05 20:20:08 +02:00
|
|
|
TempData<ThisType,ATTR_TYPE> NewTempData(){
|
|
|
|
typedef typename CATEntry<ThisType,EntryCATMulti<ThisType> >::EntryType EntryTypeMulti;
|
|
|
|
CATEntry<ThisType,EntryTypeMulti>::Insert(*this);
|
|
|
|
EntryTypeMulti entry = CATEntry<ThisType,EntryTypeMulti >::GetEntry(&*begin());
|
2004-03-31 14:40:42 +02:00
|
|
|
entry.Data().push_back(new Wrap< ATTR_TYPE>);
|
|
|
|
|
|
|
|
((Wrap<ATTR_TYPE>*)entry.Data().back())->reserve(capacity());
|
|
|
|
((Wrap<ATTR_TYPE>*)entry.Data().back())->resize(size());
|
|
|
|
|
2004-04-05 20:20:08 +02:00
|
|
|
return TempData<ThisType,ATTR_TYPE>((Wrap<ATTR_TYPE>*) entry.Data().back());
|
2004-03-31 14:40:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ATTR_TYPE>
|
2004-04-05 20:20:08 +02:00
|
|
|
void DeleteTempData(TempData<ThisType,ATTR_TYPE> & td){
|
|
|
|
typedef typename CATEntry<ThisType,EntryCATMulti<ThisType> >::EntryType EntryTypeMulti;
|
|
|
|
CATEntry<ThisType,EntryTypeMulti >::RemoveIfEmpty(*this);
|
2004-04-01 00:33:38 +02:00
|
|
|
EntryTypeMulti
|
2004-04-05 20:20:08 +02:00
|
|
|
entry = CATEntry<ThisType,EntryCATMulti<ThisType> >::GetEntry(&*begin());
|
2004-03-31 14:40:42 +02:00
|
|
|
|
|
|
|
entry.Data().remove((Wrap<ATTR_TYPE>*)td.Item());
|
|
|
|
delete ((Wrap<ATTR_TYPE>*)td.Item());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
VALUE_TYPE * old_start;
|
|
|
|
void Update();
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class VALUE_TYPE>
|
|
|
|
void TVector<VALUE_TYPE>::push_back(const VALUE_TYPE & v){
|
|
|
|
std::vector<VALUE_TYPE>::push_back(v);
|
2004-04-01 00:33:38 +02:00
|
|
|
Update();
|
2004-04-05 20:20:08 +02:00
|
|
|
std::list < CATBase<ThisType> * >::iterator ia;
|
2004-03-31 14:40:42 +02:00
|
|
|
for(ia = attributes.begin(); ia != attributes.end(); ++ia)
|
|
|
|
(*ia)->AddDataElem(&(*(this->begin())),1);
|
2004-04-01 00:33:38 +02:00
|
|
|
|
2004-03-31 14:40:42 +02:00
|
|
|
}
|
|
|
|
template <class VALUE_TYPE>
|
|
|
|
void TVector<VALUE_TYPE>::pop_back(){
|
|
|
|
std::vector<VALUE_TYPE>::pop_back();
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class VALUE_TYPE>
|
|
|
|
void TVector<VALUE_TYPE>::resize(const unsigned int & size){
|
|
|
|
std::vector<VALUE_TYPE>::resize(size);
|
2004-04-05 20:20:08 +02:00
|
|
|
std::list < CATBase<ThisType> * >::iterator ia;
|
2004-03-31 14:40:42 +02:00
|
|
|
for(ia = attributes.begin(); ia != attributes.end(); ++ia)
|
|
|
|
(*ia)->
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class VALUE_TYPE>
|
|
|
|
void TVector<VALUE_TYPE>::reserve(const unsigned int & size){
|
|
|
|
std::vector<VALUE_TYPE>::reserve(size);
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class VALUE_TYPE>
|
|
|
|
void TVector<VALUE_TYPE>::
|
|
|
|
Update(){
|
2004-04-05 20:20:08 +02:00
|
|
|
std::list < CATBase<ThisType> * >::iterator ia;
|
2004-03-31 14:40:42 +02:00
|
|
|
if(&(*begin()) != old_start)
|
|
|
|
for(ia = attributes.begin(); ia != attributes.end(); ++ia)
|
|
|
|
(*ia)->Resort(old_start,&(*begin()));
|
|
|
|
|
|
|
|
old_start = &(*begin());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class VALUE_TYPE>
|
|
|
|
TVector<VALUE_TYPE>::~TVector(){
|
2004-04-05 20:20:08 +02:00
|
|
|
std::list < CATBase<ThisType> * >::iterator ia;
|
2004-03-31 14:40:42 +02:00
|
|
|
for(ia = attributes.begin(); ia != attributes.end(); ++ia)
|
|
|
|
{
|
|
|
|
(*ia)->Remove(*this);
|
|
|
|
delete *ia;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}; // end namespace
|
|
|
|
#endif
|