1#ifndef Cpl_Dm_Mp_Array_h_
2#define Cpl_Dm_Mp_Array_h_
23#ifndef OPTION_CPL_DM_MP_ARRAY_TEMP_ARRAY_NUM_ELEMENTS
24#define OPTION_CPL_DM_MP_ARRAY_TEMP_ARRAY_NUM_ELEMENTS 8
69 const char* symbolicName,
81 const char* symbolicName,
85 void* initialValueSrcPtr );
92 virtual bool readArrayElements(
void* dstData,
size_t dstNumElements,
size_t srcIndex = 0, uint16_t* seqNumPtr = 0 ) const noexcept;
145template<class ELEMTYPE>
151 const char* symbolicName,
154 :
ArrayBase_( myModelBase, symbolicName, myDataPtr, numElements, sizeof( ELEMTYPE ) )
164 const char* symbolicName,
168 :
ArrayBase_( myModelBase, symbolicName, myDataPtr, numElements, sizeof( ELEMTYPE ), srcData )
175 inline bool read( ELEMTYPE* dstArrray,
size_t dstNumElements,
size_t srcIndex = 0, uint16_t* seqNumPtr = 0 ) const noexcept
196 size_t dstNumElements,
198 size_t srcIndex = 0 )
201 bool result = read( dstArrray, dstNumElements, srcIndex, &seqNum );
210 JsonObject obj = doc.createNestedObject(
"val" );
212 JsonArray arr = obj.createNestedArray(
"elems" );
213 ELEMTYPE* elemPtr = (ELEMTYPE*)
m_dataPtr;
216 arr.add( elemPtr[i] );
225 if ( src.is<JsonObject>() ==
false )
229 *errorMsg =
"'val' key/value pair is NOT an JSON object";
235 JsonArray elems = src[
"elems"];
236 if ( elems.isNull() )
240 *errorMsg =
"'val' key/value pair is missing the embedded 'elems' array";
246 size_t startIdx = src[
"start"] | 0;
249 size_t numElements = elems.size();
254 errorMsg->format(
"Number of array elements ([%lu+%lu)] exceeds the MP's element count (%lu)", startIdx, numElements,
m_numElements );
261 while ( numElements )
269 if ( elems[idx].is<ELEMTYPE>() ==
false )
273 errorMsg->format(
"Failed parsing element[%lu]. Content of the MP is suspect!", offset );
277 tempArray[idx] = elems[idx + offset].as<ELEMTYPE>();
294template<
class ELEMTYPE,
int NUMELEMS,
class MPTYPE>
299 ELEMTYPE m_data[NUMELEMS];
304 const char* symbolicName )
315 const char* symbolicName,
317 :
NumericArrayBase_<ELEMTYPE>( myModelBase, symbolicName, m_data, NUMELEMS, srcData )
325 return ArrayBase_::copyArrayFrom( src, lockRequest );
331 ArrayBase_::attachSubscriber( observer, initialSeqNumber );
337 ArrayBase_::detachSubscriber( observer );
366 return "Cpl::Dm::Mp::ArrayUint8";
393 return "Cpl::Dm::Mp::ArrayUint32";
420 return "Cpl::Dm::Mp::ArrayUint64";
447 return "Cpl::Dm::Mp::ArrayInt8";
474 return "Cpl::Dm::Mp::ArrayInt32";
501 return "Cpl::Dm::Mp::ArrayInt64";
528 return "Cpl::Dm::Mp::ArrayFloat";
555 return "Cpl::Dm::Mp::ArrayDouble";
#define OPTION_CPL_DM_MP_ARRAY_TEMP_ARRAY_NUM_ELEMENTS
The number of Elements in the temporary array (that is allocated on the STACK) when parsing the array...
Definition Array.h:24
This concrete class implements a simple Model Database.
Definition ModelDatabase.h:56
This concrete class provide common infrastructure for a Model Point.
Definition ModelPointCommon_.h:32
void * m_dataPtr
Reference to my Data.
Definition ModelPointCommon_.h:227
This mostly abstract class defines the interface for a Model Point.
Definition ModelPoint.h:46
LockRequest_T
Options related to the Model Point's locked state.
Definition ModelPoint.h:50
@ eNO_REQUEST
No change in the MP's lock state is requested.
Definition ModelPoint.h:51
static const uint16_t SEQUENCE_NUMBER_UNKNOWN
Magic value to use when registering for a change notification and application does not 'know' the cur...
Definition ModelPoint.h:62
virtual void attachSubscriber(SubscriberApi &observer, uint16_t initialSeqNumber=SEQUENCE_NUMBER_UNKNOWN) noexcept=0
This method is used to attach a subscriber to a Model Point.
This a mostly concrete class provides 'common' implementation for a Model Point who's data is a array...
Definition Array.h:49
ArrayBase_(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName, void *myDataPtr, size_t numElements, size_t elementSize, void *initialValueSrcPtr)
Constructor.
virtual uint16_t copyArrayFrom(const ArrayBase_ &src, Cpl::Dm::ModelPoint::LockRequest_T lockRequest=Cpl::Dm::ModelPoint::eNO_REQUEST) noexcept
Updates the MP with the valid-state/data from 'src'. Note: the src.lock state is NOT copied.
size_t elemIndex
Starting array index.
Definition Array.h:56
uint8_t * elemPtr
Pointer to the 1st element in the array to read/write.
Definition Array.h:54
size_t getNumElements() const noexcept
Returns the number of element in the array. This method IS thread safe.
Definition Array.h:112
void copyDataTo_(void *dstData, size_t dstSize) const noexcept
See Cpl::Dm::ModelPoint.
size_t m_numElements
Number of elements in the array.
Definition Array.h:61
bool exportMetadata_(void *dstDataStream, size_t &bytesAdded) const noexcept
See Cpl::Dm::ModelPoint.
size_t getInternalDataSize_() const noexcept
See Cpl::Dm::Point.
bool importMetadata_(const void *srcDataStream, size_t &bytesConsumed) noexcept
See Cpl::Dm::ModelPoint.
bool isDataEqual_(const void *otherData) const noexcept
See Cpl::Dm::ModelPoint.
size_t numElements
Number of element to read/write.
Definition Array.h:55
void copyDataFrom_(const void *srcData, size_t srcSize) noexcept
See Cpl::Dm::ModelPoint.
size_t m_elementSize
Size, in bytes, of an element.
Definition Array.h:64
virtual bool readArrayElements(void *dstData, size_t dstNumElements, size_t srcIndex=0, uint16_t *seqNumPtr=0) const noexcept
The caller can read a subset of array starting from the specified index in the Model Point's array.
ArrayBase_(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName, void *myDataPtr, size_t numElements, size_t elementSize)
Constructor: Invalid MP.
virtual uint16_t writeArrayElements(const void *srcData, size_t srcNumElements, size_t dstIndex=0, Cpl::Dm::ModelPoint::LockRequest_T lockRequest=Cpl::Dm::ModelPoint::eNO_REQUEST) noexcept
The caller can write a subset of array starting from the specified index in the Model Point's array.
double Array
Definition Array.h:538
const char * getTypeAsText() const noexcept
See Cpl::Dm::ModelPodouble.
Definition Array.h:553
ArrayDouble(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName)
Constructor. Invalid Point.
Definition Array.h:541
Cpl::Dm::Subscriber< ArrayDouble > Observer
Type safe subscriber.
Definition Array.h:559
ArrayDouble(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName, double initialValueArray[])
Constructor. Valid Point. Requires an initial value. The array size of 'initialValueArray' must match...
Definition Array.h:547
float Array
Definition Array.h:511
Cpl::Dm::Subscriber< ArrayFloat > Observer
Type safe subscriber.
Definition Array.h:532
ArrayFloat(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName, float initialValueArray[])
Constructor. Valid Point. Requires an initial value. The array size of 'initialValueArray' must match...
Definition Array.h:520
const char * getTypeAsText() const noexcept
See Cpl::Dm::ModelPofloat.
Definition Array.h:526
ArrayFloat(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName)
Constructor. Invalid Point.
Definition Array.h:514
int32_t Array
Definition Array.h:457
ArrayInt32(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName)
Constructor. Invalid Point.
Definition Array.h:460
const char * getTypeAsText() const noexcept
See Cpl::Dm::ModelPoint.
Definition Array.h:472
Cpl::Dm::Subscriber< ArrayInt32 > Observer
Type safe subscriber.
Definition Array.h:478
ArrayInt32(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName, int32_t initialValueArray[])
Constructor. Valid Point. Requires an initial value. The array size of 'initialValueArray' must match...
Definition Array.h:466
int64_t Array
Definition Array.h:484
ArrayInt64(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName)
Constructor. Invalid Point.
Definition Array.h:487
ArrayInt64(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName, int64_t initialValueArray[])
Constructor. Valid Point. Requires an initial value. The array size of 'initialValueArray' must match...
Definition Array.h:493
Cpl::Dm::Subscriber< ArrayInt64 > Observer
Type safe subscriber.
Definition Array.h:505
const char * getTypeAsText() const noexcept
See Cpl::Dm::ModelPoint.
Definition Array.h:499
int8_t Array
Definition Array.h:430
Cpl::Dm::Subscriber< ArrayInt8 > Observer
Type safe subscriber.
Definition Array.h:451
const char * getTypeAsText() const noexcept
See Cpl::Dm::ModelPoint.
Definition Array.h:445
ArrayInt8(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName)
Constructor. Invalid Point.
Definition Array.h:433
ArrayInt8(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName, int8_t initialValueArray[])
Constructor. Valid Point. Requires an initial value. The array size of 'initialValueArray' must match...
Definition Array.h:439
uint32_t Array
Definition Array.h:376
ArrayUint32(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName)
Constructor. Invalid Point.
Definition Array.h:379
ArrayUint32(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName, uint32_t initialValueArray[])
Constructor. Valid Point. Requires an initial value. The array size of 'initialValueArray' must match...
Definition Array.h:385
const char * getTypeAsText() const noexcept
See Cpl::Dm::ModelPoint.
Definition Array.h:391
Cpl::Dm::Subscriber< ArrayUint32 > Observer
Type safe subscriber.
Definition Array.h:397
uint64_t Array
Definition Array.h:403
Cpl::Dm::Subscriber< ArrayUint64 > Observer
Type safe subscriber.
Definition Array.h:424
const char * getTypeAsText() const noexcept
See Cpl::Dm::ModelPoint.
Definition Array.h:418
ArrayUint64(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName, uint64_t initialValueArray[])
Constructor. Valid Point. Requires an initial value. The array size of 'initialValueArray' must match...
Definition Array.h:412
ArrayUint64(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName)
Constructor. Invalid Point.
Definition Array.h:406
uint8_t Array
Definition Array.h:349
const char * getTypeAsText() const noexcept
See Cpl::Dm::ModelPoint.
Definition Array.h:364
Cpl::Dm::Subscriber< ArrayUint8 > Observer
Type safe subscriber.
Definition Array.h:370
ArrayUint8(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName, uint8_t initialValueArray[])
Constructor. Valid Point. Requires an initial value. The array size of 'initialValueArray' must match...
Definition Array.h:358
ArrayUint8(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName)
Constructor. Invalid Point.
Definition Array.h:352
This mostly concrete template class implements an 'numeric Array' Model Point with an element size of...
Definition Array.h:296
NumericArray_(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName)
Constructor: Invalid MP.
Definition Array.h:303
NumericArray_(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName, ELEMTYPE *srcData)
Constructor.
Definition Array.h:314
void detach(Cpl::Dm::Subscriber< MPTYPE > &observer) noexcept
Type safe un-register observer.
Definition Array.h:335
void attach(Cpl::Dm::Subscriber< MPTYPE > &observer, uint16_t initialSeqNumber=Cpl::Dm::ModelPoint::SEQUENCE_NUMBER_UNKNOWN) noexcept
Type safe register observer.
Definition Array.h:329
uint16_t copyFrom(const MPTYPE &src, Cpl::Dm::ModelPoint::LockRequest_T lockRequest=Cpl::Dm::ModelPoint::eNO_REQUEST) noexcept
Updates the MP's data/valid-state from 'src'.
Definition Array.h:323
This template class extends the implementation of ArrayBase_ to support the toJSON() and fromJSON_() ...
Definition Array.h:147
bool read(ELEMTYPE *dstArrray, size_t dstNumElements, size_t srcIndex=0, uint16_t *seqNumPtr=0) const noexcept
Type safe read. See Cpl::Dm::ModelPoint.
Definition Array.h:175
void setJSONVal(JsonDocument &doc) noexcept
See Cpl::Dm::Point.
Definition Array.h:208
NumericArrayBase_(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName, ELEMTYPE *myDataPtr, size_t numElements)
Constructor: Invalid MP.
Definition Array.h:150
bool fromJSON_(JsonVariant &src, Cpl::Dm::ModelPoint::LockRequest_T lockRequest, uint16_t &retSequenceNumber, Cpl::Text::String *errorMsg) noexcept
See Cpl::Dm::Point.
Definition Array.h:222
bool readAndSync(ELEMTYPE *dstArrray, size_t dstNumElements, SubscriberApi &observerToSync, size_t srcIndex=0)
This method is used to read the MP contents and synchronize the observer with the current MP contents...
Definition Array.h:195
NumericArrayBase_(Cpl::Dm::ModelDatabase &myModelBase, const char *symbolicName, ELEMTYPE *myDataPtr, size_t numElements, ELEMTYPE *srcData)
Constructor.
Definition Array.h:163
uint16_t write(const ELEMTYPE *srcArray, size_t srcNumElements, size_t dstIndex=0, Cpl::Dm::ModelPoint::LockRequest_T lockRequest=Cpl::Dm::ModelPoint::eNO_REQUEST) noexcept
Type safe write. See Cpl::Dm::ModelPoint.
Definition Array.h:181
This abstract class defines the Subscriber interface - for change notifications - to a Model Points d...
Definition SubscriberApi.h:34
This template class defines a type safe Subscriber.
Definition Subscriber.h:82
This abstract class defines the operations that can be before on a NULL terminated string.
Definition String.h:40
The 'Cpl' namespace is the root name space for the Colony.
Definition Api16.h:20