REST-for-Physics
v2.3
Rare Event Searches ToolKit for Physics
|
Wrapper class for different type objects
Supports both class objects(string, vector, TRestMetadata, etc.) and basic type objects(int, double, etc.). Implements object wrapping, type assembly, data member reflection, memory streaming, and string conversion. We set a type alias any
for this class.
Example 1: Type assembly & Value assignment
Example 2: Object wrapping & Memory streaming
Example 3: Convert to string
Definition at line 286 of file TRestReflector.h.
Public Member Functions | |
void | Assembly () |
Assembly a new object, and save its address. The old object will be destroied if not null. More... | |
void | Destroy () const |
Destroy the current object. It will make the class to be zombie. More... | |
TRestReflector | GetDataMember (const std::string &name) |
Find the class's datamember as TRestReflector object, including those from base class. More... | |
TRestReflector | GetDataMember (int ID) |
Get the i-th datamember of the class, ignoring those from base class. More... | |
std::string | GetDataMemberValueString (const std::string &name) |
Get the value of datamember as std::string. More... | |
std::vector< std::string > | GetListOfDataMembers () const |
Get a list of the class's datamembers as a std::vector of std::string, including those from base class. More... | |
int | GetNumberOfDataMembers () const |
Get the number of data members of a class. More... | |
template<typename T > | |
T | GetValue () |
Get the value of the wrapped type, not recommended to use. More... | |
template<class T > | |
void | InitFromTemplate () |
bool | IsZombie () const |
If this object type wrapper is invalid. More... | |
template<class T > | |
operator T* () | |
void | operator>> (const TRestReflector &to) |
Deep copy the content of the wrapped object to to . More... | |
void | ParseString (const std::string &str) const |
Set the value of the wrapped object from std::string. More... | |
void | PrintMemory (int bytepreline=16) |
Print the Hex memory std::map of the wrappered object. More... | |
template<class T > | |
void | SetValue (const T &val) |
Set the value of the wrapped type. More... | |
std::string | ToString () const |
Convert the wrapped object to std::string. More... | |
TRestReflector () | |
Default constructor. More... | |
template<class T > | |
TRestReflector (const T &obj) | |
Constructor to wrap an object. Any typed object can be revieved as argument. More... | |
template<class T > | |
TRestReflector (T *obj) | |
Constructor to wrap an object pointer. More... | |
TRestReflector (void *address, const std::string &type) | |
Constructor from a certain address and a certain type. More... | |
Data Fields | |
char * | address = 0 |
Address of the wrapped object. More... | |
TClass * | cl = 0 |
Pointer to the corresponding TClass helper, if the wrapped object is in class type. More... | |
bool | is_data_type = false |
Pointer to the corresponding TDataType helper, if the wrapped object is in data type. More... | |
std::string | name = "" |
Name field. More... | |
int | size = 0 |
Size of the object. More... | |
std::string | type = "" |
Type of the wrapped object. More... | |
const std::type_info * | typeinfo = 0 |
value of typeid(T).name() of the wrapped object More... | |
Private Member Functions | |
int | InitDictionary () |
Prepare the ROOT dictionary for this type. More... | |
Private Attributes | |
bool | onheap = false |
If on heap, we can call Destroy() to TRestReflector. True only when initialized from Assembly() More... | |
Friends | |
std::ostream & | operator<< (std::ostream &cin, TRestReflector ptr) |
Output overload by calling ToString();. More... | |
|
inline |
Default constructor.
Definition at line 364 of file TRestReflector.h.
REST_Reflection::TRestReflector::TRestReflector | ( | void * | address, |
const std::string & | type | ||
) |
Constructor from a certain address and a certain type.
Definition at line 57 of file TRestReflector.cxx.
|
inline |
Constructor to wrap an object. Any typed object can be revieved as argument.
Definition at line 369 of file TRestReflector.h.
|
inline |
Constructor to wrap an object pointer.
Definition at line 375 of file TRestReflector.h.
void REST_Reflection::TRestReflector::Assembly | ( | ) |
Assembly a new object, and save its address. The old object will be destroied if not null.
Definition at line 75 of file TRestReflector.cxx.
void REST_Reflection::TRestReflector::Destroy | ( | ) | const |
Destroy the current object. It will make the class to be zombie.
Definition at line 90 of file TRestReflector.cxx.
TRestReflector REST_Reflection::TRestReflector::GetDataMember | ( | const std::string & | name | ) |
Find the class's datamember as TRestReflector object, including those from base class.
Definition at line 288 of file TRestReflector.cxx.
TRestReflector REST_Reflection::TRestReflector::GetDataMember | ( | int | ID | ) |
Get the i-th datamember of the class, ignoring those from base class.
Definition at line 316 of file TRestReflector.cxx.
string REST_Reflection::TRestReflector::GetDataMemberValueString | ( | const std::string & | name | ) |
Get the value of datamember as std::string.
Definition at line 363 of file TRestReflector.cxx.
vector< string > REST_Reflection::TRestReflector::GetListOfDataMembers | ( | ) | const |
Get a list of the class's datamembers as a std::vector of std::string, including those from base class.
Definition at line 332 of file TRestReflector.cxx.
int REST_Reflection::TRestReflector::GetNumberOfDataMembers | ( | ) | const |
Get the number of data members of a class.
Definition at line 371 of file TRestReflector.cxx.
|
inline |
Get the value of the wrapped type, not recommended to use.
Definition at line 316 of file TRestReflector.h.
|
private |
Prepare the ROOT dictionary for this type.
Definition at line 154 of file TRestReflector.cxx.
|
inline |
Definition at line 381 of file TRestReflector.h.
bool REST_Reflection::TRestReflector::IsZombie | ( | ) | const |
If this object type wrapper is invalid.
Definition at line 256 of file TRestReflector.cxx.
|
inline |
Type conversion operator. With this, one can implicitly convert TRestReflector object to pointer of certain type. For example, TRestEvent* eve = REST_Reflection::Assembly("TRestRawSignalEvent");
Definition at line 360 of file TRestReflector.h.
void REST_Reflection::TRestReflector::operator>> | ( | const TRestReflector & | to | ) |
Deep copy the content of the wrapped object to to
.
Definition at line 124 of file TRestReflector.cxx.
void REST_Reflection::TRestReflector::ParseString | ( | const std::string & | str | ) | const |
Set the value of the wrapped object from std::string.
Definition at line 141 of file TRestReflector.cxx.
void REST_Reflection::TRestReflector::PrintMemory | ( | int | bytepreline = 16 | ) |
Print the Hex memory std::map of the wrappered object.
Definition at line 107 of file TRestReflector.cxx.
|
inline |
Set the value of the wrapped type.
Definition at line 327 of file TRestReflector.h.
string REST_Reflection::TRestReflector::ToString | ( | ) | const |
Convert the wrapped object to std::string.
Definition at line 126 of file TRestReflector.cxx.
|
friend |
Output overload by calling ToString();.
Definition at line 313 of file TRestReflector.h.
char* REST_Reflection::TRestReflector::address = 0 |
Address of the wrapped object.
Definition at line 301 of file TRestReflector.h.
TClass* REST_Reflection::TRestReflector::cl = 0 |
Pointer to the corresponding TClass helper, if the wrapped object is in class type.
Definition at line 305 of file TRestReflector.h.
bool REST_Reflection::TRestReflector::is_data_type = false |
Pointer to the corresponding TDataType helper, if the wrapped object is in data type.
Definition at line 307 of file TRestReflector.h.
std::string REST_Reflection::TRestReflector::name = "" |
Name field.
Definition at line 295 of file TRestReflector.h.
|
private |
If on heap, we can call Destroy() to TRestReflector. True only when initialized from Assembly()
Definition at line 291 of file TRestReflector.h.
int REST_Reflection::TRestReflector::size = 0 |
Size of the object.
Definition at line 303 of file TRestReflector.h.
std::string REST_Reflection::TRestReflector::type = "" |
Type of the wrapped object.
Definition at line 297 of file TRestReflector.h.
const std::type_info* REST_Reflection::TRestReflector::typeinfo = 0 |
value of typeid(T).name() of the wrapped object
Definition at line 299 of file TRestReflector.h.