From b6f21780dc2c77b5000ee476890841f0490d9f33 Mon Sep 17 00:00:00 2001 From: ganovelli Date: Wed, 12 Nov 2008 16:10:04 +0000 Subject: [PATCH] added workaround for std::vector bitwise implementation. The workaround is a rough reimplementation of std::vector. If you can, use "char" as temporary data and cast it when you need. --- vcg/container/simple_temporary_data.h | 115 +++++++++++++++++--------- 1 file changed, 77 insertions(+), 38 deletions(-) diff --git a/vcg/container/simple_temporary_data.h b/vcg/container/simple_temporary_data.h index b21cc9a3..27669474 100644 --- a/vcg/container/simple_temporary_data.h +++ b/vcg/container/simple_temporary_data.h @@ -63,56 +63,95 @@ public: virtual int SizeOf() const = 0; }; +template +struct VectorNBW: public std::vector {}; + +template <> +class VectorNBW{ +public: + VectorNBW():data(0),datasize(0),datareserve(0){} + bool * data ; + + void reserve (const int & sz) { + if(sz<=datareserve) return; + bool * newdataLoc = new bool[ sz ]; + if(datasize!=0) memcpy(newdataLoc,data,sizeof(datasize)); + std::swap(data,newdataLoc); + if(newdataLoc != 0) delete newdataLoc; + datareserve = sz; + } + + void resize (const int & sz) { + int oldDatasize = datasize; + datasize = sz; + if(datasize <= oldDatasize) return; + if(datasize > datareserve) + reserve(datasize); + memset(&data[oldDatasize],0,datasize-oldDatasize); + } + void push_back(const bool & v) { resize(datasize+1); data[datasize] = v;} + + void clear(){ datasize = 0;} + + const unsigned int & size() const { return datasize;} + + bool & operator [](const int & i){return data[i];} + +private: + int datasize; + int datareserve; +}; + template class SimpleTempData:public SimpleTempDataBase{ -public: -typedef SimpleTempData SimpTempDataType; -typedef ATTR_TYPE AttrType; + public: + typedef SimpleTempData SimpTempDataType; + typedef ATTR_TYPE AttrType; -STL_CONT& c; -std::vector data; + STL_CONT& c; + VectorNBW data; -SimpleTempData(STL_CONT &_c):c(_c){data.reserve(c.capacity());data.resize(c.size());}; -SimpleTempData(STL_CONT &_c, const ATTR_TYPE &val):c(_c){ - data.reserve(c.capacity());data.resize(c.size()); - Init(val); -}; + SimpleTempData(STL_CONT &_c):c(_c){data.reserve(c.capacity());data.resize(c.size());}; + SimpleTempData(STL_CONT &_c, const ATTR_TYPE &val):c(_c){ + data.reserve(c.capacity());data.resize(c.size()); + Init(val); + }; -~SimpleTempData(){data.clear();} + ~SimpleTempData(){data.clear();} -void Init(const ATTR_TYPE &val) -{ - std::fill(data.begin(),data.end(),val); -} -// 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::iterator & cont){return data[&(*cont)-&*c.begin()];} -ATTR_TYPE & operator[](const int & i){return data[i];} + void Init(const ATTR_TYPE &val) + { + std::fill(data.begin(),data.end(),val); + } + // 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::iterator & cont){return data[&(*cont)-&*c.begin()];} + ATTR_TYPE & operator[](const int & i){return data[i];} -// update temporary data size -bool UpdateSize(){ - if(data.size() != c.size()) - { - data.resize(c.size()); - return false; - } - return true; + // update temporary data size + bool UpdateSize(){ + if(data.size() != c.size()) + { + data.resize(c.size()); + return false; + } + return true; + } + + void Resize(const int & sz){ + data.resize(sz); } -void Resize(const int & sz){ - data.resize(sz); -} - -void Reorder(std::vector & newVertIndex){ - for(unsigned int i = 0 ; i < data.size(); ++i){ - if( newVertIndex[i] != std::numeric_limits::max()) - data[newVertIndex[i]] = data[i]; + void Reorder(std::vector & newVertIndex){ + for(unsigned int i = 0 ; i < data.size(); ++i){ + if( newVertIndex[i] != std::numeric_limits::max()) + data[newVertIndex[i]] = data[i]; + } } -} -int SizeOf() const {return sizeof(ATTR_TYPE);} + int SizeOf() const {return sizeof(ATTR_TYPE);} }; class AttributeBase{