GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmValueSetPackedData.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_PACKED_DATA_H_
24#define _GEMA_VALUE_SET_PACKED_DATA_H_
25
26#include "gmValueSetData.h"
27#include "gmPackedBuffer.h"
28
29class GmUserFunction;
31class GmNanBoxedValue;
32
33template <class T, bool Align> class GmTLBuffer;
34
37{
38public:
40 virtual GmPackedBuffer* pack() const = 0;
41
46 virtual void packLayoutUpdated() = 0;
47};
48
60template <class T, template <class> class Vector>
62{
63public:
64 GmNoFValueSetPackedData(GmPackedBuffer* pack, GmValueInfo* info, int state);
65
67
68 virtual void packLayoutUpdated();
69
70 virtual GmPackedBuffer* pack() const { return _pack; }
71
72 // See comments on the base class
73 virtual GmValueInfo* info() const { return _info; }
74
75 // See comments on the base class
76 virtual bool isDual() const { return _pack->isDual(); }
77
78 // See comments on the base class
79 virtual int numValues() const { return _pack->numValues(); }
80
81 // See comments on the base class
82 virtual int storedItemSize() const { return _dim * sizeof(T); }
83
84 virtual GmTrackedValueAccessor* accessor(const GmLogCategory& logger, UnitConverter* conv,
85 QString desiredUnit, bool atomic = false);
86
88 virtual size_t usedMemory() const { return 0; }
89
90#if defined ENABLE_TESTS || defined ENABLE_VALUESETDATA_TESTS
91 virtual void validateInternalStructure();
92#endif
93
94protected:
96 const T* iptr(int index) const
97 {
98 assert(index >= 0 && index < numValues());
99 if constexpr(std::is_same_v<Vector<T>, GmSingleVector<T>>)
100 {
101 assert(_ptr && _strideOrIndex);
102 return (T*)(_ptr + (size_t)index * _strideOrIndex);
103 }
104 else
105 {
106 assert(_strideOrIndex >= 0);
107 return ((T*)_pack->iptr(_strideOrIndex, index)) + _state * _dim;
108 }
109 }
110
112 T* iptr(int index) { return const_cast<T*>(const_cast<const GmNoFValueSetPackedData<T,Vector>*>(this)->iptr(index)); }
113
114 // See comments on the base class
115 virtual bool isDefValue(int index) const { return !memcmp(value(index), _info->defValue(), _dim * sizeof(double)); }
116
117 // See comments on the base class
118 virtual GmValueSetData::StoredValueType storedValueType(int index) const { Q_UNUSED(index); return GM_SVT_NUMBER; }
119
120 virtual const double* value (int index) const;
121 virtual bool setValue(int index, const double* values);
122
123 // See comments on the base class. Functions are not supported by this value set
124 virtual void* functionValue(int index) const { Q_UNUSED(index); assert(0); return NULL; }
125
126 // See comments on the base class. Functions are not supported by this value set
127 virtual bool setFunctionValue(int index, GmValueSetData::StoredValueType type, void* functionObj)
128 {
129 Q_UNUSED(index); Q_UNUSED(type); Q_UNUSED(functionObj);
130 assert(0);
131 return false;
132 }
133
134protected:
137 int _state;
138 int _dim;
139 char* _ptr;
142
143private:
144 Q_DISABLE_COPY(GmNoFValueSetPackedData);
145};
146
151template <template <class> class Vector>
153{
154public:
155 GmFValueSetPackedData(GmPackedBuffer* pack, GmValueInfo* info, int state, GmValueSetEvalContext* evalContext);
156
157 virtual GmTrackedValueAccessor* accessor(const GmLogCategory& logger, UnitConverter* conv,
158 QString desiredUnit, bool atomic = false);
159
160protected:
162 const GmNanBoxedValue* nanBoxPtr(int index) const { return (const GmNanBoxedValue*)iptr(index); }
163
165 GmNanBoxedValue* nanBoxPtr(int index) { return (GmNanBoxedValue*)iptr(index); }
166
167 virtual bool isDefValue(int index) const;
168
169 virtual GmValueSetData::StoredValueType storedValueType(int index) const;
170
171 virtual const double* value (int index) const;
172 virtual bool setValue(int index, const double* values);
173
174 virtual void* functionValue (int index) const;
175 virtual bool setFunctionValue(int index, GmValueSetData::StoredValueType type, void* functionObj);
176
177private:
179};
180
181
182#endif
183
184
The value set data object for packed data with function support. Very similar to GmFVectorValueSetSto...
Definition gmValueSetPackedData.h:153
const GmNanBoxedValue * nanBoxPtr(int index) const
Returns a pointer to the index data inside the pack converted to a Nan Box.
Definition gmValueSetPackedData.h:162
GmNanBoxedValue * nanBoxPtr(int index)
Non-const overload to return a pointer to the index data inside the pack converted to a Nan Box.
Definition gmValueSetPackedData.h:165
GmUserFunction * _defFunction
The default user function if the default value is a function, NULL otherwise.
Definition gmValueSetPackedData.h:178
Class representing a category with multiple logging levels.
Definition gmLog.h:58
A wrapper class around QtNanBoxedValue providing specific constructors to store user functions / user...
Definition gmNanBoxedValue.h:41
The value set data object for packed data without function support. Very similar to GmVectorValueSetS...
Definition gmValueSetPackedData.h:62
int _dim
Value dimension. Equal to _info->size();.
Definition gmValueSetPackedData.h:138
int _state
The state index number if _info->history() > 0, 0 otherwise.
Definition gmValueSetPackedData.h:137
virtual int numValues() const
Returns the number of values stored in this value set.
Definition gmValueSetPackedData.h:79
virtual size_t usedMemory() const
Memory usage is accounted by the pack and not by the value set data.
Definition gmValueSetPackedData.h:88
char * _ptr
The pointer to the first entry of our data in the pack WHEN Vector is a single vector.
Definition gmValueSetPackedData.h:139
GmTLBuffer< double, GM_VALUESET_ALIGNED_BUFFERS > * _convBuffer
The buffer used to store data returned by value() when T is not double.
Definition gmValueSetPackedData.h:141
int _strideOrIndex
The "distance" between data entries for Single Vector or the value set index in the pack for Dual vec...
Definition gmValueSetPackedData.h:140
virtual GmPackedBuffer * pack() const
Returns the associated pack object;.
Definition gmValueSetPackedData.h:70
virtual bool isDual() const
Returns true if the underlying data storage is a dual vector, false if not.
Definition gmValueSetPackedData.h:76
const T * iptr(int index) const
Returns a pointer to the index data inside the pack.
Definition gmValueSetPackedData.h:96
virtual int storedItemSize() const
Returns the size in bytes of a value set item. It is usually equal to the data dimension (info()->siz...
Definition gmValueSetPackedData.h:82
GmPackedBufferImpl< Vector > * _pack
The pack that contains the data for this object.
Definition gmValueSetPackedData.h:135
virtual GmValueInfo * info() const
Returns a pointer to the associated value info object.
Definition gmValueSetPackedData.h:73
GmValueInfo * _info
The info object describing this set contents.
Definition gmValueSetPackedData.h:136
T * iptr(int index)
Non-const overload to return a pointer to the index data inside the pack.
Definition gmValueSetPackedData.h:112
virtual bool setFunctionValue(int index, GmValueSetData::StoredValueType type, void *functionObj)
Overload of setValue() storing a user function definition.
Definition gmValueSetPackedData.h:127
virtual void * functionValue(int index) const
Returns a pointer to the stored function object. Return will be either a GmUserFunction* or a GmUserF...
Definition gmValueSetPackedData.h:124
virtual bool isDefValue(int index) const
Returns true if the indexed value is the default value for the set.
Definition gmValueSetPackedData.h:115
virtual GmValueSetData::StoredValueType storedValueType(int index) const
Returns the type (number, function definition/evaluator) of the stored value for the given index.
Definition gmValueSetPackedData.h:118
The basic interface for a shared buffer storing interleaved data for a group of value sets.
Definition gmPackedBuffer.h:119
The concrete implementation for GmPackedBuffer. The template parameter defines the kind of vector use...
Definition gmPackedBuffer.h:188
A class with the same API as GmDualVector storing a single vector. No query "if" overhead....
Definition gmSingleVector.h:37
A class similar to GmTLS that creates a buffer for each possible thread in the GmThreadManager,...
Definition gmThreadLocalBuffer.h:106
Auxiliary class responisble for allowing a value accessor to track changes to the referenced value se...
Definition gmTrackedValueAccessor.h:38
Class used to store the definition of a user function and its parameters.
Definition gmUserFunction.h:82
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
virtual const double * value(int index) const =0
Returns the numeric value stored at the given index (converted to a double if needed) Must be called ...
virtual void * functionValue(int index) const =0
Returns a pointer to the stored function object. Return will be either a GmUserFunction* or a GmUserF...
virtual int numValues() const =0
Returns the number of values stored in this value set.
StoredValueType
Enumeration to detect the type of stored data for an index.
Definition gmValueSetData.h:62
@ GM_SVT_NUMBER
A number.
Definition gmValueSetData.h:63
virtual GmTrackedValueAccessor * accessor(const GmLogCategory &logger, UnitConverter *conv, QString desiredUnit, bool atomic=false)=0
Returns an accessor for the stored data. The atomic flag can be used by the caller to request that a ...
virtual bool setFunctionValue(int index, StoredValueType type, void *functionObj)=0
Overload of setValue() storing a user function definition.
virtual bool setValue(int index, const double *values)=0
Updates the value stored at the given index with a numeric value (converted to the correct type if ne...
virtual bool isDefValue(int index) const =0
Returns true if the indexed value is the default value for the set.
virtual StoredValueType storedValueType(int index) const =0
Returns the type (number, function definition/evaluator) of the stored value for the given index.
Auxiliar class used to store the needed information to translate an user function id / user function ...
Definition gmValueSetEvalContext.h:46
The generic GmValueSetData interface for packed storage.
Definition gmValueSetPackedData.h:37
virtual void packLayoutUpdated()=0
Updates internal data after a layout update inside the pack. This INCLUDES internal buffer updates,...
virtual GmPackedBuffer * pack() const =0
Returns the associated pack object;.
#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 GmPackedBuffer and GmPackedBufferInfo classes.
Declaration of the GmValueSetData interface.