GemaCoreLib
The GeMA Core library
Public Types | Signals | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
GmValueSet Class Reference

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>

Inheritance diagram for GmValueSet:
Inheritance graph
[legend]
Collaboration diagram for GmValueSet:
Collaboration graph
[legend]

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...
 
GmValueInfoinfo () 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...
 
GmValueAccessoraccessor (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).
 
GmValueAccessoraccessor (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.
 
GmValueSetDatavalueSetData (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.
 
GmValueSetEvalContextevalContext () 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...
 
- Public Member Functions inherited from QObject
virtual const QMetaObjectmetaObject () 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)
 
QThreadthread () 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)
 
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 &regExp, 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< QByteArraydynamicPropertyNames () const const
 
void destroyed (QObject *obj)
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
bool inherits (const char *className) const const
 
void deleteLater ()
 

Protected Member Functions

GmValueSetDatavd (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.
 
GmValueSetDatacreateDataObject ()
 Creates a new GmValueSetData object for storing data described by the associated info object.
 
- Protected Member Functions inherited from QObject
QObjectsender () 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

- Static Public Member Functions inherited from QObject
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)
 
- Properties inherited from QObject
 objectName
 

Detailed Description

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).

Type | Func? | Dim | Aloc | Aloc | Structure | Used memory (bytes)
| | | Mode | Strategy | |
----------------------------------------|----------------|------------------------------------------
T Y/N d Auto - | - | Constant until a value is written. Reverts
| | to the equivalent Full case after a set.
----------------------------------------|----------------|-----------------------------------------
T N d Full - | vector<T> | n * d * sizeof(T)
----------------------------------------|----------------|-----------------------------------------
T Y d Full Auto | vector<NanBox> | n * d * sizeof(double)

Member Enumeration Documentation

◆ SaveStateMode

Initialization mode for calls to saveState()

Enumerator
VS_NOINIT_VALUES 

Values for the new state will be uninitialized.

VS_INIT_VALUES 

Values for the new state will be set to the ValueSet default.

VS_COPY_VALUES 

Values for the new state will copy the old current state values.

Constructor & Destructor Documentation

◆ GmValueSet()

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.

Member Function Documentation

◆ accessor()

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.

◆ clear()

void GmValueSet::clear ( )
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

◆ init()

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.

◆ saveState()

bool GmValueSet::saveState ( SaveStateMode  mode,
const GmLogCategory logger 
)
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.

◆ usedMemory()

size_t GmValueSet::usedMemory ( ) const
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


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