fix VectorNBW bool specialization with const

This commit is contained in:
alemuntoni 2021-03-23 12:59:45 +01:00
parent f83bdf0815
commit bf6c48f9be
1 changed files with 20 additions and 15 deletions

View File

@ -24,6 +24,11 @@
#ifndef __VCGLIB_SIMPLE__ #ifndef __VCGLIB_SIMPLE__
#define __VCGLIB_SIMPLE__ #define __VCGLIB_SIMPLE__
#include <string.h>
#include <limits>
#include <vector>
#include <assert.h>
namespace vcg namespace vcg
{ {
@ -42,16 +47,16 @@ public:
virtual void CopyValue(const size_t to, const size_t from, const SimpleTempDataBase *other) = 0; virtual void CopyValue(const size_t to, const size_t from, const SimpleTempDataBase *other) = 0;
}; };
template <class TYPE> template <class TYPE, class ...p>
class VectorNBW : public std::vector<TYPE> class VectorNBW : public std::vector<TYPE, p...>
{ {
}; };
template <> template <class ...p>
class VectorNBW<bool> class VectorNBW<bool, p...>
{ {
public: public:
VectorNBW() : data(0), datasize(0), datareserve(0) {} VectorNBW() : data(nullptr), datasize(0), datareserve(0) {}
~VectorNBW() ~VectorNBW()
{ {
@ -59,22 +64,20 @@ public:
delete[] data; delete[] data;
} }
bool *data; void reserve(size_t sz)
void reserve(const int &sz)
{ {
if (sz <= datareserve) if (sz <= datareserve)
return; return;
bool *newdataLoc = new bool[sz]; bool *newdataLoc = new bool[sz];
if (datasize != 0) if (datasize != 0)
memcpy(newdataLoc, data, sizeof(datasize)); memcpy(newdataLoc, data, sizeof(bool) * sizeof(datasize));
std::swap(data, newdataLoc); std::swap(data, newdataLoc);
if (newdataLoc != 0) if (newdataLoc != 0)
delete[] newdataLoc; delete[] newdataLoc;
datareserve = sz; datareserve = sz;
} }
void resize(const int &sz) void resize(size_t sz)
{ {
int oldDatasize = datasize; int oldDatasize = datasize;
if (sz <= oldDatasize) if (sz <= oldDatasize)
@ -96,14 +99,16 @@ public:
bool empty() const { return datasize == 0; } bool empty() const { return datasize == 0; }
bool *begin() const { return data; } bool* begin() {return data;}
const bool *begin() const { return data; }
bool &operator[](const int &i) { return data[i]; } bool &operator[](size_t i) { return data[i]; }
const bool &operator[](const int &i) const { return data[i]; } const bool &operator[](size_t i) const { return data[i]; }
private: private:
int datasize; bool *data;
int datareserve; size_t datasize;
size_t datareserve;
}; };
template <class STL_CONT, class ATTR_TYPE> template <class STL_CONT, class ATTR_TYPE>