library: libXMLIO #include "TXMLPlayer.h"

# TXMLPlayer

class description - source file - inheritance tree (.pdf)

## class TXMLPlayer : public TObject

| Inheritance Chart:
`TObject`
| <- | `TXMLPlayer` |

        protected:

          const char* ElementGetter(TClass* cl, const char* membername, int specials = 0) const
          const char* ElementSetter(TClass* cl, const char* membername, char* endch) const
              TString GetBasicTypeName(TStreamerElement* el)
              TString GetBasicTypeReaderMethodName(Int_t type, const char* realname)
              TString GetMemberTypeName(TDataMember* member)
              TString GetStreamerName(TClass* cl)
                 bool ProduceSTLstreamer(ostream& fs, TClass* cl, TStreamerSTL* el, Bool_t isWriting)
                 void ProduceStreamerSource(ostream& fs, TClass* cl, TList* cllist)
                 void ReadSTLarg(ostream& fs, TString& argname, int argtyp, bool isargptr, TClass* argcl, TString& tname, TString& ifcond)
                 void WriteSTLarg(ostream& fs, const char* accname, int argtyp, bool isargptr, TClass* argcl)

        public:

                          TXMLPlayer()
                          TXMLPlayer(const TXMLPlayer&)
                  virtual ~TXMLPlayer()
           static TClass* Class()
          virtual TClass* IsA() const
              TXMLPlayer& operator=(const TXMLPlayer&)
                   Bool_t ProduceCode(TList* cllist, const char* filename)
             virtual void ShowMembers(TMemberInspector& insp, char* parent)
             virtual void Streamer(TBuffer& b)
                     void StreamerNVirtual(TBuffer& b)

### Data Members

        protected:

            TString fGetterName  !  buffer for name of getter method
            TString fSetterName  !  buffer for name of setter method
          TXMLSetup fXmlSetup    !  buffer for xml names convertion

## Class Description

     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("libRXML.so");   // load ROOT xml library
          gSystem->Load("libuser.so");   // load user ROOT library

          TList lst;
          lst.Add(gROOT->GetClass("TUserClass1"));
          lst.Add(gROOT->GetClass("TUserClass2"));
          ...
          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
         from http://www-linux.gsi.de/~linev/xmlfile.tar.gz

     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
            file.ls();                             // show list of keys in file
            TExample* ex1 = (TExample*) file.Get("ex1", TExample_streamer); // get object
            file.Close();

     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
            outfile.Close();

     Complete example for generating and using of external xml streamers can be taken from
     http://www-linux.gsi.de/~linev/xmlreader.tar.gz

     Any bug reports and requests for additional functionality are welcome.

     Sergey Linev, S.Linev@gsi.de

    ________________________________________________________________________

TXMLPlayer() : TObject()

     default constructor

~TXMLPlayer()

     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)

     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 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 isargptr, TClass* argcl)

     Produce code to write argument of stl container to xml file

bool ProduceSTLstreamer(ostream& fs, TClass* cl, TStreamerSTL* el, Bool_t isWriting)

     Produce code of xml streamer for data member of stl type

### Inline Functions

                TClass* Class()
                TClass* IsA() const
                   void ShowMembers(TMemberInspector& insp, char* parent)
                   void Streamer(TBuffer& b)
                   void StreamerNVirtual(TBuffer& b)
             TXMLPlayer TXMLPlayer(const TXMLPlayer&)
            TXMLPlayer& operator=(const TXMLPlayer&)

Author: Sergey Linev, Rene Brun 10.05.2004
Last update: root/xml:$Name: $:$Id: TXMLPlayer.cxx,v 1.7 2005/02/23 11:46:02 brun Exp $
Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *