SourceForge.net Logo
PythonQt
Public Member Functions | List of all members
PythonQtValueStorageWithCleanup< T, chunkEntries > Class Template Reference

a helper class that stores basic C++ value types in chunks and clears the unused values on setPos() usage. More...

#include <PythonQtMisc.h>

Inheritance diagram for PythonQtValueStorageWithCleanup< T, chunkEntries >:
PythonQtValueStorage< T, chunkEntries >

Public Member Functions

void setPos (const PythonQtValueStoragePosition &pos)
 
- Public Member Functions inherited from PythonQtValueStorage< T, chunkEntries >
 PythonQtValueStorage ()
 
void clear ()
 clear all memory More...
 
void getPos (PythonQtValueStoragePosition &pos)
 get the current position to be restored with setPos More...
 
void setPos (const PythonQtValueStoragePosition &pos)
 set the current position (without freeing memory, thus caching old entries for reuse) More...
 
T * nextValuePtr ()
 add one default constructed value and return the pointer to it More...
 

Additional Inherited Members

- Protected Attributes inherited from PythonQtValueStorage< T, chunkEntries >
QList< T * > _chunks
 
int _chunkIdx
 
int _chunkOffset
 
T * _currentChunk
 

Detailed Description

template<typename T, int chunkEntries>
class PythonQtValueStorageWithCleanup< T, chunkEntries >

a helper class that stores basic C++ value types in chunks and clears the unused values on setPos() usage.

Definition at line 135 of file PythonQtMisc.h.

Member Function Documentation

template<typename T, int chunkEntries>
void PythonQtValueStorageWithCleanup< T, chunkEntries >::setPos ( const PythonQtValueStoragePosition pos)
inline

Definition at line 138 of file PythonQtMisc.h.

138  {
139  if (_chunkIdx > pos.chunkIdx) {
140  T* firstChunk = _chunks.at(pos.chunkIdx);
141  // clear region in first chunk
142  for (int i = pos.chunkOffset; i < chunkEntries; i++) {
143  firstChunk[i] = T();
144  }
145  for (int chunk = pos.chunkIdx + 1; chunk < _chunkIdx; chunk++) {
146  // clear the full chunks between the first and last chunk
147  T* fullChunk = _chunks.at(chunk);
148  for (int i = 0; i < chunkEntries; i++) {
149  fullChunk[i] = T();
150  }
151  }
152  // clear region in last chunk
153  T* lastChunk = _chunks.at(_chunkIdx);
154  for (int i = 0; i < _chunkOffset; i++) {
155  lastChunk[i] = T();
156  }
157  } else if (_chunkIdx == pos.chunkIdx) {
158  // clear the region in the last chunk only
159  T* lastChunk = _chunks.at(_chunkIdx);
160  for (int i = pos.chunkOffset; i<_chunkOffset; i++) {
161  lastChunk[i] = T();
162  }
163  }
164 
166  }
QList< T * > _chunks
Definition: PythonQtMisc.h:123
void setPos(const PythonQtValueStoragePosition &pos)
set the current position (without freeing memory, thus caching old entries for reuse) ...
Definition: PythonQtMisc.h:99

The documentation for this class was generated from the following file: