23#ifndef _GEMA_SINGLE_VECTOR_H_
24#define _GEMA_SINGLE_VECTOR_H_
39 static_assert(!QTypeInfo<T>::isComplex,
"Not a POD type");
51 bool isDual()
const {
return false; }
54 size_t size()
const {
return _v.size(); }
57 const T*
iptr(
size_t index)
const { assert(index <
_v.size());
return _v.data() + index; }
60 T*
iptr(
size_t index) { assert(index <
_v.size());
return _v.data() + index; }
72 iterator begin() {
return _v.data(); }
73 iterator end() {
return _v.data() +
_v.size(); }
84 bool addValues(
size_t numAddedValues,
bool tight =
false)
86 if(
_v.size() > std::numeric_limits<size_t>::max() - numAddedValues)
88 gmWarnMsg(
GmPanicLogger(),
QObject::tr(
"Single vector: Error adding values. Vector size would surpass the maximum possible capacity."));
92 if(tight || !
_v.size())
95 return _v.resize(
_v.size() + numAddedValues);
103 assert(oldNumValues <=
_v.size());
104 _v.resize(oldNumValues);
108 void removeValues(
size_t index,
size_t numValues) {
_v.remove(index, numValues); }
114 void zero(
size_t index = 0) {
_v.zero(index); }
127 char*
dumpBuffer(
int i)
const { Q_UNUSED(i); assert(i == 0);
return (
char*)
_v.data(); }
130 size_t dumpBufferSize(
int i)
const { Q_UNUSED(i); assert(i == 0);
return _v.size() *
sizeof(T); }
A simple vector for Plain Old Data (POD) types with the control size variable type parameterized to a...
Definition gmPODVector.h:88
A class with the same API as GmDualVector storing a single vector. No query "if" overhead....
Definition gmSingleVector.h:37
void removeValues(size_t index, size_t numValues)
Removes numValues from the set, starting from (and including) index.
Definition gmSingleVector.h:108
GmPODVector< T > _v
The real vector.
Definition gmSingleVector.h:135
T DataType
The stored data type.
Definition gmSingleVector.h:42
void clear()
Clears all stored data returning the object to a default constructed state.
Definition gmSingleVector.h:111
int numDumpBuffers() const
Returns the number of internal buffers used by this implementation.
Definition gmSingleVector.h:124
GmSingleVector()
Default constructor.
Definition gmSingleVector.h:45
bool addValues(size_t numAddedValues, bool tight=false)
Adds numAddedValues to the set, without any initialization. Returns true on success,...
Definition gmSingleVector.h:84
void zero(size_t index=0)
Clears the vector area by setting to zero all entries starting at the given index.
Definition gmSingleVector.h:114
T * iptr(size_t index)
Non-const overload for iptr()
Definition gmSingleVector.h:60
size_t usedMemory() const
Returns an estimative of the memory used by the data set in bytes.
Definition gmSingleVector.h:121
const T & operator[](size_t index) const
Standard indexing operator.
Definition gmSingleVector.h:63
size_t size() const
Returns the vector size.
Definition gmSingleVector.h:54
const T * iptr(size_t index) const
Returns a pointer to the index data inside the vector.
Definition gmSingleVector.h:57
T & operator[](size_t index)
Non-const overload for the standard indexing operator.
Definition gmSingleVector.h:66
size_t dumpBufferSize(int i) const
Returns the size in bytes of the i'th internal buffer returned by dumpBuffer(i)
Definition gmSingleVector.h:130
char * dumpBuffer(int i) const
Returns the i'th internal buffer, i from 0 to numDumpBuffers()-1.
Definition gmSingleVector.h:127
GmSingleVector(size_t nvalues)
The constructor initializing the vector with the given size. The vector contents is NOT initialized.
Definition gmSingleVector.h:48
void restoreSize(size_t oldNumValues)
Restores the size of the set to the previous size before the last call to addValues()....
Definition gmSingleVector.h:101
bool isDual() const
Returns false, since this is NOT a Dual vector.
Definition gmSingleVector.h:51
const GmLogCategory & GmPanicLogger()
Returns the global "panic" logger, usually used to report memory allocation fails deep inside class s...
Definition gmLog.cpp:647
Implementation of the GmPODVector template class.
size_t GmPODVectorTightGrow(size_t s, size_t a)
Vector growing to exactly the needed size.
Definition gmPODVector.h:72
QString tr(const char *sourceText, const char *disambiguation, int n)