FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairXMLNode.h
Go to the documentation of this file.
1 /*
2  * FairXLMNode.h
3  *
4  * Created on: 13 wrz 2017
5  * Author: Daniel Wielanek
6  * E-mail: daniel.wielanek@gmail.com
7  * Warsaw University of Technology, Faculty of Physics
8  */
9 #ifndef FAIRXLMNODE_H_
10 #define FAIRXLMNODE_H_
11 
12 #include <Rtypes.h>
13 #include <TList.h>
14 #include <TNamed.h>
15 #include <TObject.h>
16 #include <TString.h>
17 #include <TXMLEngine.h>
18 #include <memory>
19 
20 class TXMLNode;
21 
25 class FairXMLAttrib : public TNamed
26 {
27  public:
32  : TNamed()
33  {}
39  FairXMLAttrib(TString name, TString value)
40  {
41  SetName(name);
42  SetTitle(value);
43  }
48  TString GetValue() const { return GetTitle(); };
53  void SetValue(TString val) { SetTitle(val); };
54  virtual ~FairXMLAttrib(){};
56 };
60 class FairXMLNode : public TNamed
61 {
62  TList fChildren;
63  TList fAttrib;
64 
65  public:
70  FairXMLNode(const FairXMLNode &other);
76  FairXMLNode(TString name = "", TString value = "");
82  FairXMLNode &operator=(const FairXMLNode &other);
87  void Copy(TXMLNode *node);
92  void SetValue(TString value) { SetTitle(value); };
98  void AddChild(FairXMLNode *node) { fChildren.AddLast(node); };
103  void AddAttrib(FairXMLAttrib *attrib);
108  Int_t GetNChildren() const { return fChildren.GetEntries(); };
113  Int_t GetNAttributes() const { return fAttrib.GetEntries(); };
119  Int_t GetNChildren(TString name) const;
124  TString GetValue() const { return GetTitle(); };
130  FairXMLAttrib *GetAttrib(TString name) const;
136  FairXMLAttrib *GetAttrib(Int_t index) const;
143  FairXMLNode *GetChild(TString name, Int_t count = 0) const;
149  FairXMLNode *GetChild(Int_t index) const;
150  virtual ~FairXMLNode();
151  ClassDef(FairXMLNode, 1);
152 };
153 
157 class FairXMLFile : public TObject
158 {
159  std::unique_ptr<FairXMLNode> fRootNode;
160  TString fName;
161  Bool_t fOverwrite;
162  void ExportNode(XMLNodePointer_t &nodePointer, TXMLEngine &engine, const FairXMLNode &node) const;
163 
164  public:
170  FairXMLFile(TString name = "", TString mode = "read");
175  void CreateRootNode(TString name);
180  void SetRootNode(FairXMLNode *node);
185  FairXMLNode *GetRootNode() const { return fRootNode.get(); };
189  void Close();
193  virtual ~FairXMLFile();
194  ClassDef(FairXMLFile, 1);
195 };
196 
197 #endif /* FAIRXLMNODE_H_ */
Int_t GetNChildren() const
Definition: FairXMLNode.h:108
FairXMLNode * GetRootNode() const
Definition: FairXMLNode.h:185
Int_t GetNAttributes() const
Definition: FairXMLNode.h:113
ClassDef(FairXMLAttrib, 1)
TString GetValue() const
Definition: FairXMLNode.h:48
FairXMLFile(TString name="", TString mode="read")
FairXMLNode(const FairXMLNode &other)
Definition: FairXMLNode.cxx:26
FairXMLAttrib * GetAttrib(TString name) const
void Copy(TXMLNode *node)
Definition: FairXMLNode.cxx:54
TString GetValue() const
Definition: FairXMLNode.h:124
void SetValue(TString val)
Definition: FairXMLNode.h:53
FairXMLNode & operator=(const FairXMLNode &other)
Definition: FairXMLNode.cxx:37
void SetRootNode(FairXMLNode *node)
void AddChild(FairXMLNode *node)
Definition: FairXMLNode.h:98
virtual ~FairXMLAttrib()
Definition: FairXMLNode.h:54
FairXMLNode * GetChild(TString name, Int_t count=0) const
FairXMLAttrib(TString name, TString value)
Definition: FairXMLNode.h:39
void SetValue(TString value)
Definition: FairXMLNode.h:92
virtual ~FairXMLNode()
void CreateRootNode(TString name)
virtual ~FairXMLFile()
void AddAttrib(FairXMLAttrib *attrib)
Definition: FairXMLNode.cxx:84
ClassDef(FairXMLNode, 1)
ClassDef(FairXMLFile, 1)