GemaCoreLib
The GeMA Core library
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 "gmCoreConfig.h"
27 #include "gmValueSetData.h"
28 #include "gmValueInfo.h"
29 
30 #include <QVarLengthArray>
31 #include <assert.h>
32 
33 #include <QObject>
34 
35 class GmValueAccessor;
36 class GmSimulationData;
37 class GmMesh;
38 class GmLogCategory;
40 class GmValueSetData;
41 class Unit;
42 
43 
44 // Enable the define bellow to force validation of internal structures after value set initialization or growth
45 // #define ENABLE_VALUESET_TESTS
46 
47 
54 {
55  Q_OBJECT
56 public:
57 
60  {
64  };
65 
66  GmValueSet(GmValueInfo* info, GmSimulationData* simData, GmMesh* mesh);
67  virtual ~GmValueSet();
68 
69  bool init(int numValues, bool releaseInfoOnError = false);
70 
72  GmValueInfo* info() const { return _info; }
73 
75  int numValues() const { assert(!_vsDataList.isEmpty()); return _vsDataList.first()->numValues(); }
76 
77  bool addValues(int numAddedValues);
78  void restoreSize(int oldNumValues);
79 
80  virtual void removeValues(int index, int numValues);
81 
82  virtual void clear();
83 
87  GmValueAccessor* accessor(const Unit& desiredUnit, const GmLogCategory& logger, const GmMesh* mesh = NULL)
88  {
89  return accessor(0, true, desiredUnit, logger, mesh);
90  }
91 
92  GmValueAccessor* accessor(int snum, bool locked, const Unit& desiredUnit, const GmLogCategory& logger, const GmMesh* mesh = NULL);
93 
94  virtual bool saveState(SaveStateMode mode, const GmLogCategory& logger);
95 
97  int numSets() const { return _vsDataList.size(); }
98 
103  GmValueSetData* valueSetData(int sindex, bool locked) const { return _vsDataList.at(locked ? t(sindex) : sindex); }
104 
105  void replaceValueSetData(GmValueSetData* oldData, GmValueSetData* newData);
106 
110  GmValueSetEvalContext* evalContext() const { return _evalContext; }
111 
113  QString stateTag(int snum) const { return _tagList.at(t(snum)); }
114 
116  double stateTime(int snum) const { return _timeList.at(t(snum)); }
117 
119  void setStateTag(int snum, QString tag) { _tagList[t(snum)] = tag; }
120 
122  void setStateTime(int snum, double time) { _timeList[t(snum)] = time; }
123 
124 #if defined ENABLE_TESTS || defined ENABLE_VALUESET_TESTS
125  virtual void validateInternalStructure();
126 #endif
127 
128  virtual size_t printMemoryStatistics(const GmLogCategory& logger, GmLogLevel level) const;
129  virtual size_t usedMemory() const;
130 
131 signals:
135  void setDataChanged(const GmValueSet* vs);
136 
137 protected:
139  GmValueSetData* vd(int snum) const { return _vsDataList.at(t(snum)); }
140 
142  int t(int index) const
143  {
144  int n = _vsDataList.size();
145  assert(index >= 0 && index < n);
146  return (_info->history() > 0) ? (_currentSet + index) % n : n - index - 1;
147  }
148 
149  GmValueSetData* createDataObject();
150 
153 
158 
159 private:
160  Q_DISABLE_COPY(GmValueSet)
161 };
162 
163 #endif
164 
165 
Auxiliar class used to store the definition of a value. It can be used to store informations about st...
Definition: gmValueInfo.h:126
QStringList _tagList
A list of tag names associated to each saved state.
Definition: gmValueSet.h:155
Declaration of the GmValueSetData family of classes.
GmValueSetData * vd(int snum) const
Returns the value set data object associated with the given state number.
Definition: gmValueSet.h:139
Values for the new state will copy the old current state values.
Definition: gmValueSet.h:63
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:87
Basic class used to store sets of values, bound to a common definition, on behalf of another object (...
Definition: gmValueSet.h:53
QList< double > _timeList
A list of times associated to each saved state.
Definition: gmValueSet.h:156
void setStateTag(int snum, QString tag)
Updates the tag associated to the given state.
Definition: gmValueSet.h:119
Declaration of usefull configuration definitions for the Core library.
Declaration of the GmValueInfo class.
GmValueInfo * info() const
Returns the metadata associated with this value set.
Definition: gmValueSet.h:72
Values for the new state will be uninitialized.
Definition: gmValueSet.h:61
GmValueSetEvalContext * evalContext() const
Returns the function evalution context associated with this value set (will be NULL if the data set d...
Definition: gmValueSet.h:110
Interface class for accessing and setting values from an "indexable" collection of values.
Definition: gmValueAccessor.h:59
Values for the new state will be set to the ValueSet default.
Definition: gmValueSet.h:62
Auxiliar class used to store the complete set of simulation data.
Definition: gmSimulationData.h:51
QString stateTag(int snum) const
Returns the tag associated to the given state.
Definition: gmValueSet.h:113
int _currentSet
The index of the current set for rolling histories.
Definition: gmValueSet.h:157
GmValueSetData * valueSetData(int sindex, bool locked) const
Returns the value set data object associated with the given index. If locked == true,...
Definition: gmValueSet.h:103
double stateTime(int snum) const
Returns the time associated to the given state.
Definition: gmValueSet.h:116
int numValues() const
Returns the number of values stored in this value set.
Definition: gmValueSet.h:75
GmValueInfo * _info
Metadata defining the value set.
Definition: gmValueSet.h:151
GmValueSetEvalContext * _evalContext
The context used by accessors to evaluate function values (can be NULL)
Definition: gmValueSet.h:152
#define GMC_API_EXPORT
Macro for controling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_LI...
Definition: gmCoreConfig.h:35
The generic interface implemented by every GmValueSetData object. Its purpose is to provide a base cl...
Definition: gmValueSetData.h:65
int numSets() const
Returns the number of saved states for this set.
Definition: gmValueSet.h:97
GmLogLevel
Available log levels list.
Definition: gmLog.h:36
Auxiliar class used to store the needed information to translate an user function id / user function ...
Definition: gmValueSetEvalContext.h:45
Class representing a category with multiple logging levels.
Definition: gmLog.h:58
SaveStateMode
Initialization mode for calls to saveState()
Definition: gmValueSet.h:59
const QChar at(int position) const const
int t(int index) const
Get the index in _vsDataList corresponding to the given state index.
Definition: gmValueSet.h:142
QList< GmValueSetData * > _vsDataList
The list of value sets.
Definition: gmValueSet.h:154
void setStateTime(int snum, double time)
Updates the time associated to the given state.
Definition: gmValueSet.h:122
Base interface class for Mesh type plugins.
Definition: gmMesh.h:44