TDataMember
class description - source file - inheritance tree
public:
TDataMember TDataMember(G__DataMemberInfo* info = 0, TClass* cl = 0)
TDataMember TDataMember(TDataMember&)
virtual void ~TDataMember()
static TClass* Class()
virtual Int_t Compare(const TObject* obj) const
Int_t GetArrayDim() const
const char* GetArrayIndex() const
TClass* GetClass() const
TDataType* GetDataType() const
const char* GetFullTypeName() const
Int_t GetMaxIndex(Int_t dim) const
virtual const char* GetName() const
Int_t GetOffset() const
Int_t GetOffsetCint() const
TList* GetOptions() const
TMethodCall* GetterMethod(TClass* cl = 0)
virtual const char* GetTitle() const
const char* GetTypeName() const
virtual ULong_t Hash() const
virtual TClass* IsA() const
Bool_t IsaPointer() const
Bool_t IsBasic() const
Bool_t IsEnum() const
Bool_t IsPersistent() const
Int_t IsSTLContainer()
virtual Long_t Property() const
TMethodCall* SetterMethod(TClass* cl)
virtual void ShowMembers(TMemberInspector& insp, char* parent)
virtual void Streamer(TBuffer& b)
void StreamerNVirtual(TBuffer& b)
private:
G__DataMemberInfo* fInfo pointer to CINT data member info
TClass* fClass pointer to the class
TDataType* fDataType pointer to data basic type descriptor
TMethodCall* fValueGetter method that returns a value;
TMethodCall* fValueSetter method which sets value;
TList* fOptions list of possible values 0=no restrictions
public:
static const enum TObject:: kObjIsPersistent
static const TDataMember::ESTLType kNone
static const TDataMember::ESTLType kVector
static const TDataMember::ESTLType kList
static const TDataMember::ESTLType kDeque
static const TDataMember::ESTLType kMap
static const TDataMember::ESTLType kMultimap
static const TDataMember::ESTLType kSet
static const TDataMember::ESTLType kMultiset
TDataMember.
All ROOT classes may have RTTI (run time type identification) support
added. The data is stored in so called DICTIONARY (look at TDictionary).
Information about a class is stored in TClass.
This information may be obtained via the CINT api - see class TCint.
TClass has a list of TDataMember objects providing information about all
data members of described class.
/*
*/
TDataMember provides information about name of data member, its type,
and comment field string. It also tries to find the TMethodCall objects
responsible for getting/setting a value of it, and gives you pointers
to these methods. This gives you a unique possibility to access
protected and private (!) data members if only methods for doing that
are defined.
These methods could either be specified in a comment field, or found
out automatically by ROOT: here's an example:
suppose you have a class definition:
/*
class MyClass{
private:
Float_t fX1;
...
public:
void SetX1(Float_t x) {fX1 = x;};
Float_t GetX1() {return fX1;};
...
}
*/
Look at the data member name and method names: a data member name has
a prefix letter (f) and has a base name X1 . The methods for getting and
setting this value have names which consist of string Get/Set and the
same base name. This convention of naming data fields and methods which
access them allows TDataMember find this methods by itself completely
automatically. To make this description complete, one should know,
that names that are automatically recognized may be also:
for data fields: either fXXX or fIsXXX; and for getter function
GetXXX() or IsXXX() [where XXX is base name].
As an example of using it let's analyse a few lines which get and set
a fEditable field in TCanvas:
/*
TCanvas *c = new TCanvas("c"); // create a canvas
TClass *cl = c->IsA(); // get its class description object.
TDataMember *dm = cl->GetDataMember("fEditable"); //This is our data member
TMethodCall *getter = dm->GetterMethod(c); //find a method that gets value!
Long_t l; // declare a storage for this value;
getter->Execute(c,"",l); // Get this Value !!!! It will appear in l !!!
TMethodCall *setter = dm->SetterMethod(c);
setter->Execute(c,"0",); // Set Value 0 !!!
*/
This trick is widely used in ROOT TContextMenu and dialogs for obtaining
current values and put them as initial values in dialog fields.
If you don't want to follow the convention of naming used by ROOT
you still could benefit from Getter/Setter method support: the solution
is to instruct ROOT what the names of these routines are.
The way to do it is putting this information in a comment string to a data
field in your class declaration:
/*
class MyClass{
Int_t mydata; // *OPTIONS={GetMethod="Get";SetMethod="Set"}
...
Int_t Get(){ return mydata;};
void Set(Int_t i){mydata=i;};
}
*/
However, this getting/setting functions are not the only feature of
this class. The next point is providing lists of possible settings
for the concerned data member. The idea is to have a list of possible
options for this data member, with strings identifying them. This
is used in dialogs with parameters to set - for details see
TMethodArg, TRootContextMenu, TContextMenu. This list not only specifies
the allowed value, but also provides strings naming the options.
Options are managed via TList of TOptionListItem objects. This list
is also created automatically: if a data type is an enum type,
the list will have items describing every enum value, and named
according to enum name. If type is Bool_t, two options "On" and "Off"
with values 0 and 1 are created. For other types you need to instruct
ROOT about possible options. The way to do it is the same as in case of
specifying getter/setter method: a comment string to a data field in
Your header file with class definition.
The most general format of this string is:
/*
*OPTIONS={GetMethod="getter";SetMethod="setter";Items=(it1="title1",it2="title2", ... ) }
*/
While parsing this string ROOT firstly looks for command-tokens:
GetMethod, SetMethod, Items; They must be preceded by string
*OPTIONS= , enclosed by {} and separated by semicolons ";".
All command token should have a form TOKEN=VALUE.
All tokens are optional.
The names of getter and setter method must be enclosed by double-quote
marks (") .
Specifications of Items is slightly more complicated: you need to
put token ITEMS= and then enclose all options in curly brackets "()".
You separate options by comas ",".
Each option item may have one of the following forms:
/*
IntegerValue = "Text Label"
EnumValue = "Text Label"
"TextValue" = Text Label"
*/
One can sepcify values as Integers or Enums - when data field is an
Integer, Float or Enum type; as texts - for Text_t (more precisely:
Option_t).
As mentioned above - this information are mainly used by contextmenu,
but also in Dump() and Inspect() methods and by the THtml class.
TDataMember(G__DataMemberInfo *info, TClass *cl) : TDictionary()
Default TDataMember ctor. TDataMembers are constructed in TClass
via a call to TCint::CreateListOfDataMembers(). It parses the comment
string, initializes optionlist and getter/setter methods.
~TDataMember()
TDataMember dtor deletes adopted G__DataMemberInfo object.
Int_t GetArrayDim() const
Return number of array dimensions.
const char* GetArrayIndex() const
If the data member is pointer and has a valid array size in its comments
GetArrayIndex returns a string pointing to it;
otherwise it returns an empty string.
Int_t GetMaxIndex(Int_t dim) const
Return maximum index for array dimension "dim".
const char* GetTypeName() const
Get type of data member, e,g.: "class TDirectory*" -> "TDirectory".
Result needs to be used or copied immediately.
const char* GetFullTypeName() const
Get full type description of data member, e,g.: "class TDirectory*".
const char* GetName() const
Get data member name.
Int_t GetOffset() const
Get offset from "this".
Int_t GetOffsetCint() const
Get offset from "this" using the information in CINT only.
const char* GetTitle() const
Get data member description string (comment).
Int_t Compare(const TObject *obj) const
Compare to other object. Returns 0<, 0 or >0 depending on
whether "this" is lexicographically less than, equal to, or
greater than obj.
ULong_t Hash() const
Return hash value for TDataMember based on its name.
Bool_t IsBasic() const
Return true if data member is a basic type, e.g. char, int, long...
Bool_t IsEnum() const
Return true if data member is an enum.
Bool_t IsaPointer() const
Return true if data member is a pointer.
int IsSTLContainer()
Return which type (if any) of STL container the data member is.
Long_t Property() const
Get property description word. For meaning of bits see EProperty.
TList* GetOptions() const
Returns list of options - list of TOptionListItems
TMethodCall* GetterMethod(TClass *cl)
Return a TMethodCall method responsible for getting the value
of data member. The cl argument specifies the class of the object
which will be used to call this method (in case of multiple
inheritance TMethodCall needs to know this to calculate the proper
offset).
TMethodCall* SetterMethod(TClass *cl)
Return a TMethodCall method responsible for setting the value
of data member. The cl argument specifies the class of the object
which will be used to call this method (in case of multiple
inheritance TMethodCall needs to know this to calculate the proper
offset).
Inline Functions
TClass* GetClass() const
TDataType* GetDataType() const
Bool_t IsPersistent() const
TClass* Class()
TClass* IsA() const
void ShowMembers(TMemberInspector& insp, char* parent)
void Streamer(TBuffer& b)
void StreamerNVirtual(TBuffer& b)
TDataMember TDataMember(TDataMember&)
Author: Fons Rademakers 04/02/95
Last update: root/meta:$Name: $:$Id: TDataMember.cxx,v 1.12 2002/05/23 08:11:35 brun Exp $
Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
ROOT page - Class index - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.