GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmValueSet.h
Go to the documentation of this file.
1/************************************************************************
2**
3** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4** All rights reserved.
5**
6** This file is part of the "GeMA" software. It's use should respect
7** the terms in the license agreement that can be found together
8** with this source code.
9** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11** A PARTICULAR PURPOSE.
12**
13************************************************************************/
14
23#ifndef _GEMA_VALUE_SET_H_
24#define _GEMA_VALUE_SET_H_
25
26#include "gmValueSetData.h"
27
28#include <QVarLengthArray>
29#include <assert.h>
30
31#include <QObject>
32
33class GmValueAccessor;
35class GmMesh;
36class GmLogCategory;
38class GmValueSetData;
39class GmPackedBuffer;
40class Unit;
41class GmTaskManager;
42
43
44// Enable the define below to force validation of internal structures after value set initialization or growth
45// #define ENABLE_VALUESET_TESTS
46
47
54{
55 Q_OBJECT
56public:
57
65
66 GmValueSet(GmValueInfo* info, GmPackedBuffer* pack, GmSimulationData* simData, GmMesh* mesh);
67 virtual ~GmValueSet();
68
69 virtual bool init(int numValues, bool releaseInfoOnError = false);
70
72 GmValueInfo* info() const { return _info; }
73
77 void releaseInfo() { _info = NULL; }
78
80 GmPackedBuffer* pack() const { return _pack; }
81
82 void packLayoutUpdated();
83
85 int numValues() const { assert(!_vsDataList.isEmpty()); return _vsDataList.first()->numValues(); }
86
87 bool addValues(int numAddedValues);
88 void restoreSize(int oldNumValues);
89
90 virtual void removeValues(int index, int numValues);
91
92 virtual void clear();
93
97 GmValueAccessor* accessor(const Unit& desiredUnit, const GmLogCategory& logger, const GmMesh* mesh = NULL)
98 {
99 return accessor(0, true, desiredUnit, logger, mesh);
100 }
101
102 GmValueAccessor* accessor(int snum, bool locked, const Unit& desiredUnit, const GmLogCategory& logger, const GmMesh* mesh = NULL);
103
104 virtual bool saveState(GmTaskManager* tm, SaveStateMode mode, const GmLogCategory& logger);
105
107 int numSets() const { return _vsDataList.size(); }
108
115 GmValueSetData* valueSetData(int sindex, bool locked) const { return _vsDataList.at(locked ? t(sindex) : sindex); }
116
117 void replaceValueSetData(GmValueSetData* oldData, GmValueSetData* newData);
118
122 GmValueSetEvalContext* evalContext() const { return _evalContext; }
123
125 QString stateTag(int snum) const { return _tagList.at(t(snum)); }
126
128 double stateTime(int snum) const { return _timeList.at(t(snum)); }
129
131 void setStateTag(int snum, QString tag) { _tagList[t(snum)] = tag; }
132
134 void setStateTime(int snum, double time) { _timeList[t(snum)] = time; }
135
136#if defined ENABLE_TESTS || defined ENABLE_VALUESET_TESTS
137 virtual void validateInternalStructure();
138#endif
139
140 virtual size_t printMemoryStatistics(const GmLogCategory& logger, GmLogLevel level) const;
141 virtual size_t usedMemory() const;
142
143signals:
147 void setDataChanged(const GmValueSet* vs);
148
149protected:
151 GmValueSetData* vd(int snum) const { return _vsDataList.at(t(snum)); }
152
154 int t(int index) const
155 {
156 int n = _vsDataList.size();
157 assert(index >= 0 && index < n);
158 return (_info->history() > 0) ? (_currentSet + index) % n : n - index - 1;
159 }
160
161 GmValueSetData* createDataObject(int state, bool dual);
162
165
171
172private:
174};
175
176#endif
177
178
Class representing a category with multiple logging levels.
Definition gmLog.h:58
Base interface class for Mesh type plugins.
Definition gmMesh.h:48
The basic interface for a shared buffer storing interleaved data for a group of value sets.
Definition gmPackedBuffer.h:119
Auxiliar class used to store the complete set of simulation data.
Definition gmSimulationData.h:55
Task manager used for handling parallel executions.
Definition gmTaskManager.h:84
Interface class for accessing and setting values from an "indexable" collection of values.
Definition gmValueAccessor.h:60
Auxiliar class used to store the definition of a value. It can be used to store informations about st...
Definition gmValueInfo.h:132
The generic interface implemented by every GmValueSetData object. Its purpose is to provide a base cl...
Definition gmValueSetData.h:58
Auxiliar class used to store the needed information to translate an user function id / user function ...
Definition gmValueSetEvalContext.h:46
Basic class used to store sets of values, bound to a common definition, on behalf of another object (...
Definition gmValueSet.h:54
GmValueSetEvalContext * _evalContext
The context used by accessors to evaluate function values (can be NULL)
Definition gmValueSet.h:164
void setDataChanged(const GmValueSet *vs)
Signal emitted whenever a state was added to the set by saveState in a rolling history scenario or wh...
QList< GmValueSetData * > _vsDataList
The list of value sets. Stores either GmValueSetStoredData or GmValueSetPackedData pointers depending...
Definition gmValueSet.h:167
SaveStateMode
Initialization mode for calls to saveState()
Definition gmValueSet.h:60
@ VS_INIT_VALUES
Values for the new state will be set to the ValueSet default.
Definition gmValueSet.h:62
@ VS_COPY_VALUES
Values for the new state will copy the old current state values.
Definition gmValueSet.h:63
@ VS_NOINIT_VALUES
Values for the new state will be uninitialized.
Definition gmValueSet.h:61
int t(int index) const
Get the index in _vsDataList corresponding to the given state index.
Definition gmValueSet.h:154
int _currentSet
The index of the current set for rolling histories.
Definition gmValueSet.h:170
void setStateTime(int snum, double time)
Updates the time associated to the given state.
Definition gmValueSet.h:134
void releaseInfo()
Releases the value set hold on the info object by setting it to NULL. Use very carefully for error tr...
Definition gmValueSet.h:77
GmValueSetData * valueSetData(int sindex, bool locked) const
Returns the value set data object associated with the given index. If locked == true,...
Definition gmValueSet.h:115
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 callin...
Definition gmValueSet.h:97
QList< double > _timeList
A list of times associated to each saved state.
Definition gmValueSet.h:169
GmPackedBuffer * _pack
The packed buffer containing the data vector if the value set belongs to a pack. NULL otherwise.
Definition gmValueSet.h:166
GmValueSetEvalContext * evalContext() const
Returns the function evalution context associated with this value set (will be NULL if the data set d...
Definition gmValueSet.h:122
double stateTime(int snum) const
Returns the time associated to the given state.
Definition gmValueSet.h:128
QStringList _tagList
A list of tag names associated to each saved state
Definition gmValueSet.h:168
GmValueInfo * info() const
Returns the metadata associated with this value set.
Definition gmValueSet.h:72
QString stateTag(int snum) const
Returns the tag associated to the given state.
Definition gmValueSet.h:125
GmValueSetData * vd(int snum) const
Returns the value set data object associated with the given state number.
Definition gmValueSet.h:151
int numSets() const
Returns the number of saved states for this set.
Definition gmValueSet.h:107
GmPackedBuffer * pack() const
Returns the associated packed buffer if this value set is tied to one. Returns NULL otherwise.
Definition gmValueSet.h:80
int numValues() const
Returns the number of values stored in this value set.
Definition gmValueSet.h:85
void setStateTag(int snum, QString tag)
Updates the tag associated to the given state.
Definition gmValueSet.h:131
GmValueInfo * _info
Metadata defining the value set.
Definition gmValueSet.h:163
#define GMC_API_EXPORT
Macro for controlling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_L...
Definition gmCoreConfig.h:35
GmLogLevel
Available log levels list.
Definition gmLog.h:36
Declaration of the GmValueSetData interface.
Q_DISABLE_COPY(Class)
const QChar at(int position) const const