KPN IoT / senml

Fork of kpn_senml by KPN IoT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers senml_pack_t.h Source File

senml_pack_t.h

00001 /*  _  __  ____    _   _ 
00002  * | |/ / |  _ \  | \ | |
00003  * | ' /  | |_) | |  \| |
00004  * | . \  |  __/  | |\  |
00005  * |_|\_\ |_|     |_| \_|
00006  * 
00007  * (c) 2018 KPN
00008  * License: MIT License.
00009  * Author: Jan Bogaerts
00010  * 
00011  * pack (document) base class for packs that have base values
00012  */
00013 
00014 #ifndef SENMLPACKTEMPLATE
00015 #define SENMLPACKTEMPLATE
00016 
00017 #include <senml_pack.h>
00018 
00019 /**
00020  * A template class that can be used to create new SenMLPack types that store a base-value and/or base-sum 
00021  * with a basic data type (no structs or classes).
00022  * When you create a new class, you should always implement the following functions in order
00023  * for the new class to operate correctly: fieldsToJson() and fieldsToCbor(). These functions are responsible
00024  * for rendering both base-value and base-sum. This class does not implement any rendering.
00025  * See previous implementations such as SenMLIntPack for inspiration.
00026  */ 
00027 template <class T>
00028 class SenMLPackTemplate: public SenMLPack
00029 {
00030     public:
00031 
00032         SenMLPackTemplate(const char* baseName): SenMLPack(baseName, SENML_UNIT_NONE, NAN) {};
00033         SenMLPackTemplate(const char* baseName, SenMLUnit baseUnit): SenMLPack(baseName, baseUnit, NAN) {};
00034         SenMLPackTemplate(const char* baseName, SenMLUnit baseUnit, double baseTime): SenMLPack(baseName, baseUnit, baseTime) {};
00035 
00036         SenMLPackTemplate(PACK_ACTUATOR_SIGNATURE): SenMLPack("", SENML_UNIT_NONE, NAN, callback) {};
00037         SenMLPackTemplate(const char* baseName, PACK_ACTUATOR_SIGNATURE): SenMLPack(baseName, SENML_UNIT_NONE, NAN, callback) {};
00038         SenMLPackTemplate(const char* baseName, SenMLUnit baseUnit, PACK_ACTUATOR_SIGNATURE): SenMLPack(baseName, baseUnit, NAN, callback) {};
00039         SenMLPackTemplate(const char* baseName, SenMLUnit baseUnit, double baseTime, PACK_ACTUATOR_SIGNATURE): SenMLPack(baseName, baseUnit, baseTime, callback){};
00040 
00041 
00042 
00043         ~SenMLPackTemplate(){};
00044 
00045         /**
00046          * Get the base-sum assigned to this pack object.
00047          * @returns: the base-sum.
00048          */
00049         T getBaseSum() {return _sum; } ;
00050 
00051         /**
00052          * Store the base-sum in the pack object.
00053          * @returns: true (returns a value to support possible future extentions)
00054          */
00055         bool setBaseSum(T value) {_sum = value; return true;};
00056 
00057         /**
00058          * Get the base-value assigned to this pack object.
00059          * @returns: the base-value.
00060          */
00061         T getBaseValue() {return _value; } ;
00062 
00063         /**
00064          * Store the base-value in the pack object.
00065          * @returns: true (returns a value to support possible future extentions)
00066          */
00067         bool setBaseValue(T value) {_value = value; return true;};
00068 
00069 protected:
00070 
00071 
00072 private:
00073     T _sum;
00074     T _value;
00075 };
00076 
00077 #endif // SENMLPACKTEMPLATE
00078 
00079 
00080 
00081 
00082 
00083 
00084