123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- /*
- * FairXLMNode.h
- *
- * Created on: 13 wrz 2017
- * Author: Daniel Wielanek
- * E-mail: daniel.wielanek@gmail.com
- * Warsaw University of Technology, Faculty of Physics
- */
- #ifndef MPDXLMNODE_H
- #define MPDXLMNODE_H
- #include <TXMLNode.h>
- #include <TList.h>
- #include <TXMLAttr.h>
- #include <TXMLEngine.h>
- #include <TNamed.h>
- #include <memory>
- /**
- * class for representing node attributes
- */
- class MpdXMLAttrib: public TNamed{
- public :
- /**
- * default constructor
- */
- MpdXMLAttrib():TNamed(){}
- /**
- * default constructor
- * @param name name of attribute
- * @param value value of attribute
- */
- MpdXMLAttrib(TString name, TString value){
- SetName(name);
- SetTitle(value);}
- /**
- *
- * @return value of node
- */
- TString GetValue() const{return GetTitle();};
- /**
- *
- * @param val value of node to se
- */
- void SetValue(TString val){SetTitle(val);};
- virtual ~MpdXMLAttrib(){};
- ClassDef(MpdXMLAttrib,1)
- };
- /**
- * class for representing XML node
- */
- class MpdXMLNode : public TNamed{
- TList fChildren;
- TList fAttrib;
- public:
- /**
- * copy constructor
- * @param other
- */
- MpdXMLNode(const MpdXMLNode &other);
- /**
- * default constructor
- * @param name name of node
- * @param value value of node
- */
- MpdXMLNode(TString name="",TString value="");
- /**
- * assignement operator
- * @param node
- * @return
- */
- MpdXMLNode& operator=(const MpdXMLNode &other);
- /**
- * copy data for node to this
- * @param node
- */
- void Copy(TXMLNode *node);
- /**
- *
- * @param value new value
- */
- void SetValue(TString value){SetTitle(value);};
- /**
- * add child node to this node, node is now owned by
- * parent node
- * @param node node to add
- */
- void AddChild(MpdXMLNode *node){fChildren.AddLast(node);};
- /**
- * add attribute to this class
- * @param attrib
- */
- void AddAttrib(MpdXMLAttrib *attrib);
- /**
- *
- * @return number of childen nodes
- */
- Int_t GetNChildren() const {return fChildren.GetEntries();};
- /**
- *
- * @return number of attributes
- */
- Int_t GetNAttributes() const{return fAttrib.GetEntries();};
- /**
- * search for child with given name
- * @param name name of node
- * @return number of node with given name
- */
- Int_t GetNChildren(TString name) const;
- /**
- *
- * @return value of node
- */
- TString GetValue() const{return GetTitle();};
- /**
- *
- * @param name name of atribute
- * @return
- */
- MpdXMLAttrib *GetAttrib(TString name)const;
- /**
- *
- * @param index index of atrribute
- * @return
- */
- MpdXMLAttrib *GetAttrib(Int_t index)const;
- /**
- * search for node with given name
- * @param name name of node
- * @param count number of node (if more than one with given name exist)
- * @return node
- */
- MpdXMLNode *GetChild(TString name, Int_t count =0) const;
- /**
- *
- * @param index child number
- * @return child at given position
- */
- MpdXMLNode *GetChild(Int_t index) const;
- virtual ~MpdXMLNode();
- ClassDef(MpdXMLNode,1)
- };
- /**
- * class for opening XML files
- */
- class MpdXMLFile: public TObject{
- std::unique_ptr<MpdXMLNode> fRootNode;
- TString fName;
- Bool_t fOverwrite;
- void ExportNode(XMLNodePointer_t &nodePointer, TXMLEngine &engine,const MpdXMLNode &node) const;
- public:
- /**
- *
- * @param name name of xml file
- * @param mode if "READ" or "read" - only read file, otherwise create /overwrite file
- */
- MpdXMLFile(TString name="", TString mode="read");
- /**
- * create new root node
- * @param name name of new node
- */
- void CreateRootNode(TString name);
- /**
- * set new root node, old node will be overwritten
- * @param node root node
- */
- void SetRootNode(MpdXMLNode *node);
- /**
- *
- * @return root node
- */
- MpdXMLNode *GetRootNode()const{return fRootNode.get();};
- /**
- * close and write xml (if needed)
- */
- void Close();
- /**
- * destroy object (and save xml file if needed and Close was not called)
- */
- virtual ~MpdXMLFile();
- ClassDef(MpdXMLFile,1)
- };
- #endif /* MPDXLMNODE_H */
|