1 #ifndef MHO_ContainerJSONConverter_HH__
2 #define MHO_ContainerJSONConverter_HH__
55 using hops::eJSONBasic;
56 using hops::eJSONTags;
57 using hops::eJSONWithAxes;
58 using hops::eJSONWithLabels;
200 fContainer =
dynamic_cast< XContainerType*
>(element);
219 if(fContainer !=
nullptr)
226 XContainerType* fContainer;
238 std::string class_name = MHO_ClassIdentity::ClassName< XCheckType >();
239 std::string class_uuid = MHO_ClassIdentity::GetUUIDFromClass< XCheckType >().as_string();
240 fJSON[
"class_name"] = class_name;
241 fJSON[
"class_uuid"] = class_uuid;
255 template<
typename XCheckType = XContainerType >
256 typename std::enable_if< std::is_base_of< MHO_ScalarContainerBase, XCheckType >::value,
void >::type
260 std::string class_name = MHO_ClassIdentity::ClassName< XContainerType >();
261 std::string class_uuid = MHO_ClassIdentity::GetUUIDFromClass< XContainerType >().as_string();
262 if(
fLOD >= eJSONBasic)
264 fJSON[
"class_name"] = class_name;
265 fJSON[
"class_uuid"] = class_uuid;
266 fJSON[
"rank"] = fContainer->GetRank();
267 fJSON[
"total_size"] = fContainer->GetSize();
270 if(
fLOD >= eJSONTags)
275 fJSON[
"tags"] = jtags;
283 fJSON[
"data"] = data;
299 template<
typename XCheckType = XContainerType >
300 typename std::enable_if< (std::is_base_of< MHO_VectorContainerBase, XCheckType >::value &&
301 !std::is_base_of< MHO_AxisBase, XCheckType >::value),
306 std::string class_name = MHO_ClassIdentity::ClassName< XContainerType >();
307 std::string class_uuid = MHO_ClassIdentity::GetUUIDFromClass< XContainerType >().as_string();
308 if(
fLOD >= eJSONBasic)
310 fJSON[
"class_name"] = class_name;
311 fJSON[
"class_uuid"] = class_uuid;
312 fJSON[
"rank"] = fContainer->GetRank();
313 fJSON[
"total_size"] = fContainer->GetSize();
314 fJSON[
"dimensions"] = fContainer->GetDimensionArray();
317 if(
fLOD >= eJSONTags)
322 fJSON[
"tags"] = jtags;
329 for(
auto it = fContainer->cbegin(); it != fContainer->cend(); it++)
333 fJSON[
"data"] = data;
337 std::size_t elem_size =
sizeof(
typename XContainerType::value_type);
338 std::size_t n_elem = fContainer->GetSize();
339 fRank = XContainerType::rank::value;
341 fRawData =
reinterpret_cast<const char*
>( fContainer->GetData() );
351 template<
typename XCheckType = XContainerType >
352 typename std::enable_if< std::is_base_of< MHO_AxisBase, XCheckType >::value,
void >::type
356 std::string class_name = MHO_ClassIdentity::ClassName< XContainerType >();
357 std::string class_uuid = MHO_ClassIdentity::GetUUIDFromClass< XContainerType >().as_string();
358 if(
fLOD >= eJSONBasic)
360 fJSON[
"class_name"] = class_name;
361 fJSON[
"class_uuid"] = class_uuid;
362 fJSON[
"rank"] = fContainer->GetRank();
363 fJSON[
"total_size"] = fContainer->GetSize();
364 fJSON[
"dimensions"] = fContainer->GetDimensionArray();
367 if(
fLOD >= eJSONTags)
372 fJSON[
"tags"] = jtags;
379 for(
auto it = fContainer->cbegin(); it != fContainer->cend(); it++)
383 fJSON[
"data"] = data;
387 std::size_t elem_size =
sizeof(
typename XContainerType::value_type);
388 std::size_t n_elem = fContainer->GetSize();
389 fRank = XContainerType::rank::value;
391 fRawData =
reinterpret_cast<const char*
>( fContainer->GetData() );
402 template<
typename XCheckType = XContainerType >
403 typename std::enable_if< std::is_base_of< MHO_TableContainerBase, XCheckType >::value,
void >::type
407 std::string class_name = MHO_ClassIdentity::ClassName< XContainerType >();
408 std::string class_uuid = MHO_ClassIdentity::GetUUIDFromClass< XContainerType >().as_string();
409 if(
fLOD >= eJSONBasic)
411 fJSON[
"class_name"] = class_name;
412 fJSON[
"class_uuid"] = class_uuid;
413 fJSON[
"rank"] = fContainer->GetRank();
414 fJSON[
"total_size"] = fContainer->GetSize();
415 fJSON[
"dimensions"] = fContainer->GetDimensionArray();
416 fJSON[
"strides"] = fContainer->GetStrideArray();
419 if(
fLOD >= eJSONTags)
424 fJSON[
"tags"] = jtags;
431 for(
auto it = fContainer->cbegin(); it != fContainer->cend(); it++)
435 fJSON[
"data"] = data;
438 if(
fLOD >= eJSONWithAxes)
441 for(std::size_t idx = 0; idx < obj->GetRank(); idx++)
444 apply_at< typename XContainerType::axis_pack_tuple_type, AxisDumper >(*obj, idx, axis_dumper);
449 std::size_t elem_size =
sizeof(
typename XContainerType::value_type );
450 std::size_t n_elem = fContainer->GetSize();
451 fRank = XContainerType::rank::value;
453 fRawData =
reinterpret_cast<const char*
>( fContainer->GetData() );
476 std::string class_name = MHO_ClassIdentity::ClassName< XAxisType >();
477 std::string class_uuid = MHO_ClassIdentity::GetUUIDFromClass< XAxisType >().as_string();
478 if(fLOD >= eJSONBasic)
480 j[
"class_name"] = class_name;
481 j[
"class_uuid"] = class_uuid;
482 j[
"rank"] =
axis.GetRank();
483 j[
"total_size"] =
axis.GetSize();
484 j[
"dimensions"] =
axis.GetDimensionArray();
487 if(fLOD >= eJSONTags)
497 for(
auto it =
axis.cbegin(); it !=
axis.cend(); it++)
520 std::stringstream ss;
521 ss <<
"axis_" << fIndex;
522 (*fAxisJSON)[ss.str().c_str()] = j;
561 if(fContainer !=
nullptr)
576 std::string class_name = MHO_ClassIdentity::ClassName< MHO_ObjectTags >();
577 std::string class_uuid = MHO_ClassIdentity::GetUUIDFromClass< MHO_ObjectTags >().as_string();
578 fJSON[
"class_name"] = class_name;
579 fJSON[
"class_uuid"] = class_uuid;
582 for(std::size_t i = 0; i < obj_uuids.size(); i++)
584 fJSON[
"object_uuids"].push_back(obj_uuids[i].as_string());
589 fJSON[
"tags"] = jtags;
598 MHO_ObjectTags* fContainer;
int axis(char *y_axis, char *x_axis)
Definition: axis.c:22
Class AxisDumper - helper class needed to extract MHO_Axis objects from MHO_AxisPack objects inside M...
Definition: MHO_ContainerJSONConverter.hh:461
~AxisDumper()
Definition: MHO_ContainerJSONConverter.hh:464
void SetIndex(std::size_t idx)
Setter for index.
Definition: MHO_ContainerJSONConverter.hh:471
void operator()(const XAxisType &axis)
Definition: MHO_ContainerJSONConverter.hh:473
AxisDumper(mho_json *json_ptr, int level)
Definition: MHO_ContainerJSONConverter.hh:463
Class MHO_ContainerJSONConverter.
Definition: MHO_ContainerJSONConverter.hh:194
std::enable_if<(std::is_base_of< MHO_VectorContainerBase, XCheckType >::value &&!std::is_base_of< MHO_AxisBase, XCheckType >::value), void >::type ConstructJSON(const XContainerType *obj)
Constructs a JSON representation for an XContainerType object (vector specialization (but not an axis...
Definition: MHO_ContainerJSONConverter.hh:303
MHO_ContainerJSONConverter(MHO_ExtensibleElement *element)
Definition: MHO_ContainerJSONConverter.hh:198
std::enable_if< std::is_base_of< MHO_AxisBase, XCheckType >::value, void >::type ConstructJSON(const XContainerType *obj)
Constructs a JSON representation for an XContainerType object (axis specialization)
Definition: MHO_ContainerJSONConverter.hh:353
virtual void SetObjectToConvert(MHO_Serializable *obj)
Setter for object to convert.
Definition: MHO_ContainerJSONConverter.hh:211
std::enable_if< std::is_base_of< MHO_TableContainerBase, XCheckType >::value, void >::type ConstructJSON(const XContainerType *obj)
Constructs a JSON representation for the given XContainerType object (table specialization).
Definition: MHO_ContainerJSONConverter.hh:404
MHO_ContainerJSONConverter()
Definition: MHO_ContainerJSONConverter.hh:196
std::enable_if< std::is_base_of< MHO_ScalarContainerBase, XCheckType >::value, void >::type ConstructJSON(const XContainerType *obj)
Constructs a JSON representation for an XContainerType object (scalar specialization)
Definition: MHO_ContainerJSONConverter.hh:257
virtual void ConstructJSONRepresentation()
Constructs a JSON representation if fContainer is not nullptr.
Definition: MHO_ContainerJSONConverter.hh:217
virtual ~MHO_ContainerJSONConverter()
Definition: MHO_ContainerJSONConverter.hh:203
void ConstructJSON(const XCheckType *obj)
Constructs a JSON representation for an object of type XCheckType (unspecialized template doesn't do ...
Definition: MHO_ContainerJSONConverter.hh:235
Class MHO_ExtensibleElement.
Definition: MHO_ExtensibleElement.hh:60
Class MHO_JSONConverter.
Definition: MHO_ContainerJSONConverter.hh:76
void InsertElement(const std::complex< long double > &value, mho_json &data)
Inserts a complex value into a JSON data array, this is a specialization for complex<> element data i...
Definition: MHO_ContainerJSONConverter.hh:155
std::size_t GetRank() const
Getter for rank, needed for access to raw data in table containers this is a bit of a hack for 'hops2...
Definition: MHO_ContainerJSONConverter.hh:114
mho_json fJSON
Definition: MHO_ContainerJSONConverter.hh:181
std::size_t fRawByteSize
Definition: MHO_ContainerJSONConverter.hh:185
const char * fRawData
Definition: MHO_ContainerJSONConverter.hh:186
virtual void SetObjectToConvert(MHO_Serializable *)=0
Setter for object to convert.
void InsertElement(const XValueType &value, mho_json &data)
Inserts an element into a JSON data list (helper functions for generic data insertion for elements of...
Definition: MHO_ContainerJSONConverter.hh:143
std::string GetRawDataDescriptor() const
Getter for raw data descriptor.
Definition: MHO_ContainerJSONConverter.hh:132
virtual void ConstructJSONRepresentation()=0
Constructs a JSON representation if fContainer is not nullptr.
MHO_JSONConverter()
Definition: MHO_ContainerJSONConverter.hh:78
std::size_t fRank
Definition: MHO_ContainerJSONConverter.hh:184
std::size_t GetRawByteSize() const
Getter for raw byte size.
Definition: MHO_ContainerJSONConverter.hh:120
std::string fRawDataDescriptor
Definition: MHO_ContainerJSONConverter.hh:187
mho_json * GetJSON()
Getter for json.
Definition: MHO_ContainerJSONConverter.hh:93
const char * GetRawData() const
Getter for raw data.
Definition: MHO_ContainerJSONConverter.hh:126
void SetLevelOfDetail(int level)
Setter for level of detail.
Definition: MHO_ContainerJSONConverter.hh:86
void InsertElement(const std::complex< float > &value, mho_json &data)
Inserts a complex float value into the given mho_json data structure.
Definition: MHO_ContainerJSONConverter.hh:177
virtual ~MHO_JSONConverter()
Definition: MHO_ContainerJSONConverter.hh:79
int fLOD
Definition: MHO_ContainerJSONConverter.hh:180
void InsertElement(const std::complex< double > &value, mho_json &data)
Inserts a complex double value into an mho_json data structure.
Definition: MHO_ContainerJSONConverter.hh:166
Class MHO_Serializable.
Definition: MHO_Serializable.hh:26
Class MHO_Taggable.
Definition: MHO_Taggable.hh:26
mho_json GetMetaDataAsJSON() const
Getter for all meta data stored in this object as a json object.
Definition: MHO_Taggable.hh:95
Definition: MHO_ChannelLabeler.hh:17
void FillJSONFromTaggable(const MHO_Taggable *map, mho_json &obj_tags)
Fills a JSON object with metadata from a Taggable map.
Definition: MHO_ContainerJSONConverter.hh:66
MHO_JSONVerbosityLevel
Definition: MHO_ContainerJSONConverter.hh:39
@ eJSONAxesWithLabelsLevel
Definition: MHO_ContainerJSONConverter.hh:43
@ eJSONAxesLevel
Definition: MHO_ContainerJSONConverter.hh:42
@ eJSONAllLevel
Definition: MHO_ContainerJSONConverter.hh:44
@ eJSONBasicLevel
Definition: MHO_ContainerJSONConverter.hh:40
@ eJSONTagsLevel
Definition: MHO_ContainerJSONConverter.hh:41