35#ifdef ENABLE_VECTORDEBUG
36#define VECTORDEBUG(...) { printf(__VA_ARGS__); printf(" this=%p [%p,%p,%p]\n",(void*)this,(void*)&mData,mStart,mEnd); }
39#define VECTORDEBUG(...)
42#define BITVECTOR_REFCNTS 0
46template <
class T>
class RCData :
public RefCntBase {
138 mData = elements ?
new T[elements] : NULL;
147 VECTORDEBUG(
"VectorBase::shiftMem(%p)",(
void*)&other);
149 this->mData=other.
mData;
150 this->mStart=other.
mStart;
151 this->mEnd=other.
mEnd;
162 this->mStart=
const_cast<T*
>(other.
mStart);
163 this->mEnd=
const_cast<T*
>(other.
mEnd);
182 VECTORDEBUG(
"VectorBase::resize(%p,%d) %s",
this,newElements, (
mData?
"delete":
""));
199 memcpy(this->mStart, other1.
mStart, other1.
bytes());
226 snprintf(buf,100,
" mData=%p mStart=%p mEnd=%p ",(
void*)
mData,
mStart,
mEnd);
227 return std::string(buf);
239 T* base = other.
mStart + start;
240 assert(base+span<=other.
mEnd);
242 memcpy(base,
mStart,span*
sizeof(T));
259 const T* base =
mStart + start;
260 assert(base+span<=
mEnd);
262 memcpy(other.
mStart,base,span*
sizeof(T));
268 while (dp<
mEnd) *dp++=val;
271 void fill(
const T& val,
unsigned start,
unsigned length)
276 while (dp<
end) *dp++=val;
310 const T*
getData()
const {
return this->mData.isNULL() ? 0 : this->mData->mPointer; }
338 assert(this->mData == 0);
353 T* wStart = this->mStart + start;
354 T* wEnd = wStart + span;
355 assert(wEnd<=this->
mEnd);
362 T* wStart = this->mStart + start;
363 T* wEnd = wStart + span;
364 assert(wEnd<=this->
mEnd);
390 for (
unsigned i=0; i<v.
size(); i++) os << v[i] <<
" ";
#define VECTORDEBUG(...)
Definition Vector.h:39
std::ostream & operator<<(std::ostream &os, const Vector< T > &v)
Definition Vector.h:388
void operator=(const VectorBase< T > &other)
Definition Vector.h:282
T * begin()
Definition Vector.h:306
void fill(const T &val, unsigned start, unsigned length)
Definition Vector.h:271
T * VectorDataType
Definition Vector.h:129
size_t size() const
Definition Vector.h:169
VectorDataType mData
allocated data block.
Definition Vector.h:131
void vInit(size_t elements)
Definition Vector.h:136
std::string inspect() const
Definition Vector.h:224
const T * getData() const
Definition Vector.h:312
void vConcat(const VectorBase< T > &other1, const VectorBase< T > &other2)
Definition Vector.h:197
VectorBase()
Definition Vector.h:205
void segmentCopyTo(VectorBase< T > &other, size_t start, size_t span) const
Definition Vector.h:257
T * end()
Definition Vector.h:308
const T * end() const
Definition Vector.h:307
void copyToSegment(VectorBase< T > &other, size_t start, size_t span) const
Definition Vector.h:237
void clear()
Definition Vector.h:188
T * mStart
start of useful data
Definition Vector.h:132
void copyTo(VectorBase< T > &other) const
Definition Vector.h:248
void copyToSegment(VectorBase< T > &other, size_t start=0) const
Definition Vector.h:246
T & operator[](size_t index)
Definition Vector.h:293
bool isOwner()
Definition Vector.h:222
void clone(const VectorBase< T > &other)
Definition Vector.h:192
size_t bytes() const
Definition Vector.h:177
void fill(const T &val)
Definition Vector.h:265
const T & operator[](size_t index) const
Definition Vector.h:299
T * mEnd
end of useful data + 1
Definition Vector.h:133
~VectorBase()
Definition Vector.h:216
void resize(size_t newElements)
Definition Vector.h:180
void makeAlias(const VectorBase< T > &other)
Definition Vector.h:156
const T * begin() const
Definition Vector.h:305
VectorBase(VectorDataType wData, T *wStart, T *wEnd)
Definition Vector.h:208
void shiftMem(VectorBase< T > &other)
Definition Vector.h:145
const Vector< T > segment(size_t start, size_t span) const
Definition Vector.h:360
const Vector< T > tail(size_t start) const
Definition Vector.h:371
void operator=(Vector< T > &other)
Definition Vector.h:345
Vector(T *wData, T *wStart, T *wEnd)
Definition Vector.h:331
T * iterator
Definition Vector.h:375
const Vector< T > head(size_t span) const
Definition Vector.h:369
Vector(const Vector< T > &other1, const Vector< T > &other2)
Definition Vector.h:337
Vector< T > head(size_t span)
Definition Vector.h:368
Vector< T > tail(size_t start)
Definition Vector.h:370
Vector< T > segment(size_t start, size_t span)
Definition Vector.h:351
const T * const_iterator
Definition Vector.h:376
Vector(const Vector< T > &other)
Definition Vector.h:328
Vector(T *wStart, size_t span)
Definition Vector.h:334
void operator=(const Vector< T > &other)
Definition Vector.h:348
Vector(size_t wSize=0)
Definition Vector.h:322
Vector(Vector< T > &other)
Definition Vector.h:325