GemaCoreLib
The GeMA Core library
gmResultDataSrc.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 
24 #ifndef _GEMA_RESULT_DATASRC_H_
25 #define _GEMA_RESULT_DATASRC_H_
26 
27 #include "gmResultDataSrcInfo.h"
28 
29 #include "gmInterpolator.h"
30 #include "gmValueAccessor.h"
31 #include "gmCellAccessor.h"
32 #include "gmGaussAccessor.h"
33 
34 #include <luaFunction.h>
35 #include <unitConverter.h>
36 
37 
44 {
45 public:
46  GmAttributeResultDataSrc(int trackId, GmResultDataSrcType type, QString name, Unit unit)
47  : _trackId(trackId), _type(type), _alias(name), _unit(unit), _info(NULL), _id(-1), _conv(NULL) {}
48 
49  virtual ~GmAttributeResultDataSrc() { delete _conv; }
50 
54  bool setInfo(const GmAttributeResultDataSrcInfo* info, int id)
55  {
56  assert(info);
57  assert(info->type() == _type);
58  assert(info->alias() == _alias);
59 
60  if(_unit.name().isEmpty()) // If the user didn't gave a unit, the result will be on _info unit.
61  _unit = info->unit();
62  else
63  {
64  bool compatibleUnits;
65  _conv = Unit::converter(info->unit(), _unit, &compatibleUnits);
66  if(!compatibleUnits)
67  return false; // We don't know how to convert from _info->unit() to _unit.
68  }
69 
70  _info = info;
71  _id = id;
72  return true;
73  }
74 
75  virtual int trackId() const { return _trackId; }
76  virtual GmResultDataSrcType type() const { return _type; }
77  virtual QString alias() const { return _alias; }
78  virtual Unit unit() const { return _unit; }
79  virtual QString description() const { return _info ? _info->description() : ""; }
80  virtual int size() const { return _info ? _info->size() : -1; }
81  virtual int nlin() const { return _info ? _info->nlin() : -1; }
82  virtual int ncol() const { return _info ? _info->ncol() : -1; }
83  virtual QString formatStr() const { return _info ? _info->formatStr() : ""; }
84 
85  int resultId() const { return _id; }
86  UnitConverter* unitConverter() const { return _conv; }
87 
88 private:
89  Q_DISABLE_COPY(GmAttributeResultDataSrc);
90 
91  int _trackId;
96  int _id;
98 };
99 
100 
105 {
106 public:
107 
110  : _trackId(trackId), _dim(-1), _history(0), _interpType(GM_DEFAULT_INTERPOLATOR),
111  _nResLin(0), _nResCol(0), _interp(NULL) {}
112 
114  virtual GmResultAcDataSrcBase::~GmResultAcDataSrcBase() { delete _interp; }
115 
116  // Comments on the base class
117  virtual int trackId() const { return _trackId; }
118 
119  // Returns the accessor id
120  virtual QString id() const = 0;
121 
122  // Comments on the base class
123  virtual QString alias() const { return _alias; }
124 
125  // Comments on the base class
126  virtual QString formatStr() const { return _formatStr; }
127 
129  virtual bool isScalar() const = 0;
130 
132  virtual int dimSize() const = 0;
133 
135  int history() const { return _history; }
136 
138  int dimFilter() const { return _dim; }
139 
141  void setBasicData(int dim, const QString& alias, int history,
142  GmInterpolatorType interpType, const QVariant& interpParam)
143  {
144  _dim = dim;
145  _alias = alias;
146  _history = history;
147  _interpType = interpType;
148  _interpParam = interpParam;
149  }
150 
152  void setFormatStr(const QString& formatStr) { _formatStr = formatStr; }
153 
155  void setTransformationFunction(LuaFunction& tfunc, int nresLin, int nresCol)
156  {
157  _tFunc = tfunc;
158  _tFunc.makeRef(); // Ensure that tFunc stores a function reference and not a stack index
159  _nResLin = nresLin;
160  _nResCol = nresCol;
161  }
162 
164  void setInterpolator(GmInterpolator* interp) { delete _interp; _interp = interp; }
165 
166 protected:
167  friend class GmResultsRule; // Give full acces to the results rule class
168 
169  Q_DISABLE_COPY(GmResultAcDataSrcBase);
170 
177  {
178  assert(!ptr->_interp);
179 
180  _interpType = GM_DEFAULT_INTERPOLATOR;
181  _interp = NULL;
182  _interpParam = QVariant();
183 
184  _trackId = ptr->_trackId;
185  _alias = ptr->_alias;
186  _dim = ptr->_dim;
187  _formatStr = ptr->_formatStr;
188  _history = ptr->_history;
189  _tFunc = ptr->_tFunc;
190  _nResLin = ptr->_nResLin;
191  _nResCol = ptr->_nResCol;
192  }
193 
194  int _trackId;
196  int _dim;
198  int _history;
202  int _nResLin;
203  int _nResCol;
205 };
206 
208 template <class T>
210 {
211 public:
212  // The stored accessr type
213  typedef T AcType;
214 
216  GmResultAcDataSrc(int trackId, T* ac) : GmResultAcDataSrcBase(trackId) { assert(ac); _ac = ac; _ownership = true; }
217 
219  virtual ~GmResultAcDataSrc() { if(_ownership) delete _ac; }
220 
221  // Comments on the base class
222  virtual QString id() const { return _ac->info()->id(); }
223 
224  // Comments on the base class
225  virtual QString description() const { return _ac->info()->description(); }
226 
227  // Comments on the base class
228  virtual Unit unit() const { return _ac->unit(); }
229 
230  // Comments on the base class
231  virtual bool isScalar() const { return _dim >= 0 || _ac->isScalar(); }
232 
233  // Comments on the base class
234  virtual int dimSize() const { return _dim == -1 ? _ac->valueSize() : 1; }
235 
236  // Comments on the base class
237  virtual int size() const { return _tFunc.isValid() ? _nResLin * _nResCol : dimSize(); }
238 
239  // Comments on the base class
240  virtual int nlin() const { return _tFunc.isValid() ? _nResLin : (_dim == -1 ? _ac->info()->nlin() : 1); }
241 
242  // Comments on the base class
243  virtual int ncol() const { return _tFunc.isValid() ? _nResCol : (_dim == -1 ? _ac->info()->ncol() : 1); }
244 
246  T* ac() const { return _ac; }
247 
251  void setAc(T* newAc) { if(_ownership) delete _ac; _ac = newAc; _ownership = true; }
252 
253 protected:
254 
264  template <class Result>
266  {
267  assert(dynamic_cast<Result*>(this)); // Result should realy be the same type as this!!!
268 
269  QVector<Result*> list;
270  list.append(dynamic_cast<Result*>(this));
271 
272  if(!isScalar())
273  {
274  for(int i = 1, ndim = _ac->valueSize(); i < ndim; i++)
275  {
276  Result* r = new Result(this);
277  r->_dim = i;
278  r->_alias = r->_alias + QString("_%1").arg(i+1);
279  list.append(r);
280  }
281  _dim = 0;
282  _alias = _alias + QString("_%1").arg(1); // Can't be done before the loop or the copy would already include the dimension suffix
283  }
284  return list;
285  }
286 
292  : GmResultAcDataSrcBase(ptr)
293  {
294  _ac = ptr->_ac;
295  _ownership = false;
296  }
297 
298  T* _ac;
299  bool _ownership;
300 };
301 
303 class GMC_API_EXPORT GmResultNodeDataSrc : public GmResultAcDataSrc<GmValueAccessor>
304 {
305 public:
308 
309  // Comments on the base class
310  virtual GmResultDataSrcType type() const { return GM_RR_DS_NODEDATA; }
311 
313  QVector<GmResultNodeDataSrc*> dimensionSplit() { return dimSplit<GmResultNodeDataSrc>(); }
314 
315 private:
317 
320 };
321 
324 {
325 public:
328 
330  virtual GmResultDataSrcType type() const { return GM_RR_DS_CELLDATA; }
331 
332  // Comments on the base class
333  QVector<GmResultCellDataSrc*> dimensionSplit() { return dimSplit<GmResultCellDataSrc>(); }
334 
335 private:
337 
340 };
341 
344 {
345 public:
348 
349  // Comments on the base class
350  virtual GmResultDataSrcType type() const { return GM_RR_DS_GAUSSDATA; }
351 
353  QVector<GmResultGaussDataSrc*> dimensionSplit() { return dimSplit<GmResultGaussDataSrc>(); }
354 
355 private:
357 
360 };
361 
362 #endif
363 
virtual GmResultDataSrcType type() const
Returns the data src type.
Definition: gmResultDataSrc.h:310
UnitConverter * _conv
The unit converter, if necessary, from _info->unit() to _unit.
Definition: gmResultDataSrc.h:97
Implementation of the GmCellAccessor proxy class.
int _nResCol
The number of columns of the result returned by _tFunc.
Definition: gmResultDataSrc.h:203
virtual GmResultDataSrcType type() const
Returns the data src type.
Definition: gmResultDataSrc.h:350
GmResultAcDataSrcBase(const GmResultAcDataSrcBase *ptr)
A kind of "copy" constructor geting a pointer instead of a reference that copies the contents of the ...
Definition: gmResultDataSrc.h:176
A GmResultDataSrc class holding a cell value accessor.
Definition: gmResultDataSrc.h:323
A GmResultDataSrc class holding a node value accessor.
Definition: gmResultDataSrc.h:303
virtual QString description() const
Returns the data src description, when available.
Definition: gmResultDataSrc.h:225
void append(const T &value)
GmInterpolator * _interp
The configured interpolator object. Can be NULL.
Definition: gmResultDataSrc.h:204
QString _alias
The name given to the "exported" data. Always filled (might be equal to id())
Definition: gmResultDataSrc.h:195
A basic interface with the metadata common to all result data src types. This is the information that...
Definition: gmResultDataSrcInfo.h:50
QVector< GmResultGaussDataSrc * > dimensionSplit()
See dimSplit() documentation on the base calss.
Definition: gmResultDataSrc.h:353
virtual QString alias() const
Returns the data src "exported" id.
Definition: gmResultDataSrc.h:77
The GmGaussAccessor class is a proxy object to a value accesor implementing a more convenient interfa...
Definition: gmGaussAccessor.h:38
void makeRef()
virtual Unit unit() const
Returns the unit in which the data is expressed.
Definition: gmResultDataSrc.h:78
QVariant _interpParam
Optional interpolation parameters.
Definition: gmResultDataSrc.h:200
GmResultNodeDataSrc(int trackId, GmValueAccessor *ac)
Constructor.
Definition: gmResultDataSrc.h:307
A GmResultDataSrc class holding a Gauss value accessor.
Definition: gmResultDataSrc.h:343
Node attributes + State vars.
Definition: gmResultDataSrcInfo.h:36
Interpolation should be done using the default method for the interpolator object.
Definition: gmInterpolator.h:133
int dimFilter() const
Returns the dimension filter value (-1 if there is no filter)
Definition: gmResultDataSrc.h:138
GmResultAcDataSrcBase(int trackId)
Default constructor.
Definition: gmResultDataSrc.h:109
GmResultDataSrcType
The types of data srcs stored by a rule.
Definition: gmResultDataSrcInfo.h:34
GmResultCellDataSrc(int trackId, GmCellAccessor *ac)
Constructor.
Definition: gmResultDataSrc.h:327
Interface class for accessing and setting values from an "indexable" collection of values.
Definition: gmValueAccessor.h:59
QString _alias
The data src alias (needed while _info is NULL)
Definition: gmResultDataSrc.h:93
GmResultGaussDataSrc(const GmResultAcDataSrc< GmGaussAccessor > *base)
Special "copy" (gets a pointer and not a reference) constructor accessible by dimSplit() to duplicate...
Definition: gmResultDataSrc.h:359
virtual Unit unit() const
Returns the unit in which the data is expressed.
Definition: gmResultDataSrcInfo.h:122
Interpolator class used for managing available interpolator algorithms and providing basic support fu...
Definition: gmInterpolator.h:228
bool setInfo(const GmAttributeResultDataSrcInfo *info, int id)
Sets the associated info object + its id on GmResultsData. If the src data unit is incompatible with ...
Definition: gmResultDataSrc.h:54
bool _ownership
Are we the owner of _ac? This can be false as a result of the dimSplit() operation.
Definition: gmResultDataSrc.h:299
GmResultGaussDataSrc(int trackId, GmGaussAccessor *ac)
Constructor.
Definition: gmResultDataSrc.h:347
GmResultCellDataSrc(const GmResultAcDataSrc< GmCellAccessor > *base)
Special "copy" (gets a pointer and not a reference) constructor accessible by dimSplit() to duplicate...
Definition: gmResultDataSrc.h:339
virtual int nlin() const
The number of lines in the returned result, taking into account any applied transformations or dim fi...
Definition: gmResultDataSrc.h:81
A calss storing basic information about a result data to be exported (monitored / saved),...
Definition: gmResultDataSrc.h:104
virtual QString alias() const
Returns the data src "exported" id.
Definition: gmResultDataSrc.h:123
int _trackId
The numeric id for this data src (a value between 0 and the number of data srcs in the model)
Definition: gmResultDataSrc.h:91
virtual Unit unit() const
Returns the unit in which the data is expressed.
Definition: gmResultDataSrc.h:228
QVector< Result * > dimSplit()
Returns a vector with as many data srcs as dimensions. The first one will be the original data src wi...
Definition: gmResultDataSrc.h:265
int _history
The state accessed by this data src (0 = current state, 1 = previous, etc..)
Definition: gmResultDataSrc.h:198
A result rule storing what should be exported, when it should be exported and to where it should be e...
Definition: gmResultsRule.h:54
virtual int dimSize() const
Returns the accessor valueSize() adjusted by an optional dimension filter.
Definition: gmResultDataSrc.h:234
int history() const
Returns the state accessed by this data src.
Definition: gmResultDataSrc.h:135
GmInterpolatorType
Available interpolation methods. Not every method is suitable for every kind of interpolator class....
Definition: gmInterpolator.h:62
virtual int ncol() const
The number of columns in the returned result, taking into account any applied transformations or dim ...
Definition: gmResultDataSrc.h:82
void setTransformationFunction(LuaFunction &tfunc, int nresLin, int nresCol)
Sets the transformation function along with its result dimensions.
Definition: gmResultDataSrc.h:155
void setAc(T *newAc)
Updates the stored accessor, taking ownership of it. Used by GmFileIO for replacing an accessor by an...
Definition: gmResultDataSrc.h:251
The GmCellAccessor class is a proxy object to a value accesor implementing a more convenient interfac...
Definition: gmCellAccessor.h:66
GmResultDataSrcType _type
The data src type (needed while _info is NULL)
Definition: gmResultDataSrc.h:92
virtual QString formatStr() const =0
How should dataSrc values be formated?
Implementation of the GmGaussAccessor proxy class.
void setInterpolator(GmInterpolator *interp)
Sets the configured interpolator for this data source. Takes ownership of the object.
Definition: gmResultDataSrc.h:164
GmResultAcDataSrc(int trackId, T *ac)
Constructor.
Definition: gmResultDataSrc.h:216
virtual int size() const
Returns the dimension of the data src values, taking into account any applied transformations or dim ...
Definition: gmResultDataSrc.h:237
static UnitConverter * converter(const Unit &srcUnit, const Unit &dstUnit, bool *compatible=NULL)
QVector< GmResultNodeDataSrc * > dimensionSplit()
See dimSplit() documentation on the base calss.
Definition: gmResultDataSrc.h:313
virtual QString formatStr() const
How should dataSrc values be formated?
Definition: gmResultDataSrc.h:126
virtual GmResultDataSrcType type() const
See dimSplit() documentation on the base calss.
Definition: gmResultDataSrc.h:330
T * ac() const
Returns the associated accessor.
Definition: gmResultDataSrc.h:246
GmInterpolatorType _interpType
How do we interpolate data?
Definition: gmResultDataSrc.h:199
const GmAttributeResultDataSrcInfo * _info
The metadata info. Might be NULL for a while.
Definition: gmResultDataSrc.h:95
virtual GmResultDataSrcType type() const
Returns the data src type.
Definition: gmResultDataSrcInfo.h:119
virtual ~GmResultAcDataSrcBase()
Destructor.
Definition: gmResultDataSrc.h:114
virtual int trackId() const
Returns a numeric id for this data src (a value between 0 and the number of monitored data srcs in th...
Definition: gmResultDataSrc.h:117
virtual QString alias() const =0
Returns the data src "exported" id.
A class implementing the GmResultDataSrcInfo interface, storing the metadata and id for a result data...
Definition: gmResultDataSrc.h:43
QString _formatStr
The format string for the data. Usually equal to the accessor format.
Definition: gmResultDataSrc.h:197
#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
virtual int nlin() const
The number of lines in the returned result, taking into account any applied transformations or dim fi...
Definition: gmResultDataSrc.h:240
virtual QString alias() const
Returns the data src "exported" id.
Definition: gmResultDataSrcInfo.h:120
Declaration of the GmResultDataSrcInfo interface and GmAttributeResultDataSrcInfo class.
virtual int ncol() const
The number of columns in the returned result, taking into account any applied transformations or dim ...
Definition: gmResultDataSrc.h:243
Declaration of the GmValueAccessor interface and GmValueAccessorBase class.
virtual bool isScalar() const =0
Returns true if the accessor value is a scalar value or there is a dimensional filter.
virtual int trackId() const
Returns a numeric id for this data src (a value between 0 and the number of monitored data srcs in th...
Definition: gmResultDataSrc.h:75
GmResultNodeDataSrc(const GmResultAcDataSrc< GmValueAccessor > *base)
Special "copy" (gets a pointer and not a reference) constructor accessible by dimSplit() to duplicate...
Definition: gmResultDataSrc.h:319
int _dim
A "bound" dimension for returning a scalar when the data is multidimensional (-1 for returning all va...
Definition: gmResultDataSrc.h:196
A basic class used to store meta-data information about result attributes DEFINITIONS.
Definition: gmResultDataSrcInfo.h:100
int _id
The attribute id inside GmResultData when _info is not NULL. -1 when it is.
Definition: gmResultDataSrc.h:96
Gauss attributes.
Definition: gmResultDataSrcInfo.h:38
T * _ac
The node data accessor.
Definition: gmResultDataSrc.h:298
GmResultAcDataSrc(const GmResultAcDataSrc< T > *ptr)
A private "copy" constructor geting a pointer instead of a reference that copies the contents of the ...
Definition: gmResultDataSrc.h:291
int _nResLin
The number of lines of the result returned by _tFunc.
Definition: gmResultDataSrc.h:202
Cell attributes + properties.
Definition: gmResultDataSrcInfo.h:37
virtual int dimSize() const =0
Returns the accessor valueSize() adjusted by an optional dimension filter.
void setFormatStr(const QString &formatStr)
Sets the format string.
Definition: gmResultDataSrc.h:152
virtual GmResultDataSrcType type() const
Returns the data src type.
Definition: gmResultDataSrc.h:76
virtual QString description() const
Returns the data src description, when available.
Definition: gmResultDataSrc.h:79
Unit _unit
The exported unit. Might be different from _info->unit()
Definition: gmResultDataSrc.h:94
virtual int size() const
Returns the dimension of the data src values, taking into account any applied transformations or dim ...
Definition: gmResultDataSrc.h:80
virtual ~GmResultAcDataSrc()
Destructor.
Definition: gmResultDataSrc.h:219
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
void setBasicData(int dim, const QString &alias, int history, GmInterpolatorType interpType, const QVariant &interpParam)
Sets the values of the given basic object attributes.
Definition: gmResultDataSrc.h:141
Aux class adding an accessor to a basic result data source.
Definition: gmResultDataSrc.h:209
int _trackId
The numeric id for this data src (a value between 0 and the number of data srcs in the model)
Definition: gmResultDataSrc.h:194
virtual bool isScalar() const
Returns true if the accessor value is a scalar value or there is a dimensional filter.
Definition: gmResultDataSrc.h:231
Declaration of the GmInterpolator and GmInterpolatorObject classes.
LuaFunction _tFunc
An optional transformation function applied over the data (filtered by _dim) before exporting.
Definition: gmResultDataSrc.h:201
virtual QString formatStr() const
How should dataSrc values be formated?
Definition: gmResultDataSrc.h:83