KPN Things Device SDK
senml_base.h
Go to the documentation of this file.
1/* _ __ ____ _ _
2 * | |/ / | _ \ | \ | |
3 * | ' / | |_) | | \| |
4 * | . \ | __/ | |\ |
5 * |_|\_\ |_| |_| \_|
6 *
7 * (c) 2020 KPN
8 * License: MIT License.
9 * Author: Joseph Verburg, Jan Bogaerts
10 *
11 * base class for all senml objects header
12 */
13
14#ifndef THINGSML_SENML_BASE
15#define THINGSML_SENML_BASE
16
17#include "defaults.h"
18#include "senml_enums.h"
19#include <math.h>
20
24class SenMLBase {
25 friend class SenMLBasePack;
26 friend class SenMLPack;
27 friend class SenMLSimplePack;
28 friend class SenMLRecord;
29 friend class SenMLJsonListener;
30 friend class SenMLBaseParser;
31
32 public:
33 SenMLBase();
34 ~SenMLBase();
35
40 return this->_next;
41 };
42
49
50 // This function is called by the root SenMLPack object to indicate that the object
51 // should adjust it's time info relative to the new base time (if applicable)
52 // doesn't do anything by default
53 // params: prev: previous base time
54 // time: new base time
55 virtual void adjustToBaseTime(double prev, double time){};
56
64 virtual int fieldsToJson() = 0;
65
74 virtual int fieldsToCbor() = 0;
75
76 protected:
77 /*
78 renders all the fields to json, with the starting and ending brackets.
79 Inheriters can extend this function if they want to add extra fields to the json output
80 note: tihs is public so that custom implementations for the record object can use other objects internally and
81 render to json using this function (ex: coordinatesRecord using 3 floatRecrods for lat, lon & alt.
82 */
83 virtual int contentToJson() = 0;
84
85 // assign the element in the list that this object points to.
86 void setNext(SenMLBase *value);
87
88 // assign the previous element in the list that thisobject points to.
89 void setPrev(SenMLBase *value);
90 // assign the previous element in the list that thisobject points to.
92
93 // derived classes can use this function to see if the root object (getRoot) is a SenMLPack
94 // class or not.
95 virtual bool isPack() {
96 return false;
97 }
98
99 // renders the content of the pack object without [], but still with {} for objects
100 virtual int contentToCbor() = 0;
101
102 // calculates the nr of items that this object will put in the json array in senml representation
103 // this is used for rendering cbor which needs to declare the nr of elements in an array.
104 // packs can have multiple elements in the array, but also custom implementations for records that wrap muliple
105 // records.
106 virtual int getArrayLength() {
107 return 1;
108 };
109
110 // calculates the nr of fields that this object will produce.
111 virtual int getFieldLength() = 0;
112
113 private:
114 SenMLBase *_next; // reference to the next element in the list.
115 SenMLBase *_prev; // reference to the previous element, needed for deletion of record
116};
117
118#endif // THINGSML_SENML_BASE
Definition: senml_base.h:24
~SenMLBase()
Definition: senml_base.cpp:20
void setNext(SenMLBase *value)
Definition: senml_base.cpp:29
virtual int contentToCbor()=0
SenMLBase()
Definition: senml_base.cpp:17
virtual int fieldsToJson()=0
virtual bool isPack()
Definition: senml_base.h:95
SenMLBase * getRoot()
Definition: senml_base.cpp:48
void setPrev(SenMLBase *value)
Definition: senml_base.cpp:40
virtual int fieldsToCbor()=0
SenMLBase * getPrev()
Definition: senml_base.cpp:44
virtual int getFieldLength()=0
virtual void adjustToBaseTime(double prev, double time)
Definition: senml_base.h:55
SenMLBase * getNext()
Definition: senml_base.h:39
virtual int contentToJson()=0
virtual int getArrayLength()
Definition: senml_base.h:106
Definition: senml_basepack.h:24
Definition: senml_base_parser.h:24
Definition: senml_json_parser.h:23
Definition: senml_pack.h:68
Definition: senml_record.h:33
Definition: senml_simplepack.h:19