Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
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.
 
void from_json (const json &js, T &object)
 Convert JSon to object/.
 

Detailed Description

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

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

Definition at line 165 of file JSonSupportkit.hh.

Friends And Related Symbol 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 172 of file JSonSupportkit.hh.

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

◆ from_json

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

Convert JSon to object/.

Parameters
jsjson
objectobject

Definition at line 197 of file JSonSupportkit.hh.

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

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