GemaCoreLib
The GeMA Core library
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | List of all members
GmDefValueValueSetData Class Reference

A GmValueSetData implementation that stores no data and returns the default value, whenever queried, until a different value is written to the set. At that moment, instructs the Value set that owns this data set to exchange it by a base container that will contain the data from that moment on. More...

#include <gmValueSetData.h>

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

Public Member Functions

 GmDefValueValueSetData (GmValueSetData *baseContainer, GmValueSet *vs)
 Constructor. Gets as parameters the base container that will receive data if ever a set operation is done on this set and the Value set that owns us. More...
 
virtual ~GmDefValueValueSetData ()
 Destructor.
 
virtual GmValueInfoinfo () const
 Returns a pointer to the associated value info object.
 
virtual bool init (int numValues)
 Initilizes the value set allocating space.
 
virtual int numValues () const
 Returns the number of values stored in this value set.
 
virtual bool addValues (int numAddedValues)
 Adds numAddedValues to the set, initializing them to the default value. Returns true on success, false on error. On errors previous values are kept.
 
virtual 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 set, restoring its size to 0.
 
virtual GmTrackedValueAccessoraccessor (const GmLogCategory &logger, UnitConverter *conv, QString desiredUnit, bool atomic=false)
 Returns an accessor for the stored data. The atomic flag can be used by the caller to request that a protected version of the accessor is needed for multi-threaded cases.
 
virtual size_t usedMemory () const
 Returns an estimative of the memory used by the data set in bytes. More...
 
- Public Member Functions inherited from GmValueSetData
virtual ~GmValueSetData ()
 Virtual destructor.
 

Static Public Member Functions

static void cleanupDetachedData ()
 Deletes objetcs stored for delayed destruction. Must be called at the main thread, after all workers are done.
 

Protected Member Functions

virtual bool isDefValue (int index) const
 Returns true if the indexed value is the default value for the set.
 
virtual StoredValueType storedValueType (int index) const
 Returns the type (number, function definition/evaluator) of the stored value for the given index.
 
virtual const double * value (int index) const
 Returns the numeric value stored at the given index (converted to a double if needed) Must be called only for indices storing numeric data. Does NOT evaluate functions. More...
 
virtual bool setValue (int index, const double *values)
 Updates the value stored at the given index with a numeric value (converted to the correct type if needed) More...
 
virtual void * functionValue (int index) const
 Returns a pointer to the stored function object. Return will be either a GmUserFunction* or a GmUserFunctionEvaluator* depending on the type returned by storedValueType(index). Must be called only for indices storing data of those types.
 
virtual bool setFunctionValue (int index, StoredValueType type, void *functionObj)
 Overload of setValue() storing a user function definition. More...
 
- Protected Member Functions inherited from GmValueSetData
virtual char * dumpBuffer ()
 Returns the internal buffer that can be used for a direct data dumping/loading by the GmStateDump classes. Returns NULL if there is no such buffer and that is NOT supported.
 
virtual int dumpBufferSize () const
 Returns the size in bytes of the internal buffer returned by dumpBuffer. Returns 0 if there is no such buffer and that is NOT supported.
 

Protected Attributes

int _numValues
 The number of entries in this data set.
 
GmValueSetData_bc
 The base container that we should initialize and revert to when a value is written to the data set.
 
GmValueSet_vs
 The value set that owns us.
 
StoredValueType _defType
 The type of the default value.
 
void * _defValue
 The default value. Will be a double* or a pointer to one of the function object types depending on _defType.
 
QMutex _setMutex
 The mutex protecting setXxxx() operations.
 
bool _detached
 Flag marking that this object should be no longer in use.
 

Static Protected Attributes

static QVector< GmValueSetData * > _detachedList
 A global list with the set of detached GmDefValueValueSetData marked for delayed deletion by cleanupDetachedData(). More...
 

Private Member Functions

 Q_DISABLE_COPY (GmDefValueValueSetData)
 

Additional Inherited Members

- Public Types inherited from GmValueSetData
enum  StoredValueType { GM_SVT_NUMBER, GM_SVT_FUNCTION, GM_SVT_FUNCTION_EVAL }
 Enumeration to detect the type of stored data for an index. More...
 

Detailed Description

A GmValueSetData implementation that stores no data and returns the default value, whenever queried, until a different value is written to the set. At that moment, instructs the Value set that owns this data set to exchange it by a base container that will contain the data from that moment on.

When the first set occurs, the value set is notified of the change so that it can update its data list to point to the base value set container and emit an GmValueSet::setDataChanged() signal so that all affected accessors are updated. In this scenario, the current value set data is then deleted (by a delete this) and causes no further overhead.

This behaviour works well in tight connection with the GmValueSetDataAccessor familly of implementations. Be carefull when changing either of them.

Constructor & Destructor Documentation

◆ GmDefValueValueSetData()

GmDefValueValueSetData::GmDefValueValueSetData ( GmValueSetData baseContainer,
GmValueSet vs 
)

Constructor. Gets as parameters the base container that will receive data if ever a set operation is done on this set and the Value set that owns us.

This object takes ownership of the base container until a set operation is done. If no set is ever made, the base container will be deleted by this object. Otherwise it will transfer its ownership to the value set upon the set.

Member Function Documentation

◆ setFunctionValue()

bool GmDefValueValueSetData::setFunctionValue ( int  index,
StoredValueType  type,
void *  functionObj 
)
protectedvirtual

Overload of setValue() storing a user function definition.

Receives as parameters the value index, its type (function definition/evaluator) and a pointer to the stored function object (should be either a GmUserFunction or a GmUserFunctionEvaluator object).

Returns false if the data could not be set.

Implements GmValueSetData.

◆ setValue()

bool GmDefValueValueSetData::setValue ( int  index,
const double *  values 
)
protectedvirtual

Updates the value stored at the given index with a numeric value (converted to the correct type if needed)

Returns false if the data could not be set.

Implements GmValueSetData.

◆ usedMemory()

virtual size_t GmDefValueValueSetData::usedMemory ( ) const
inlinevirtual

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

Implements GmValueSetData.

◆ value()

virtual const double* GmDefValueValueSetData::value ( int  index) const
inlineprotectedvirtual

Returns the numeric value stored at the given index (converted to a double if needed) Must be called only for indices storing numeric data. Does NOT evaluate functions.

VERY IMPORTANT: Since data conversion might be necessary (when the stored data is not in double format), the contents of the pointer returned by value is VALID only until the next call. This behaviour is COMPATIBLE with the general accessor behaviour.

Implements GmValueSetData.

Member Data Documentation

◆ _detachedList

QVector< GmValueSetData * > GmDefValueValueSetData::_detachedList
staticprotected

A global list with the set of detached GmDefValueValueSetData marked for delayed deletion by cleanupDetachedData().

Should be accessed either on the main thread, after all worker threads are done, or protected by _setMutex


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