![]() |
GemaCoreLib
The GeMA Core library
|
Basic class used to store sets of values, bound to a common definition, on behalf of another object (a mesh most likely) that contains a known maximum size of values (nodes or cells, for example). More...
#include <gmValueSet.h>
Public Types | |
enum | SaveStateMode { VS_NOINIT_VALUES, VS_INIT_VALUES, VS_COPY_VALUES } |
Initialization mode for calls to saveState() More... | |
Signals | |
void | setDataChanged (const GmValueSet *vs) |
Signal emitted whenever a state was added to the set by saveState in a rolling history scenario or when replaceValueSetData() was called. | |
Public Member Functions | |
GmValueSet (GmValueInfo *info, GmSimulationData *simData, GmMesh *mesh) | |
Constructor. More... | |
virtual | ~GmValueSet () |
Destructor. | |
bool | init (int numValues, bool releaseInfoOnError=false) |
Initializes the ValueSet, beeing responsible for allocating memory and initializing data. More... | |
GmValueInfo * | info () const |
Returns the metadata associated with this value set. | |
int | numValues () const |
Returns the number of values stored in this value set. | |
bool | addValues (int numAddedValues) |
Adds the given number of values to the sets, initializing them to the default value. Returns false on errors. On errors previous values are kept. Keep in mind that either all sets are resized or none are. | |
void | restoreSize (int oldNumValues) |
Restores the size of the set to the previous size before addValues. | |
virtual void | removeValues (int index, int numValues) |
Removes numValues from the set, starting from (and including) index. | |
virtual void | clear () |
Clears the value sets, restoring its size to 0. More... | |
GmValueAccessor * | accessor (const Unit &desiredUnit, const GmLogCategory &logger, const GmMesh *mesh=NULL) |
Returns a locked accessor to the current value set using the desired parameters. Equivalent to calling accessor(0, true, desiredUnit, logger, mesh). | |
GmValueAccessor * | accessor (int snum, bool locked, const Unit &desiredUnit, const GmLogCategory &logger, const GmMesh *mesh=NULL) |
Returns a generic accessor that can cope with any kind of data, scalars, vectors or matrices. More... | |
virtual bool | saveState (SaveStateMode mode, const GmLogCategory &logger) |
Saves the state for the current value set. Creates a new current value set or updates it if in a "rolling history mode". More... | |
int | numSets () const |
Returns the number of saved states for this set. | |
GmValueSetData * | valueSetData (int sindex, bool locked) const |
Returns the value set data object associated with the given index. If locked == true, sindex should be the locked state number. Otherwise it should be the ValueSetData index inside the ValueSet. | |
void | replaceValueSetData (GmValueSetData *oldData, GmValueSetData *newData) |
Replaces the old valueSetData by the new one, emiting the setDataChanged() signal. | |
GmValueSetEvalContext * | evalContext () const |
Returns the function evalution context associated with this value set (will be NULL if the data set does not supports functions) | |
QString | stateTag (int snum) const |
Returns the tag associated to the given state. | |
double | stateTime (int snum) const |
Returns the time associated to the given state. | |
void | setStateTag (int snum, QString tag) |
Updates the tag associated to the given state. | |
void | setStateTime (int snum, double time) |
Updates the time associated to the given state. | |
virtual size_t | printMemoryStatistics (const GmLogCategory &logger, GmLogLevel level) const |
Prints memory usage for this value set to the given logger. Returns the used memory as reported by usedMemory() | |
virtual size_t | usedMemory () const |
Returns an estimative of the memory used by the data set in bytes. More... | |
![]() | |
virtual const QMetaObject * | metaObject () const const |
virtual void * | qt_metacast (const char *) |
virtual int | qt_metacall (QMetaObject::Call, int, void **) |
QObject (QObject *parent) | |
virtual bool | event (QEvent *e) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
QString | objectName () const const |
void | setObjectName (const QString &name) |
bool | isWidgetType () const const |
bool | isWindowType () const const |
bool | signalsBlocked () const const |
bool | blockSignals (bool block) |
QThread * | thread () const const |
void | moveToThread (QThread *targetThread) |
int | startTimer (int interval, Qt::TimerType timerType) |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType) |
void | killTimer (int id) |
T | findChild (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegExp ®Exp, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
const QObjectList & | children () const const |
void | setParent (QObject *parent) |
void | installEventFilter (QObject *filterObj) |
void | removeEventFilter (QObject *obj) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const |
bool | disconnect (const char *signal, const QObject *receiver, const char *method) const const |
bool | disconnect (const QObject *receiver, const char *method) const const |
void | dumpObjectTree () |
void | dumpObjectInfo () |
void | dumpObjectTree () const const |
void | dumpObjectInfo () const const |
bool | setProperty (const char *name, const QVariant &value) |
QVariant | property (const char *name) const const |
QList< QByteArray > | dynamicPropertyNames () const const |
void | destroyed (QObject *obj) |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () const const |
bool | inherits (const char *className) const const |
void | deleteLater () |
Protected Member Functions | |
GmValueSetData * | vd (int snum) const |
Returns the value set data object associated with the given state number. | |
int | t (int index) const |
Get the index in _vsDataList corresponding to the given state index. | |
GmValueSetData * | createDataObject () |
Creates a new GmValueSetData object for storing data described by the associated info object. | |
![]() | |
QObject * | sender () const const |
int | senderSignalIndex () const const |
int | receivers (const char *signal) const const |
bool | isSignalConnected (const QMetaMethod &signal) const const |
virtual void | timerEvent (QTimerEvent *event) |
virtual void | childEvent (QChildEvent *event) |
virtual void | customEvent (QEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
Protected Attributes | |
GmValueInfo * | _info |
Metadata defining the value set. | |
GmValueSetEvalContext * | _evalContext |
The context used by accessors to evaluate function values (can be NULL) | |
QList< GmValueSetData * > | _vsDataList |
The list of value sets. | |
QStringList | _tagList |
A list of tag names associated to each saved state. | |
QList< double > | _timeList |
A list of times associated to each saved state. | |
int | _currentSet |
The index of the current set for rolling histories. | |
Additional Inherited Members | |
![]() | |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
QString | trUtf8 (const char *sourceText, const char *disambiguation, int n) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, Functor functor) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type) |
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
bool | disconnect (const QMetaObject::Connection &connection) |
bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
![]() | |
objectName | |
Basic class used to store sets of values, bound to a common definition, on behalf of another object (a mesh most likely) that contains a known maximum size of values (nodes or cells, for example).
The set data is always stored in an object of type GmValueSetData. Several subclasses of the GmValueSetData abstract interface exist for efficiently handling different data types, scalar or multidimensional values, presence of functions, sparse data, etc. The concrete type used for storage is defined by the information given by the GmValueInfo object passed to the GmValueSet constructor.
Each value set can hold a list of value set data objects to store history data. This indirection also enables the possibility of having a set that changes the value set data used for data storage, without invalidating accessors. For that, tracked value accessors can be used. Those accessors are notified by signals whenever the value set data holding the information was changed by the data set. This same mechanism is used for implementing locked accessors when dealing with rolling histories.
Several of the class functions receive as parameter a state number. This is the number of the saved state in the multi value set. State numbers range from 0 to numSets()-1. The index 0 will ALWAYS reference the newest state while an index equal to numSets() - 1 will reference the oldest sate in the set. In that way, when a new state is saved, a state with index 0 will become the state 1 and the new state will be the 0 one.
To access the data stored in a value set, the user should make use of accessors, which are created by the set and provide read and write access to the data. There are several specialized kinds of accessors to efficiently handle data sets stored with different types of value GmValueSetData objects, with or without function support, with or without unit conversion. Keep in mind that the accessor interface always gets and sets values as doubles, even if they are stored in a more compact memory format.
In order for an accessor to be able to call functions, the necessary information (simulation data + mesh) should have been provided in the value set constructor.
When deciding if a sparse representation is recommended, one should take into account the expected percentage of filled values. From that information the approximate sizes below can be used to indicate the best option. On this formulas, "n" is the number of nodes / cells in the set, "p" the percentage of filled values (between 0 and 1) and "f" is the percentage of function references (between 0 and 1).
Initialization mode for calls to saveState()
GmValueSet::GmValueSet | ( | GmValueInfo * | info, |
GmSimulationData * | simData, | ||
GmMesh * | mesh | ||
) |
Constructor.
This constructor receives as parameters the metadata describing the values which will be later inserted in the set and also a reference for the simulationData and mesh. This later two parameters are needed only if the set can store function references (as indicated by the info metadata). In that case, mesh can be set to NULL if the value set is not directly bound to a mesh (bound to a property set, for example).
If the info metadata dictates that there is no need of history tracking, a single ValueSetData object will be instanced. For rolling history type, all needed states are instanced and for multiple states the first one is instanced.
A call to the constructor should be succeeded by a call to init() wich will be responsible for allocating memory.
This function uses the information stored in the metadata given by info to determine how to allocate memory. Any changes to that information after the construction can be harmfull.
IMPORTANT: The Value Set takes ownership of the info object and will release its memory upon destruction.
GmValueAccessor * GmValueSet::accessor | ( | int | snum, |
bool | locked, | ||
const Unit & | desiredUnit, | ||
const GmLogCategory & | logger, | ||
const GmMesh * | mesh = NULL |
||
) |
Returns a generic accessor that can cope with any kind of data, scalars, vectors or matrices.
The 'snum' parameter defines the state number that will be queried (0 is the most recent state - see comments on the class description). If the value set is not associated with a history, just pass 0.
The 'locked' parameter controls what happends when a new state is created by a call to saveState(). When locked is false, the old accessor will keep pointing to the same data it pointed before. When locked is true, it will change the value set data it points to, so that it always points to the current value set with the same state number (for example, if snum == 0 the accessor will always point to the most recent state and if snum == 1 the accessor will always point to the previous state).
If desiredUnit is a known unit, different from the basic ValueSet unit, the accessor will automatically convert it to the desired unit. If no conversion is possible, the function returns NULL. To avoid conversions, just pass Unit() as the desiredUnit.
The mesh parameter is only needed if the value set supports function references and in the construction mesh was set to NULL
IMPORTANT: The returned accessor should be deallocated by the caller.
|
virtual |
Clears the value sets, restoring its size to 0.
Important: This function clears data from every state value set but does NOT removes states
bool GmValueSet::init | ( | int | numValues, |
bool | releaseInfoOnError = false |
||
) |
Initializes the ValueSet, beeing responsible for allocating memory and initializing data.
Returns false if it was not possible to allocate memory. If releaseInfoOnError is true and there was an error allocating memory, the ValueSet releases its ownership claim over the information object, that will not be released by the value set anymore. It also sets its internal info pointer to NULL.
|
virtual |
Saves the state for the current value set. Creates a new current value set or updates it if in a "rolling history mode".
The new current state will be initialized accordingly to the mode defined by the given mode paramater. Returns true on success, false on error.
|
virtual |
Returns an estimative of the memory used by the data set in bytes.
It returns in general the variable memory that depends on the number of set entries but does not include constant overheads used by the class for control