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;
201 fContainer =
dynamic_cast< XContainerType*
>(element);
220 if(fContainer !=
nullptr)
227 XContainerType* fContainer;
239 std::string class_name = MHO_ClassIdentity::ClassName< XCheckType >();
240 std::string class_uuid = MHO_ClassIdentity::GetUUIDFromClass< XCheckType >().as_string();
241 fJSON[
"class_name"] = class_name;
242 fJSON[
"class_uuid"] = class_uuid;
256 template<
typename XCheckType = XContainerType >
257 typename std::enable_if< std::is_base_of< MHO_ScalarContainerBase, XCheckType >::value,
void >::type
261 std::string class_name = MHO_ClassIdentity::ClassName< XContainerType >();
262 std::string class_uuid = MHO_ClassIdentity::GetUUIDFromClass< XContainerType >().as_string();
263 if(
fLOD >= eJSONBasic)
265 fJSON[
"class_name"] = class_name;
266 fJSON[
"class_uuid"] = class_uuid;
267 fJSON[
"rank"] = fContainer->GetRank();
268 fJSON[
"total_size"] = fContainer->GetSize();
271 if(
fLOD >= eJSONTags)
276 fJSON[
"tags"] = jtags;
300 template<
typename XCheckType = XContainerType >
301 typename std::enable_if< (std::is_base_of< MHO_VectorContainerBase, XCheckType >::value &&
302 !std::is_base_of< MHO_AxisBase, XCheckType >::value),
307 std::string class_name = MHO_ClassIdentity::ClassName< XContainerType >();
308 std::string class_uuid = MHO_ClassIdentity::GetUUIDFromClass< XContainerType >().as_string();
309 if(
fLOD >= eJSONBasic)
311 fJSON[
"class_name"] = class_name;
312 fJSON[
"class_uuid"] = class_uuid;
313 fJSON[
"rank"] = fContainer->GetRank();
314 fJSON[
"total_size"] = fContainer->GetSize();
315 fJSON[
"dimensions"] = fContainer->GetDimensionArray();
318 if(
fLOD >= eJSONTags)
323 fJSON[
"tags"] = jtags;
330 for(
auto it = fContainer->cbegin(); it != fContainer->cend(); it++)
338 std::size_t elem_size =
sizeof(
typename XContainerType::value_type);
339 std::size_t n_elem = fContainer->GetSize();
340 fRank = XContainerType::rank::value;
342 fRawData =
reinterpret_cast< const char*
>(fContainer->GetData());
352 template<
typename XCheckType = XContainerType >
353 typename std::enable_if< std::is_base_of< MHO_AxisBase, XCheckType >::value,
void >::type
357 std::string class_name = MHO_ClassIdentity::ClassName< XContainerType >();
358 std::string class_uuid = MHO_ClassIdentity::GetUUIDFromClass< XContainerType >().as_string();
359 if(
fLOD >= eJSONBasic)
361 fJSON[
"class_name"] = class_name;
362 fJSON[
"class_uuid"] = class_uuid;
363 fJSON[
"rank"] = fContainer->GetRank();
364 fJSON[
"total_size"] = fContainer->GetSize();
365 fJSON[
"dimensions"] = fContainer->GetDimensionArray();
368 if(
fLOD >= eJSONTags)
373 fJSON[
"tags"] = jtags;
380 for(
auto it = fContainer->cbegin(); it != fContainer->cend(); it++)
388 std::size_t elem_size =
sizeof(
typename XContainerType::value_type);
389 std::size_t n_elem = fContainer->GetSize();
390 fRank = XContainerType::rank::value;
392 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++)
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:195
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:304
MHO_ContainerJSONConverter(MHO_ExtensibleElement *element)
Definition: MHO_ContainerJSONConverter.hh:199
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:354
virtual void SetObjectToConvert(MHO_Serializable *obj)
Setter for object to convert.
Definition: MHO_ContainerJSONConverter.hh:212
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:197
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:258
virtual void ConstructJSONRepresentation()
Constructs a JSON representation if fContainer is not nullptr.
Definition: MHO_ContainerJSONConverter.hh:218
virtual ~MHO_ContainerJSONConverter()
Definition: MHO_ContainerJSONConverter.hh:204
void ConstructJSON(const XCheckType *obj)
Constructs a JSON representation for an object of type XCheckType (unspecialized template doesn't do ...
Definition: MHO_ContainerJSONConverter.hh:236
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:156
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:113
mho_json fJSON
Definition: MHO_ContainerJSONConverter.hh:182
std::size_t fRawByteSize
Definition: MHO_ContainerJSONConverter.hh:186
const char * fRawData
Definition: MHO_ContainerJSONConverter.hh:187
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:144
std::string GetRawDataDescriptor() const
Getter for raw data descriptor.
Definition: MHO_ContainerJSONConverter.hh:134
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:185
std::size_t GetRawByteSize() const
Getter for raw byte size.
Definition: MHO_ContainerJSONConverter.hh:120
std::string fRawDataDescriptor
Definition: MHO_ContainerJSONConverter.hh:188
mho_json * GetJSON()
Getter for json.
Definition: MHO_ContainerJSONConverter.hh:93
const char * GetRawData() const
Getter for raw data.
Definition: MHO_ContainerJSONConverter.hh:127
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:178
virtual ~MHO_JSONConverter()
Definition: MHO_ContainerJSONConverter.hh:79
int fLOD
Definition: MHO_ContainerJSONConverter.hh:181
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:167
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_AdhocFlagging.hh:18
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