1
0
Fork 0
WhisperCom/include/Whisper/Payload.hpp

65 lines
1.3 KiB
C++

#pragma once
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
/** @file */
/** @copyright 2021 MPLv2 */
#include <Tree/tree.hpp>
#include <string>
#include <cstdint>
//#define DEFINE_TYPE_NAME(type, name) template<> Whisper::PayloadType GetType<type>(){return name;}
/**
* @brief This is the main namespace for all whisper-com related datatypes and classed.
*/
namespace Whisper
{
enum class PayloadType : std::uint8_t
{
UINT8,
UINT16,
UINT32,
UINT64,
INT8,
INT16,
INT32,
INT64,
FLOAT,
DOUBLE,
STRING,
PAYLOAD
};
template<typename T> Whisper::PayloadType GetType();
template<typename T>
class Payload : public Tree::BaseNode
{
private:
std::string fieldName_;
T value_;
public:
Payload(const std::string field, T value) :
fieldName_(field), value_(value), Tree::BaseNode() {}
Payload(const std::string field) :
fieldName_(field), Tree::BaseNode() {}
Whisper::PayloadType getType() {return Whisper::GetType<T>();}
T getValue() const { return value_;}
std::string getFieldName() const { return fieldName_;}
}; // class Payload
}; // namespace Whisper