GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmAttributeResultsManager.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_ATTRIBUTE_RESULTS_MANAGER_H_
25#define _GEMA_ATTRIBUTE_RESULTS_MANAGER_H_
26
27#include "gmCoreConfig.h"
28
30#include "gmVector.h"
31#include "gmMatrix.h"
32
33class GmResultsData;
37
38#include <qtPtrList.h>
39#include <QObject>
40#include <QMap>
41
60{
61 Q_OBJECT
62
63public:
66 : _resultsData(resultsData),
67 _monitor(false),
68 _resultAttributes(true) // true to make the list own the stored pointers
69 {}
70
73
74 void clear();
75
77 void enableMonitoring() { _monitor = true; }
78
79 int registerResultAttribute(const QObject* owner, QString name, QString description, Unit unit,
80 int nlin, int ncol, QString format, int stats);
81
82 void removeResultAttribute(int id);
83 bool renameResultAttribute(int id, QString newName);
84
85 bool registerAttributeDataSrc(GmResultsDataSet* dataSet, GmAttributeResultsDataSrc* ds, QString& err);
86
87 void updateRegisteredAttributeDataSrc(GmResultsDataSet* dataSet, GmAttributeResultsDataSrc* ds);
88
89 void removeAttributeDataSet(GmResultsDataSet* dataSet);
90
91 void setResultAttributeValue(int id, double val);
92 void setResultAttributeValue(int id, double val1, double val2);
93 void setResultAttributeValue(int id, double val1, double val2, double val3);
94 void setResultAttributeValue(int id, const double* val);
95 void setResultAttributeValue(int id, const GmVector& val);
96 void setResultAttributeValue(int id, const GmMatrix& val);
97 void setResultAttributeValue(int id, QString val);
98
99 void clearAttributeStatistics (int id);
100 void updateAttributeStatistics(int id);
101
103 bool isValidAttributeId(int id) const { return id >= 0 && id < _resultAttributes.listSize() && _resultAttributes[id]; }
104
106 const QObject* attributeIdOwner(int id) const { return data(id)->_owner; }
107
109 int resultAttributeId(QString name) const { return _resultAttributesMap.value(name, -1); }
110
112 bool isNumericResult(int id) const { return info(id)->size(); } // String attributes have a 0 size
113
115 const GmAttributeResultsDataSrcInfo* resultAttributeInfo(int id) const { return info(id); }
116
118 const double* resultAttributeBuffer(int id) const
119 {
120 assert(isNumericResult(id));
121 return info(id)->attributeStats() ? value(id)._statValue->_value :
122 value(id)._numValue;
123 }
124
127 {
128 assert(!isNumericResult(id));
129 return *value(id)._strValue;
130 }
131
135 const double* resultAttributeStatisticsMinBuffer(int id) const
136 {
137 assert(isNumericResult(id));
138 return info(id)->attributeStats() ? value(id)._statValue->_statMin : NULL;
139 }
140
144 const double* resultAttributeStatisticsMaxBuffer(int id) const
145 {
146 assert(isNumericResult(id));
147 return info(id)->attributeStats() ? value(id)._statValue->_statMax : NULL;
148 }
149
153 const double* resultAttributeStatisticsSumBuffer(int id) const
154 {
155 assert(isNumericResult(id));
156 return info(id)->attributeStats() ? value(id)._statValue->_statSum : NULL;
157 }
158
162 quint64 resultAttributeStatisticsCount(int id) const
163 {
164 assert(isNumericResult(id));
165 return info(id)->attributeStats() ? value(id)._statValue->_statCount : 0;
166 }
167
168signals:
170 void attributeRegistered(int id, QString name);
171
173 void attributeUnregistered(int id, QString name);
174
175private slots:
176 void removeRegisteredAttributes(QObject* owner);
177
178private:
180
183 {
184 double* _value;
185 double* _statMin;
186 double* _statMax;
187 double* _statSum;
188 quint64 _statCount;
189
190 AttrValueWithStats(int s);
192 void zero(int s);
193 void clearStats(int s);
194 void updateStats(int s);
195 };
196
204 {
205 double* _numValue;
208
209 AttrValue() { _numValue = NULL; }
210 void init (GmAttributeResultsDataSrcInfo* info);
211 void clear (GmAttributeResultsDataSrcInfo* info);
212 void zero (GmAttributeResultsDataSrcInfo* info);
213 double* valueBuffer(GmAttributeResultsDataSrcInfo* info);
214 };
215
239
241 inline RegisteredAttrData* data(int id) const { assert(isValidAttributeId(id)); return _resultAttributes[id]; }
242
244 inline GmAttributeResultsDataSrcInfo* info(int id) const { return data(id)->_info; }
245
247 inline AttrValue& value(int id) const { return data(id)->_value; }
248
249 void unregisteredToRegistered(RegisteredAttrData* ad, int attrId);
250 void registeredToUnregistered(RegisteredAttrData* ad);
251
252 void emitValueChanged(RegisteredAttrData* ad, double val);
253 void emitValueChanged(RegisteredAttrData* ad, QString val);
254 void emitValueChanged(RegisteredAttrData* ad, const double* valList, int n);
255
256
262
263 bool _monitor;
264
267
272 QtPtrList<RegisteredAttrData> _resultAttributes;
273
276};
277
278#endif
A class implementing the GmResultsDataSrcInfo interface, storing the metadata and id for a result dat...
Definition gmAttributeResultsDataSrc.h:41
A basic class used to store meta-data information about result attributes DEFINITIONS.
Definition gmAttributeResultsDataSrcInfo.h:32
A class used to host the metadata and the values for all attributes added to the results data....
Definition gmAttributeResultsManager.h:60
GmAttributeResultsDataSrcInfo * info(int id) const
Helper function to return the attribute info associated to a valid attribute id.
Definition gmAttributeResultsManager.h:244
bool _monitor
Is there someone monitoring data changes?
Definition gmAttributeResultsManager.h:263
QString resultAttributeString(int id) const
Returns the string value for the given STRING result attribute id.
Definition gmAttributeResultsManager.h:126
AttrValue & value(int id) const
Helper function to return the attribute value associated to a valid attribute id.
Definition gmAttributeResultsManager.h:247
QMap< QString, QVector< QPair< GmResultsDataSet *, GmAttributeResultsDataSrc * > > > _unregisteredAttributes
A map storing for each unregistered attribute name, the set of dataSet + dataSrc pairs referencing th...
Definition gmAttributeResultsManager.h:275
int resultAttributeId(QString name) const
Returns the id associated with the given result attribute name or -1 if no attribute with that name e...
Definition gmAttributeResultsManager.h:109
void attributeRegistered(int id, QString name)
Signal emitted whenever a new attribute was registered by registerResultAttribute()
quint64 resultAttributeStatisticsCount(int id) const
Returns the count of the saved results for the given NUMERIC result attribute id. Returns 0 if no sta...
Definition gmAttributeResultsManager.h:162
bool isValidAttributeId(int id) const
Returns true if the given id is a valid attribute id.
Definition gmAttributeResultsManager.h:103
bool isNumericResult(int id) const
Returns true if the given valid result id refers to a numeric based value.
Definition gmAttributeResultsManager.h:112
const double * resultAttributeStatisticsMinBuffer(int id) const
Returns the internal buffer used to store the minimum saved result for the given NUMERIC result attri...
Definition gmAttributeResultsManager.h:135
~GmAttributeResultsManager()
Destructor.
Definition gmAttributeResultsManager.h:72
QMap< QString, int > _resultAttributesMap
Map storing for each registered attribute name its id on the _resultAttributes list.
Definition gmAttributeResultsManager.h:266
const double * resultAttributeStatisticsMaxBuffer(int id) const
Returns the internal buffer used to store the maximum saved result for the given NUMERIC result attri...
Definition gmAttributeResultsManager.h:144
void attributeUnregistered(int id, QString name)
Signal emitted whenever a registered attribute is removed by removeResultAttribute() or by its owner ...
const double * resultAttributeBuffer(int id) const
Returns the internal buffer used to store the last saved result for the given NUMERIC result attribut...
Definition gmAttributeResultsManager.h:118
const GmAttributeResultsDataSrcInfo * resultAttributeInfo(int id) const
Returns the metadata associated with the given result attribute id.
Definition gmAttributeResultsManager.h:115
void enableMonitoring()
Enables the emission of the monitorValueChanged() family of signals (from the resultsData object)
Definition gmAttributeResultsManager.h:77
GmResultsData * _resultsData
The results data object. Used for emitting signals whenever an attribute value is changed for a monit...
Definition gmAttributeResultsManager.h:261
const double * resultAttributeStatisticsSumBuffer(int id) const
Returns the internal buffer used to store the sum of the saved results for the given NUMERIC result a...
Definition gmAttributeResultsManager.h:153
const QObject * attributeIdOwner(int id) const
Returns the owner object for the given result attribute.
Definition gmAttributeResultsManager.h:106
GmAttributeResultsManager(GmResultsData *resultsData)
Constructor.
Definition gmAttributeResultsManager.h:65
RegisteredAttrData * data(int id) const
Helper function to return the full attribute data associated to a valid attribute id.
Definition gmAttributeResultsManager.h:241
QtPtrList< RegisteredAttrData > _resultAttributes
A list storing for each registered result attribute its data. Might contain "holes" due to unregister...
Definition gmAttributeResultsManager.h:272
Auxiliar class used to store the complete set of results data for a simulation.
Definition gmResultsData.h:58
A set storing what should be exported (saved / printed / monitored) by the result rule classes.
Definition gmResultsDataSet.h:58
Declaration of the GmAttributeResultsDataSrcInfo class.
Declaration of useful configuration definitions for the Core library.
#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
Declaration of the GmMatrix class.
arma::mat GmMatrix
The basic type for a GeMA matrix object. Currently based on an Armadillo matrix.
Definition gmMatrix.h:38
Declaration of the GmVector class.
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition gmVector.h:34
Q_DISABLE_COPY(Class)
An option to store an attribute value with statistics.
Definition gmAttributeResultsManager.h:183
double * _statSum
The buffer for storing the value sum.
Definition gmAttributeResultsManager.h:187
quint64 _statCount
The number of values accumulated on the stats attributes.
Definition gmAttributeResultsManager.h:188
double * _statMax
The buffer for storing the maximum value.
Definition gmAttributeResultsManager.h:186
double * _value
The value buffer.
Definition gmAttributeResultsManager.h:184
double * _statMin
The buffer for storing the minimum value.
Definition gmAttributeResultsManager.h:185
The data associated with registered attributes. It includes the object "owner" to allow for auto dere...
Definition gmAttributeResultsManager.h:224
AttrValue _value
The current attribute value.
Definition gmAttributeResultsManager.h:227
QVector< GmAttributeResultsDataSrc * > _monitoredList
The subset of _dataSrcList with data sources that should broadcast attribute changes.
Definition gmAttributeResultsManager.h:236
const QObject * _owner
The object that "owns" this attribute.
Definition gmAttributeResultsManager.h:226
GmAttributeResultsDataSrcInfo * _info
The metadata information on the registered attribute.
Definition gmAttributeResultsManager.h:225
QVector< QPair< GmResultsDataSet *, GmAttributeResultsDataSrc * > > _dataSrcList
If this attribute is referenced by any data set, the _dataSrcList references the data set and its ass...
Definition gmAttributeResultsManager.h:233
The union representing the saved value Using a QString instead of a QString* should be possible,...
Definition gmAttributeResultsManager.h:204
AttrValueWithStats * _statValue
The data used for storing a numeric value with statistics.
Definition gmAttributeResultsManager.h:206
double * _numValue
The buffer for storing a numeric value.
Definition gmAttributeResultsManager.h:205
QString * _strValue
A string value.
Definition gmAttributeResultsManager.h:207