ROOT logo
ROOT » IO » XML » TXMLPlayer

class TXMLPlayer: public TObject

 Class for xml code generation
 It should be used for generation of xml steramers, which could be used outside root
 enviroment. This means, that with help of such streamers user can read and write
 objects from/to xml file, which later can be accepted by ROOT.

 At the moment supported only classes, which are not inherited from TObject
 and which not contains any TObject members.

 To generate xml code:

 1. ROOT library with required classes should be created.
    In general, without such library non of user objects can be stored and
    retrived from any ROOT file

 2. Generate xml streamers by root script like:

    void generate() {
      gSystem->Load("");   // load ROOT xml library
      gSystem->Load("");   // load user ROOT library

      TList lst;

      TXMLPlayer player;
      player.ProduceCode(&lst, "streamers");    // create xml streamers

  3. Copy "streamers.h", "streamers.cxx", "TXmlFile.h", "TXmlFile.cxx" files
     to user project and compile them. TXmlFile class implementation can be taken

 TXMLPlayer class generates one function per class, which called class streamer.
 Name of such function for class TExample will be TExample_streamer.

 Following data members for streamed classes are supported:
  - simple data types (int, double, float)
  - array of simple types (int[5], double[5][6])
  - dynamic array of simple types (int* with comment field // [fSize])
  - const char*
  - object of any nonROOT class
  - pointer on object
  - array of objects
  - array of pointers on objects
  - stl string
  - stl vector, list, deque, set, multiset, map, multimap
  - allowed arguments for stl containers are: simple data types, string, object, pointer on object
  Any other data member can not be (yet) read from xml file and write to xml file.

 If data member of class is private or protected, it can not be accessed via
 member name. Two alternative way is supported. First, if for class member fValue
 exists function GetValue(), it will be used to get value from the class, and if
 exists SetValue(), it will be used to set apropriate data member. Names of setter
 and getter methods can be specified in comments filed like:

     int  fValue;   // *OPTION={GetMethod="GetV";SetMethod="SetV"}

 If getter or setter methods does not available, address to data member will be
 calculated as predefined offeset to object start address. In that case generated code
 should be used only on the same platform (OS + compiler), where it was generated.

 Generated streamers resolve inheritance tree for given class. This allows to have
 array (or vector) of object pointers on some basic class, while objects of derived
 class(es) are used.

 To access data from xml files, user should use TXmlFile class, which is different from
 ROOT TXMLFile, but provides very similar functionality. For example, to read
 object from xml file:

        TXmlFile file("test.xml");             // open xml file;                             // show list of keys in file
        TExample* ex1 = (TExample*) file.Get("ex1", TExample_streamer); // get object

 To write object to file:

        TXmlFile outfile("test2.xml", "recreate");    // create xml file
        TExample* ex1 = new TExample;
        outfile.Write(ex1, "ex1", TExample_streamer);   // write object to file

 Complete example for generating and using of external xml streamers can be taken from

 Any bug reports and requests for additional functionality are welcome.

 Sergey Linev,

Function Members (Methods)

TXMLPlayer(const TXMLPlayer&)
voidTObject::AbstractMethod(const char* method) const
virtual voidTObject::AppendPad(Option_t* option = "")
virtual voidTObject::Browse(TBrowser* b)
static TClass*Class()
virtual const char*TObject::ClassName() const
virtual voidTObject::Clear(Option_t* = "")
virtual TObject*TObject::Clone(const char* newname = "") const
virtual Int_tTObject::Compare(const TObject* obj) const
virtual voidTObject::Copy(TObject& object) const
virtual voidTObject::Delete(Option_t* option = "")MENU
virtual Int_tTObject::DistancetoPrimitive(Int_t px, Int_t py)
virtual voidTObject::Draw(Option_t* option = "")
virtual voidTObject::DrawClass() constMENU
virtual TObject*TObject::DrawClone(Option_t* option = "") constMENU
virtual voidTObject::Dump() constMENU
virtual voidTObject::Error(const char* method, const char* msgfmt) const
virtual voidTObject::Execute(const char* method, const char* params, Int_t* error = 0)
virtual voidTObject::Execute(TMethod* method, TObjArray* params, Int_t* error = 0)
virtual voidTObject::ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual voidTObject::Fatal(const char* method, const char* msgfmt) const
virtual TObject*TObject::FindObject(const char* name) const
virtual TObject*TObject::FindObject(const TObject* obj) const
virtual Option_t*TObject::GetDrawOption() const
static Long_tTObject::GetDtorOnly()
virtual const char*TObject::GetIconName() const
virtual const char*TObject::GetName() const
virtual char*TObject::GetObjectInfo(Int_t px, Int_t py) const
static Bool_tTObject::GetObjectStat()
virtual Option_t*TObject::GetOption() const
virtual const char*TObject::GetTitle() const
virtual UInt_tTObject::GetUniqueID() const
virtual Bool_tTObject::HandleTimer(TTimer* timer)
virtual ULong_tTObject::Hash() const
virtual voidTObject::Info(const char* method, const char* msgfmt) const
virtual Bool_tTObject::InheritsFrom(const char* classname) const
virtual Bool_tTObject::InheritsFrom(const TClass* cl) const
virtual voidTObject::Inspect() constMENU
voidTObject::InvertBit(UInt_t f)
virtual TClass*IsA() const
virtual Bool_tTObject::IsEqual(const TObject* obj) const
virtual Bool_tTObject::IsFolder() const
Bool_tTObject::IsOnHeap() const
virtual Bool_tTObject::IsSortable() const
Bool_tTObject::IsZombie() const
virtual voidTObject::ls(Option_t* option = "") const
voidTObject::MayNotUse(const char* method) const
virtual Bool_tTObject::Notify()
static voidTObject::operator delete(void* ptr)
static voidTObject::operator delete(void* ptr, void* vp)
static voidTObject::operator delete[](void* ptr)
static voidTObject::operator delete[](void* ptr, void* vp)
void*TObject::operator new(size_t sz)
void*TObject::operator new(size_t sz, void* vp)
void*TObject::operator new[](size_t sz)
void*TObject::operator new[](size_t sz, void* vp)
TXMLPlayer&operator=(const TXMLPlayer&)
virtual voidTObject::Paint(Option_t* option = "")
virtual voidTObject::Pop()
virtual voidTObject::Print(Option_t* option = "") const
Bool_tProduceCode(TList* cllist, const char* filename)
virtual Int_tTObject::Read(const char* name)
virtual voidTObject::RecursiveRemove(TObject* obj)
voidTObject::ResetBit(UInt_t f)
virtual voidTObject::SaveAs(const char* filename = "", Option_t* option = "") constMENU
virtual voidTObject::SavePrimitive(basic_ostream<char,char_traits<char> >& out, Option_t* option = "")
voidTObject::SetBit(UInt_t f)
voidTObject::SetBit(UInt_t f, Bool_t set)
virtual voidTObject::SetDrawOption(Option_t* option = "")MENU
static voidTObject::SetDtorOnly(void* obj)
static voidTObject::SetObjectStat(Bool_t stat)
virtual voidTObject::SetUniqueID(UInt_t uid)
virtual voidShowMembers(TMemberInspector& insp, char* parent)
virtual voidStreamer(TBuffer& b)
voidStreamerNVirtual(TBuffer& b)
virtual voidTObject::SysError(const char* method, const char* msgfmt) const
Bool_tTObject::TestBit(UInt_t f) const
Int_tTObject::TestBits(UInt_t f) const
virtual voidTObject::UseCurrentStyle()
virtual voidTObject::Warning(const char* method, const char* msgfmt) const
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0)
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const
virtual voidTObject::DoError(int level, const char* location, const char* fmt, va_list va) const
const char*ElementGetter(TClass* cl, const char* membername, int specials = 0)
const char*ElementSetter(TClass* cl, const char* membername, char* endch)
TStringGetBasicTypeName(TStreamerElement* el)
TStringGetBasicTypeReaderMethodName(Int_t type, const char* realname)
TStringGetMemberTypeName(TDataMember* member)
TStringGetStreamerName(TClass* cl)
Bool_tProduceSTLstreamer(ostream& fs, TClass* cl, TStreamerSTL* el, Bool_t isWriting)
voidProduceStreamerSource(ostream& fs, TClass* cl, TList* cllist)
voidReadSTLarg(ostream& fs, TString& argname, int argtyp, Bool_t isargptr, TClass* argcl, TString& tname, TString& ifcond)
voidWriteSTLarg(ostream& fs, const char* accname, int argtyp, Bool_t isargptr, TClass* argcl)

Data Members

TStringfGetterName! buffer for name of getter method
TStringfSetterName! buffer for name of setter method
TXMLSetupfXmlSetup! buffer for xml names convertion

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

 default constructor
 destructor of TXMLPlayer object
TString GetStreamerName(TClass* cl)
 returns streamer function name for given class
Bool_t ProduceCode(TList* cllist, const char* filename)
 Produce streamers for provide class list
 TList should include list of classes, for which code should be generated.
 filename specify name of file (without extension), where streamers should be
 created. Function produces two files: header file and source file.
 For instance, if filename is "streamers", files "streamers.h" and "streamers.cxx"
 will be created.
TString GetMemberTypeName(TDataMember* member)
 returns name of simple data type for given data member
TString GetBasicTypeName(TStreamerElement* el)
 return simple data types for given TStreamerElement object
TString GetBasicTypeReaderMethodName(Int_t type, const char* realname)
 return functions name to read simple data type from xml file
const char* ElementGetter(TClass* cl, const char* membername, int specials = 0)
 produce code to access member of given class.
 Parameter specials has following meaning:
    0 - nothing special
    1 - cast to data type
    2 - produce pointer on given member
    3 - skip casting when produce pointer by buf.P() function
const char* ElementSetter(TClass* cl, const char* membername, char* endch)
 Produce code to set value to given data member.
 endch should be output after value is specified.
void ProduceStreamerSource(ostream& fs, TClass* cl, TList* cllist)
 Produce source code of streamer function for specified class
void ReadSTLarg(ostream& fs, TString& argname, int argtyp, Bool_t isargptr, TClass* argcl, TString& tname, TString& ifcond)
 Produce code to read argument of stl container from xml file
void WriteSTLarg(ostream& fs, const char* accname, int argtyp, Bool_t isargptr, TClass* argcl)
 Produce code to write argument of stl container to xml file
Bool_t ProduceSTLstreamer(ostream& fs, TClass* cl, TStreamerSTL* el, Bool_t isWriting)
 Produce code of xml streamer for data member of stl type