Jpp master_rocky-44-g75b7c4f75
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 164 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 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).
static data_type & getInstance()
Get unique instance of template class.
Definition JSingleton.hh:27
pointer_type getAddress() const
Get address.
JRootAddressableClass get(const TDataMember &data_member) const
Get addressable class of given data member.
const char * getTypename() const
Get type name.
ROOT class for writing 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 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.
Exception when parsing a value.
ROOT class for reading object.

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