Include header cleaning and reordering.
This commit is contained in:
parent
fba7d7873e
commit
f2bbdb787a
|
@ -19,51 +19,22 @@
|
||||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
||||||
* for more details. *
|
* for more details. *
|
||||||
* *
|
* *
|
||||||
****************************************************************************/
|
|
||||||
/****************************************************************************
|
|
||||||
History
|
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
|
||||||
Revision 1.7 2008/05/16 08:48:49 ganovelli
|
|
||||||
Enable() and Disable() removed. The memory is allocated by the contructor
|
|
||||||
|
|
||||||
Revision 1.6 2008/05/15 16:35:17 ganovelli
|
|
||||||
Start() Stop() removed. Allocation on creation, disallocaiton on distruction
|
|
||||||
|
|
||||||
Revision 1.5 2007/02/02 00:01:54 tarini
|
|
||||||
overloaded operator "[]" (once more) to make it possible to index the temp. structure with an iterator
|
|
||||||
|
|
||||||
Revision 1.4 2005/07/11 13:12:34 cignoni
|
|
||||||
small gcc-related compiling issues (typenames,ending cr, initialization order)
|
|
||||||
|
|
||||||
Revision 1.3 2004/12/11 15:37:47 ganovelli
|
|
||||||
added one more [], now it is polymorphic, added typenames
|
|
||||||
|
|
||||||
Revision 1.2 2004/03/31 22:36:44 ganovelli
|
|
||||||
First Working Release (with this comment)
|
|
||||||
|
|
||||||
|
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef __VCGLIB_SIMPLE__
|
#ifndef __VCGLIB_SIMPLE__
|
||||||
#define __VCGLIB_SIMPLE__
|
#define __VCGLIB_SIMPLE__
|
||||||
|
|
||||||
#include <limits>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <vector>
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
namespace vcg {
|
namespace vcg {
|
||||||
|
|
||||||
class SimpleTempDataBase{
|
class SimpleTempDataBase{
|
||||||
public:
|
public:
|
||||||
virtual ~SimpleTempDataBase() {}
|
virtual ~SimpleTempDataBase() {}
|
||||||
SimpleTempDataBase() {}
|
SimpleTempDataBase() {}
|
||||||
virtual void Resize(const int & sz) = 0;
|
virtual void Resize(const int & sz) = 0;
|
||||||
virtual void Reorder(std::vector<size_t> & newVertIndex)=0;
|
virtual void Reorder(std::vector<size_t> & newVertIndex)=0;
|
||||||
virtual int SizeOf() const = 0;
|
virtual int SizeOf() const = 0;
|
||||||
virtual void * DataBegin() = 0;
|
virtual void * DataBegin() = 0;
|
||||||
virtual void * At(unsigned int i ) = 0;
|
virtual void * At(unsigned int i ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class TYPE>
|
template <class TYPE>
|
||||||
|
@ -72,112 +43,112 @@ class VectorNBW: public std::vector<TYPE> {};
|
||||||
template <>
|
template <>
|
||||||
class VectorNBW<bool>{
|
class VectorNBW<bool>{
|
||||||
public:
|
public:
|
||||||
VectorNBW():data(0),datasize(0),datareserve(0){}
|
VectorNBW():data(0),datasize(0),datareserve(0){}
|
||||||
bool * data ;
|
bool * data ;
|
||||||
|
|
||||||
void reserve (const int & sz) {
|
void reserve (const int & sz) {
|
||||||
if(sz<=datareserve) return;
|
if(sz<=datareserve) return;
|
||||||
bool * newdataLoc = new bool[ sz ];
|
bool * newdataLoc = new bool[ sz ];
|
||||||
if(datasize!=0) memcpy(newdataLoc,data,sizeof(datasize));
|
if(datasize!=0) memcpy(newdataLoc,data,sizeof(datasize));
|
||||||
std::swap(data,newdataLoc);
|
std::swap(data,newdataLoc);
|
||||||
if(newdataLoc != 0) delete newdataLoc;
|
if(newdataLoc != 0) delete newdataLoc;
|
||||||
datareserve = sz;
|
datareserve = sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize (const int & sz) {
|
void resize (const int & sz) {
|
||||||
int oldDatasize = datasize;
|
int oldDatasize = datasize;
|
||||||
if(sz <= oldDatasize) return;
|
if(sz <= oldDatasize) return;
|
||||||
if(sz > datareserve)
|
if(sz > datareserve)
|
||||||
reserve(sz);
|
reserve(sz);
|
||||||
datasize = sz;
|
datasize = sz;
|
||||||
memset(&data[oldDatasize],0,datasize-oldDatasize);
|
memset(&data[oldDatasize],0,datasize-oldDatasize);
|
||||||
}
|
}
|
||||||
void push_back(const bool & v) { resize(datasize+1); data[datasize] = v;}
|
void push_back(const bool & v) { resize(datasize+1); data[datasize] = v;}
|
||||||
|
|
||||||
void clear(){ datasize = 0;}
|
void clear(){ datasize = 0;}
|
||||||
|
|
||||||
unsigned int size() const { return datasize;}
|
unsigned int size() const { return datasize;}
|
||||||
|
|
||||||
bool empty() const {return datasize==0;}
|
bool empty() const {return datasize==0;}
|
||||||
|
|
||||||
bool * begin() const {return data;}
|
bool * begin() const {return data;}
|
||||||
|
|
||||||
bool & operator [](const int & i){return data[i];}
|
bool & operator [](const int & i){return data[i];}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int datasize;
|
int datasize;
|
||||||
int datareserve;
|
int datareserve;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class STL_CONT, class ATTR_TYPE>
|
template <class STL_CONT, class ATTR_TYPE>
|
||||||
class SimpleTempData:public SimpleTempDataBase{
|
class SimpleTempData:public SimpleTempDataBase{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef SimpleTempData<STL_CONT,ATTR_TYPE> SimpTempDataType;
|
typedef SimpleTempData<STL_CONT,ATTR_TYPE> SimpTempDataType;
|
||||||
typedef ATTR_TYPE AttrType;
|
typedef ATTR_TYPE AttrType;
|
||||||
|
|
||||||
STL_CONT& c;
|
STL_CONT& c;
|
||||||
VectorNBW<ATTR_TYPE> data;
|
VectorNBW<ATTR_TYPE> data;
|
||||||
int padding;
|
int padding;
|
||||||
|
|
||||||
SimpleTempData(STL_CONT &_c):c(_c),padding(0){data.reserve(c.capacity());data.resize(c.size());};
|
SimpleTempData(STL_CONT &_c):c(_c),padding(0){data.reserve(c.capacity());data.resize(c.size());};
|
||||||
SimpleTempData(STL_CONT &_c, const ATTR_TYPE &val):c(_c){
|
SimpleTempData(STL_CONT &_c, const ATTR_TYPE &val):c(_c){
|
||||||
data.reserve(c.capacity());data.resize(c.size());
|
data.reserve(c.capacity());data.resize(c.size());
|
||||||
Init(val);
|
Init(val);
|
||||||
};
|
};
|
||||||
|
|
||||||
~SimpleTempData(){data.clear();}
|
~SimpleTempData(){data.clear();}
|
||||||
|
|
||||||
void Init(const ATTR_TYPE &val)
|
void Init(const ATTR_TYPE &val)
|
||||||
{
|
{
|
||||||
std::fill(data.begin(),data.end(),val);
|
std::fill(data.begin(),data.end(),val);
|
||||||
}
|
}
|
||||||
// access to data
|
// access to data
|
||||||
ATTR_TYPE & operator[](const typename STL_CONT::value_type & v){return data[&v-&*c.begin()];}
|
ATTR_TYPE & operator[](const typename STL_CONT::value_type & v){return data[&v-&*c.begin()];}
|
||||||
ATTR_TYPE & operator[](const typename STL_CONT::value_type * v){return data[v-&*c.begin()];}
|
ATTR_TYPE & operator[](const typename STL_CONT::value_type * v){return data[v-&*c.begin()];}
|
||||||
ATTR_TYPE & operator[](const typename STL_CONT::iterator & cont){return data[&(*cont)-&*c.begin()];}
|
ATTR_TYPE & operator[](const typename STL_CONT::iterator & cont){return data[&(*cont)-&*c.begin()];}
|
||||||
ATTR_TYPE & operator[](const int & i){return data[i];}
|
ATTR_TYPE & operator[](const int & i){return data[i];}
|
||||||
|
|
||||||
void * At(unsigned int i ) {return &(*this)[i];};
|
void * At(unsigned int i ) {return &(*this)[i];};
|
||||||
|
|
||||||
// update temporary data size
|
// update temporary data size
|
||||||
bool UpdateSize(){
|
bool UpdateSize(){
|
||||||
if(data.size() != c.size())
|
if(data.size() != c.size())
|
||||||
{
|
{
|
||||||
data.resize(c.size());
|
data.resize(c.size());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resize(const int & sz){
|
void Resize(const int & sz){
|
||||||
data.resize(sz);
|
data.resize(sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Reorder(std::vector<size_t> & newVertIndex){
|
void Reorder(std::vector<size_t> & newVertIndex){
|
||||||
for(unsigned int i = 0 ; i < data.size(); ++i){
|
for(unsigned int i = 0 ; i < data.size(); ++i){
|
||||||
if( newVertIndex[i] != (std::numeric_limits<size_t>::max)())
|
if( newVertIndex[i] != (std::numeric_limits<size_t>::max)())
|
||||||
data[newVertIndex[i]] = data[i];
|
data[newVertIndex[i]] = data[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int SizeOf() const {return sizeof(ATTR_TYPE);}
|
int SizeOf() const {return sizeof(ATTR_TYPE);}
|
||||||
void * DataBegin() {return data.empty()?NULL:&(*data.begin());}
|
void * DataBegin() {return data.empty()?NULL:&(*data.begin());}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class ATTR_TYPE>
|
template <class ATTR_TYPE>
|
||||||
class Attribute: public SimpleTempDataBase {
|
class Attribute: public SimpleTempDataBase {
|
||||||
public:
|
public:
|
||||||
typedef ATTR_TYPE AttrType;
|
typedef ATTR_TYPE AttrType;
|
||||||
AttrType * attribute;
|
AttrType * attribute;
|
||||||
Attribute(){attribute = new ATTR_TYPE();}
|
Attribute(){attribute = new ATTR_TYPE();}
|
||||||
~Attribute(){delete attribute;}
|
~Attribute(){delete attribute;}
|
||||||
int SizeOf()const {return sizeof(ATTR_TYPE);}
|
int SizeOf()const {return sizeof(ATTR_TYPE);}
|
||||||
void * DataBegin(){return attribute;}
|
void * DataBegin(){return attribute;}
|
||||||
|
|
||||||
void Resize(const int & ) {assert(0);}
|
void Resize(const int & ) {assert(0);}
|
||||||
void Reorder(std::vector<size_t> & ){assert(0);}
|
void Reorder(std::vector<size_t> & ){assert(0);}
|
||||||
void * At(unsigned int ) {assert(0);return (void*)0;}
|
void * At(unsigned int ) {assert(0);return (void*)0;}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace vcg
|
} // end namespace vcg
|
||||||
|
|
Loading…
Reference in New Issue