Jpp  master_rocky-43-ge265d140c
the software that should make you happy
Friends | List of all members
JDATABASE::JSonHelper< T > Struct Template Reference

Auxiliary base class for JSon I/O based on ROOT dictionary. More...

#include <JSonSupportkit.hh>

Friends

void to_json (json &js, const T &object)
 Convert object to JSon. More...
 
void from_json (const json &js, T &object)
 Convert JSon to object/. More...
 

Detailed Description

template<class T>
struct JDATABASE::JSonHelper< T >

Auxiliary base class for JSon I/O based on ROOT dictionary.

Definition at line 164 of file JSonSupportkit.hh.

Friends And Related Function Documentation

◆ to_json

template<class T >
void to_json ( json js,
const T &  object 
)
friend

Convert object to JSon.

Parameters
jsjson
objectobject

Definition at line 171 of file JSonSupportkit.hh.

172  {
173  using namespace std;
174  using namespace JPP;
175 
176  JRootWritableClass cls(object);
177 
178  for (unique_ptr<TIterator> i(cls.getClass()->GetListOfDataMembers()->MakeIterator()); const TDataMember* p = (const TDataMember*) i->Next(); ) {
179 
180  if (!JRootClass::is_static(*p)) {
181 
182  JRootWritableClass abc = cls.get(*p);
183 
184  JSonDictionary::getInstance()[abc.getTypename()]->to_json(js[p->GetName()], abc.getAddress());
185  }
186  }
187  }
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14
static data_type & getInstance()
Get unique instance of template class.
Definition: JSingleton.hh:27
pointer_type getAddress() const
Get address.
Definition: JRootClass.hh:460
JRootAddressableClass get(const TDataMember &data_member) const
Get addressable class of given data member.
Definition: JRootClass.hh:495
const char * getTypename() const
Get type name.
Definition: JRootClass.hh:205
ROOT class for writing object.
Definition: JRootClass.hh:604

◆ from_json

template<class T >
void from_json ( const json js,
T &  object 
)
friend

Convert JSon to object/.

Parameters
jsjson
objectobject

Definition at line 196 of file JSonSupportkit.hh.

197  {
198  using namespace std;
199  using namespace JPP;
200 
201  JRootReadableClass cls(object);
202 
203  for (unique_ptr<TIterator> i(cls.getClass()->GetListOfDataMembers()->MakeIterator()); const TDataMember* p = (const TDataMember*) i->Next(); ) {
204 
205  if (!JRootClass::is_static(*p)) {
206 
207  JRootReadableClass abc = cls.get(*p);
208 
209  if (js.contains(p->GetName()))
210  JSonDictionary::getInstance()[abc.getTypename()]->from_json(js[p->GetName()], abc.getAddress());
211  else
212  THROW(JParserException, "No key word <" << p->GetName() << "> in " << js);
213  }
214  }
215  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
Exception when parsing a value.
Definition: JException.hh:558
ROOT class for reading object.
Definition: JRootClass.hh:544

The documentation for this struct was generated from the following file: