23#ifndef _GEMA_DUAL_VECTOR_H_
24#define _GEMA_DUAL_VECTOR_H_
44 static_assert(!QTypeInfo<T>::isComplex,
"Not a POD type");
70 const T*
iptr(
size_t index)
const
72 assert(index <
size());
82 assert(index <
size());
100 using iterator_category = std::random_access_iterator_tag;
101 using value_type = T;
102 using difference_type = std::ptrdiff_t;
104 using reference = T&;
109 reference operator*()
const {
return (*
_vec)[
_index]; }
110 pointer operator->()
const {
return &(*_vec)[
_index]; }
111 reference operator[](difference_type n)
const {
return (*
_vec)[
_index + n]; }
117 iterator& operator+=(difference_type n) {
_index += n;
return *
this; }
118 iterator& operator-=(difference_type n) {
_index -= n;
return *
this; }
121 difference_type operator-(
const iterator& other)
const { assert(
_vec == other.
_vec);
return (difference_type)
_index - (difference_type)other.
_index; }
136 iterator end() {
return iterator(
this,
size()); }
146 bool addValues(
size_t numAddedValues,
bool tight =
false)
149 if(numAddedValues == 0)
152 if(
size() > std::numeric_limits<size_t>::max() - numAddedValues)
154 gmWarnMsg(
GmPanicLogger(),
QObject::tr(
"Dual vector: Error adding %1 values. Vector size would surpass the maximum possible capacity.").arg(numAddedValues));
169 .arg(
_fixedSize + numAddedValues).arg(
sizeof(T)));
171 gmWarnMsg(
GmPanicLogger(),
QObject::tr(
"Dual vector: Error resizing a vector with %1 entries of %2 bytes to a vector with %3 entries.")
193 assert(oldNumValues <=
size());
221 assert(index >= 0 && index <
size());
286 bool addValues(
size_t numAddedValues,
bool tight =
false)
290 if(
_size > std::numeric_limits<size_t>::max() - numAddedValues)
292 gmWarnMsg(
GmPanicLogger(),
QObject::tr(
"Dual vector: Error adding %1 values. Vector size would surpass the maximum possible capacity.").arg(numAddedValues));
296 size_t nadd = numAddedValues;
308 _size += numAddedValues;
319 _size = oldNumValues;
336 assert(index + numValues <=
_size);
346 size_t fr = index + numValues;
347 size_t nr =
_size - fr;
350 for(
size_t i = 0; i < nr; i++)
An iterator class to enable usage of the vector with standard algorithms such as std::sort.
Definition gmDualVector.h:98
size_t _index
Our internal index inside the vector.
Definition gmDualVector.h:132
GmDualVector< T > * _vec
The vector.
Definition gmDualVector.h:131
A vector tailored for storing mesh related data for the common scenario where elements are added to t...
Definition gmDualVector.h:42
int numDumpBuffers() const
Returns the number of internal buffers used by this implementation.
Definition gmDualVector.h:240
bool addValues(size_t numAddedValues, bool tight=false)
Adds numAddedValues to the set, without any initialization. Returns true on success,...
Definition gmDualVector.h:146
char * dumpBuffer(int i) const
Returns the i'th internal buffer, i from 0 to numDumpBuffers()-1.
Definition gmDualVector.h:243
void zero(size_t index=0)
Clears the vector area by setting to zero all entries starting at the given index.
Definition gmDualVector.h:215
size_t usedMemory() const
Returns an estimative of the memory used by the data set in bytes.
Definition gmDualVector.h:237
T & operator[](size_t index)
Non-const overload for the standard indexing operator.
Definition gmDualVector.h:93
T DataType
The stored data type.
Definition gmDualVector.h:47
const T & operator[](size_t index) const
Standard indexing operator.
Definition gmDualVector.h:90
GmDualVector(size_t nvalues)
The constructor initializing the "fixed" part size. The vector contents is NOT initialized.
Definition gmDualVector.h:53
void restoreSize(size_t oldNumValues)
Restores the size of the set to the previous size before the last call to addValues()....
Definition gmDualVector.h:190
size_t _fixedSize
The number of entries in _fixedData.
Definition gmDualVector.h:250
size_t dumpBufferSize(int i) const
Returns the size in bytes of the i'th internal buffer returned by dumpBuffer(i)
Definition gmDualVector.h:246
T * iptr(size_t index)
Non-const overload for iptr()
Definition gmDualVector.h:80
bool isDual() const
Returns true, since this IS a Dual vector.
Definition gmDualVector.h:59
GmPODVector< T > _growData
The variable part.
Definition gmDualVector.h:252
void clear()
Clears all stored data returning the object to a default constructed state.
Definition gmDualVector.h:205
T * _fixedData
The fixed part of the dual vector with _fixedSize entries.
Definition gmDualVector.h:249
~GmDualVector()
Destructor.
Definition gmDualVector.h:56
const T * iptr(size_t index) const
Returns a pointer to the index data inside the vector. By the very nature of this class,...
Definition gmDualVector.h:70
GmDualVector()
Default constructor.
Definition gmDualVector.h:50
size_t size() const
Returns the vector size.
Definition gmDualVector.h:62
A class very simmilar to GmDualVector with support for removing values. Removing values should be use...
Definition gmDualVector.h:264
void removeValues(size_t index, size_t numValues)
Removes numValues from the set, starting from (and including) index.
Definition gmDualVector.h:333
size_t _size
The total number of entries in the vector. Can be less than _fixedSize if entries where removed from ...
Definition gmDualVector.h:380
size_t dumpBufferSize(int i) const
Returns the size in bytes of the i'th internal buffer returned by dumpBuffer(i)
Definition gmDualVector.h:371
~GmDualVectorR()
Destructor.
Definition gmDualVector.h:273
bool addValues(size_t numAddedValues, bool tight=false)
Adds numAddedValues to the set, without any initialization. Returns true on success,...
Definition gmDualVector.h:286
GmDualVectorR()
Default constructor.
Definition gmDualVector.h:267
GmDualVectorR(size_t nvalues)
The constructor initializing the "fixed" part size. The vector contents is NOT initialized.
Definition gmDualVector.h:270
size_t size() const
Returns the vector size.
Definition gmDualVector.h:276
void restoreSize(size_t oldNumValues)
Restores the size of the set to the previous size before the last call to addValues()....
Definition gmDualVector.h:315
void clear()
Clears all stored data returning the object to a default constructed state.
Definition gmDualVector.h:363
A simple vector for Plain Old Data (POD) types with the control size variable type parameterized to a...
Definition gmPODVector.h:88
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
#define S_TRACE()
Macro for run time stack tracking at release build.
Definition gmTrace.h:44
QString tr(const char *sourceText, const char *disambiguation, int n)