1 #ifndef __JROOT__JROOTCLASS__
2 #define __JROOT__JROOTCLASS__
11 #include <TDictionary.h>
13 #include <TDataMember.h>
14 #include <TBaseClass.h>
15 #include <TIterator.h>
28 namespace JPP {
using namespace JROOT; }
50 static inline bool is_class(
const char*
const name)
52 return (name != NULL &&
53 strcmp(name, TClass ::Class()->GetName()) != 0 &&
54 strcmp(name, TObject::Class()->GetName()) != 0 &&
55 strcmp(name,
"_Rb_tree_node_base") != 0 &&
56 strcmp(name,
"fgIsA") != 0 &&
57 strcmp(name,
"atomic<TClass*>") != 0);
67 static inline bool is_class(
const TBaseClass& base_class)
69 return is_class(base_class.GetName());
79 static inline bool is_class(
const TDataMember& data_member)
81 return is_class(data_member.GetTypeName());
93 return (
const_cast<TBaseClass&
>(base_class).IsSTLContainer() != ROOT::kNotSTL);
105 return (
const_cast<TDataMember&
>(data_member).IsSTLContainer() != ROOT::kNotSTL);
117 return (strcmp(data_member.GetFullTypeName(),
"string") == 0 ||
118 strcmp(data_member.GetFullTypeName(),
"const string") == 0);
128 static inline bool is_static(
const TDataMember& data_member)
130 return (data_member.Property() & kIsStatic);
140 TClass* o_class = TClass::GetClass<TObject>();
141 return o_class->GetListOfRealData()->FindObject(name) !=
nullptr;
148 template<
class JType_t>
150 dictionary(TDictionary::GetDictionary(typeid(JType_t))),
160 template<
class JType_t,
class JClass_t>
162 dictionary(TDictionary::GetDictionary(typeid(JType_t))),
163 offset((char*) &(((JClass_t*) NULL)->*pd) - (char*) NULL)
248 if (name != NULL && strlen(name) != 0) {
258 for (std::unique_ptr<TIterator> i(this->
getClass()->GetListOfDataMembers(kFALSE)->MakeIterator());
const TDataMember* p = (
const TDataMember*) i->Next(); ) {
259 if (( option && strcmp (p->GetName(), name) == 0) ||
260 (!option && strcasecmp(p->GetName(), name) == 0)) {
261 return this->
get(*p);
267 for (std::unique_ptr<TIterator> i(this->
getClass()->GetListOfBases()->MakeIterator()); TBaseClass* p = (TBaseClass*) i->Next(); ) {
273 rcs = rcs.
find(name);
295 return JRootClass(TDictionary::GetDictionary(data_member.GetTypeName()),
296 this->getOffset() + data_member.GetOffset());
308 return JRootClass(TDictionary::GetDictionary(base_class.GetName()),
309 this->getOffset() +
const_cast<TBaseClass&
>(base_class).GetDelta());
318 inline void print(std::ostream& out)
const
358 inline void print(std::ostream& out,
const std::string& prefix)
const
366 if (this->
getClass()->GetListOfBases() != NULL) {
368 for (std::unique_ptr<TIterator> i(this->
getClass()->GetListOfBases()->MakeIterator());
const TBaseClass* p = (
const TBaseClass*) i->Next(); ) {
370 this->
get(*p).
print(out, prefix +
"::" + p->GetName());
372 print(out, prefix +
"::" + p->GetName(), this->get(*p).getTypename());
376 if (this->
getClass()->GetListOfDataMembers(kFALSE) != NULL) {
378 for (std::unique_ptr<TIterator> i(this->
getClass()->GetListOfDataMembers(kFALSE)->MakeIterator());
const TDataMember* p = (
const TDataMember*) i->Next(); ) {
382 print(out, prefix + (
is_static(*p) ?
"::" :
".") + p->GetName(), this->get(*p).getTypename());
397 inline static void print(std::ostream& out,
const std::string& name,
const std::string& type)
401 out << name <<
" " <<
'(' << type <<
')' << endl;
409 template<
class JPo
inter_t>
435 template<
class JPo
inter_t>
521 return this->
find(name);
572 operator const T&()
const
575 return * (
const T*) this->getAddress();
591 return * (T*) this->getAddress();
632 operator const T&()
const
635 return * (
const T*) this->getAddress();
655 for (std::unique_ptr<TIterator> i(parent.
getClass()->GetListOfDataMembers(kFALSE)->MakeIterator());
const TDataMember* p = (
const TDataMember*) i->Next(); ) {
664 for (std::unique_ptr<TIterator> i(parent.
getClass()->GetListOfBases()->MakeIterator());
const TBaseClass* p = (
const TBaseClass*) i->Next(); ) {
687 template<
class JType_t,
class JClass_t>
702 TClass* rc = (TClass*) TDictionary::GetDictionary(
typeid(T));
704 for (std::unique_ptr<TIterator> i(rc->GetListOfDataMembers(kFALSE)->MakeIterator()); TDataMember* p = (TDataMember*) i->Next(); ) {
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Exception for cast operation.
JType< T > getType()
Get type.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for ROOT I/O.
const TDataMember * getDataMember(JType_t JClass_t::*pd)
Get ROOT data member for given C++ data member.
std::vector< TDataMember * > getListOfDataMembers()
Get list of ROOT data members for given class.
Template definition of auxiliary base class for comparison of data structures.
Auxiliary class for a type holder.
JPointer_t pointer_type
Type definition of address.
JAddress(pointer_type p)
Constructor.
Auxiliary class to manage access to base classes and data members of ROOT class objects.
bool is_valid() const
Check validity of this addressable class.
JRootAddressableClass get(const TBaseClass &base_class) const
Get addressable class of given base class.
pointer_type getAddress() const
Get address.
JAddress_t::pointer_type pointer_type
JAddress< JPointer_t > JAddress_t
JRootAddressableClass get(const TDataMember &data_member) const
Get addressable class of given data member.
JRootAddressableClass find(const char *const name) const
Find addressable base class or data member with given name within current class.
JRootAddressableClass operator[](const char *const name) const
Find addressable base class or data member with given name within current class.
JRootAddressableClass(const JRootClass &rc, pointer_type address)
Constructor.
JRootAddressableClass(T &object)
Constructor.
Auxiliary class to manage access to base classes and data members of ROOT class.
static bool is_tobject_member(const char *name)
Check if name is one of TObject own data members (fBits or fUniqueID, for Root <= 6....
JRootClass(const JType< JType_t > &type)
Constructor.
void print(std::ostream &out) const
Print ROOT class information.
TDictionary * dictionary
pointer to ROOT dictionary
JRootClass get(const TBaseClass &base_class) const
Get ROOT class of given base class.
bool is_valid() const
Check validity of this class.
static bool is_STLcontainer(const TDataMember &data_member)
Check if data member is STL container.
JRootClass get(const TDataMember &data_member) const
Get ROOT class of given data member.
static bool is_STLcontainer(const TBaseClass &base_class)
Check if base class is STL container.
JRootClass(JType_t JClass_t::*pd)
Constructor.
JRootClass()
Default constructor.
static bool is_static(const TDataMember &data_member)
Check if data member is static.
void print(std::ostream &out, const std::string &prefix) const
Print ROOT class information.
int getOffset() const
Get offset of this class with respect to parent class.
TClass * getClass() const
Get class.
int offset
offset with respect to data structure [B]
TDictionary * getDictionary() const
Get dictionary.
JRootClass find(const char *const name, const bool option=true) const
Find base class or data member with given name within current class.
static bool is_STLstring(const TDataMember &data_member)
Check if data member is STL string.
static bool is_class(const TDataMember &data_member)
Check data member against ROOT class names.
static void print(std::ostream &out, const std::string &name, const std::string &type)
Print ROOT class information.
static bool is_class(const TBaseClass &base_class)
Check base class against ROOT class names.
const char * getTypename() const
Get type name.
JRootClass(TDictionary *dictionary, int offset)
Constructor.
static bool is_class(const char *const name)
Check name of class against ROOT classes.
bool equals(const JRootClass &object) const
Test equality of ROOT classes.
ROOT class for reading object.
JRootReadableClass(const JRootAddressableClass< char * > &rc)
Copy constructor.
JRootReadableClass(T &object)
Constructor.
ROOT class for writing object.
JRootWritableClass(const JRootAddressableClass< const char * > &rc)
Copy constructor.
JRootWritableClass(const T &object)
Constructor.