OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
JSON.cpp File Reference

Classes

class  ot::intern::JSONManager
 

Namespaces

namespace  ot
 
namespace  ot::intern
 

Macros

#define OT_JSON_checkMemberExists(___object, ___memberName, ___errorAction)   if (!___object.HasMember(___memberName)) { OT_LOG_E("JSON object member \"" + std::string(___memberName) + "\" missing"); ___errorAction; }
 
#define OT_JSON_createMemberIterator(___object, ___memberName, ___iteratorName)   ot::JsonMemberIterator ___iteratorName = ___object.FindMember(___memberName)
 
#define OT_JSON_checkMemberIteratorType(___it, ___memberName, ___memberType, ___errorAction)   if (!___it->value.Is##___memberType()) { OT_LOG_E("JSON object member \"" + std::string(___memberName) + "\" is not a " #___memberType); ___errorAction; }
 
#define OT_JSON_getFromObject(___object, ___memberName, ___memberType, ___errorAction)
 
#define OT_JSON_getListFromObject(___object, ___memberName, ___entryType, ___list, ___errorAction)
 
#define OT_JSON_getArrayFromObject(___object, ___memberName, ___entryType, ___entryTypeJson, ___sizeMember)
 
#define OT_JSON_checkArrayEntry(___array, ___ix, ___entryType, ___errorAction)   if (!_value[_ix].Is##___entryType()) { OT_LOG_E("Array entry \"" + std::to_string(_ix) + "\" is not a " #___entryType); ___errorAction; }
 
#define OT_JSON_getFromArray(___array, ___ix, ___entryType, ___errorAction)
 
#define OT_JSON_getListFromArray(___array, ___ix, ___entryType, ___list, ___errorAction)
 

Detailed Description

Author
Alexander Kuester (alexk95)
Date
November 2023

Macro Definition Documentation

◆ OT_JSON_checkArrayEntry

#define OT_JSON_checkArrayEntry ( ___array,
___ix,
___entryType,
___errorAction )   if (!_value[_ix].Is##___entryType()) { OT_LOG_E("Array entry \"" + std::to_string(_ix) + "\" is not a " #___entryType); ___errorAction; }

◆ OT_JSON_checkMemberExists

#define OT_JSON_checkMemberExists ( ___object,
___memberName,
___errorAction )   if (!___object.HasMember(___memberName)) { OT_LOG_E("JSON object member \"" + std::string(___memberName) + "\" missing"); ___errorAction; }

◆ OT_JSON_checkMemberIteratorType

#define OT_JSON_checkMemberIteratorType ( ___it,
___memberName,
___memberType,
___errorAction )   if (!___it->value.Is##___memberType()) { OT_LOG_E("JSON object member \"" + std::string(___memberName) + "\" is not a " #___memberType); ___errorAction; }

◆ OT_JSON_createMemberIterator

#define OT_JSON_createMemberIterator ( ___object,
___memberName,
___iteratorName )   ot::JsonMemberIterator ___iteratorName = ___object.FindMember(___memberName)

◆ OT_JSON_getArrayFromObject

#define OT_JSON_getArrayFromObject ( ___object,
___memberName,
___entryType,
___entryTypeJson,
___sizeMember )
Value:
___entryType* ret = nullptr; \
OT_JSON_checkMemberExists(___object, ___memberName, return ret); \
OT_JSON_createMemberIterator(___object, ___memberName, lclit); \
OT_JSON_checkMemberIteratorType(lclit, ___memberName, Array, return ret); \
___sizeMember = lclit->value.Size(); \
ret = new ___entryType[___sizeMember]; \
for (JsonSizeType i = 0; i < ___sizeMember; i++) { \
if (!lclit->value[i].Is##___entryTypeJson()) { OT_LOG_E("Array entry at index \"" + std::to_string(i) + "\" is not a " #___entryTypeJson); delete[]ret; return ret; } \
ret[i] = lclit->value[i].Get##___entryTypeJson(); \
} \
return ret;
#define OT_LOG_E(___text)
Log a error message according to the service logger configuration.
Definition Logger.h:186

◆ OT_JSON_getFromArray

#define OT_JSON_getFromArray ( ___array,
___ix,
___entryType,
___errorAction )
Value:
OT_JSON_checkArrayEntry(___array, ___ix, ___entryType, ___errorAction); \
return ___array[___ix].Get##___entryType();
#define OT_JSON_checkArrayEntry(___array, ___ix, ___entryType, ___errorAction)
Definition JSON.cpp:47

◆ OT_JSON_getFromObject

#define OT_JSON_getFromObject ( ___object,
___memberName,
___memberType,
___errorAction )
Value:
OT_JSON_checkMemberExists(___object, ___memberName, ___errorAction); \
OT_JSON_createMemberIterator(___object, ___memberName, lclit); \
OT_JSON_checkMemberIteratorType(lclit, ___memberName, ___memberType, ___errorAction); \
return lclit->value.Get##___memberType();
#define OT_JSON_checkMemberExists(___object, ___memberName, ___errorAction)
Definition JSON.cpp:12

◆ OT_JSON_getListFromArray

#define OT_JSON_getListFromArray ( ___array,
___ix,
___entryType,
___list,
___errorAction )
Value:
OT_JSON_checkArrayEntry(___array, ___ix, Array, ___errorAction); \
ot::ConstJsonArray it = ___array[___ix].Get##Array(); \
for (rapidjson::SizeType i = 0; i < it.Size(); i++) { \
___list.push_back(it[i].Get##___entryType()); \
} \
return ___list;
rapidjson::GenericArray< true, rapidjson::GenericValue< rapidjson::UTF8<>, rapidjson::MemoryPoolAllocator< rapidjson::CrtAllocator > > > ConstJsonArray
Read only JSON Array.
Definition JSON.h:42

◆ OT_JSON_getListFromObject

#define OT_JSON_getListFromObject ( ___object,
___memberName,
___entryType,
___list,
___errorAction )
Value:
OT_JSON_checkMemberExists(___object, ___memberName, ___errorAction); \
OT_JSON_createMemberIterator(___object, ___memberName, lclit); \
OT_JSON_checkMemberIteratorType(lclit, ___memberName, Array, ___errorAction); \
for (rapidjson::SizeType i = 0; i < lclit->value.Size(); i++) { \
if (!lclit->value[i].Is##___entryType()) { OT_LOG_E("Array entry at index \"" + std::to_string(i) + "\" is not a " #___entryType); ___errorAction; } \
___list.push_back(lclit->value[i].Get##___entryType()); \
} \
return ___list