BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
MpdXMLNode.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 MPDXLMNODE_H
10#define MPDXLMNODE_H
11#include <TList.h>
12#include <TNamed.h>
13#include <TXMLAttr.h>
14#include <TXMLEngine.h>
15#include <TXMLNode.h>
16#include <memory>
17/**
18 * class for representing node attributes
19 */
20class MpdXMLAttrib : public TNamed
21{
22 public:
23 /**
24 * default constructor
25 */
27 : TNamed()
28 {}
29 /**
30 * default constructor
31 * @param name name of attribute
32 * @param value value of attribute
33 */
35 {
36 SetName(name);
37 SetTitle(value);
38 }
39 /**
40 *
41 * @return value of node
42 */
43 TString GetValue() const { return GetTitle(); };
44 /**
45 *
46 * @param val value of node to se
47 */
48 void SetValue(TString val) { SetTitle(val); };
49 virtual ~MpdXMLAttrib() {};
51};
52/**
53 * class for representing XML node
54 */
55class MpdXMLNode : public TNamed
56{
57 TList fChildren;
58 TList fAttrib;
59
60 public:
61 /**
62 * copy constructor
63 * @param other
64 */
65 MpdXMLNode(const MpdXMLNode& other);
66 /**
67 * default constructor
68 * @param name name of node
69 * @param value value of node
70 */
71 MpdXMLNode(TString name = "", TString value = "");
72 /**
73 * assignement operator
74 * @param other
75 * @return
76 */
78 /**
79 * copy data for node to this
80 * @param node
81 */
82 void Copy(TXMLNode* node);
83 /**
84 *
85 * @param value new value
86 */
87 void SetValue(TString value) { SetTitle(value); };
88 /**
89 * add child node to this node, node is now owned by
90 * parent node
91 * @param node node to add
92 */
93 void AddChild(MpdXMLNode* node) { fChildren.AddLast(node); };
94 /**
95 * add attribute to this class
96 * @param attrib
97 */
98 void AddAttrib(MpdXMLAttrib* attrib);
99 /**
100 *
101 * @return number of childen nodes
102 */
103 Int_t GetNChildren() const { return fChildren.GetEntries(); };
104 /**
105 *
106 * @return number of attributes
107 */
108 Int_t GetNAttributes() const { return fAttrib.GetEntries(); };
109 /**
110 * search for child with given name
111 * @param name name of node
112 * @return number of node with given name
113 */
115 /**
116 *
117 * @return value of node
118 */
119 TString GetValue() const { return GetTitle(); };
120 /**
121 *
122 * @param name name of atribute
123 * @return
124 */
126 /**
127 *
128 * @param index index of atrribute
129 * @return
130 */
132 /**
133 * search for node with given name
134 * @param name name of node
135 * @param count number of node (if more than one with given name exist)
136 * @return node
137 */
138 MpdXMLNode* GetChild(TString name, Int_t count = 0) const;
139 /**
140 *
141 * @param index child number
142 * @return child at given position
143 */
144 MpdXMLNode* GetChild(Int_t index) const;
145 virtual ~MpdXMLNode();
147};
148
149/**
150 * class for opening XML files
151 */
152class MpdXMLFile : public TObject
153{
154 std::unique_ptr<MpdXMLNode> fRootNode;
157 void ExportNode(XMLNodePointer_t& nodePointer, TXMLEngine& engine, const MpdXMLNode& node) const;
158
159 public:
160 /**
161 *
162 * @param name name of xml file
163 * @param mode if "READ" or "read" - only read file, otherwise create /overwrite file
164 */
165 MpdXMLFile(TString name = "", TString mode = "read");
166 /**
167 * create new root node
168 * @param name name of new node
169 */
171 /**
172 * set new root node, old node will be overwritten
173 * @param node root node
174 */
176 /**
177 *
178 * @return root node
179 */
180 MpdXMLNode* GetRootNode() const { return fRootNode.get(); };
181 /**
182 * close and write xml (if needed)
183 */
184 void Close();
185 /**
186 * destroy object (and save xml file if needed and Close was not called)
187 */
188 virtual ~MpdXMLFile();
190};
191
192#endif /* MPDXLMNODE_H */
bool Bool_t
int Int_t
#define ClassDef(name, id)
void * XMLNodePointer_t
class for representing node attributes
Definition MpdXMLNode.h:21
MpdXMLAttrib()
default constructor
Definition MpdXMLNode.h:26
MpdXMLAttrib(TString name, TString value)
default constructor
Definition MpdXMLNode.h:34
virtual ~MpdXMLAttrib()
Definition MpdXMLNode.h:49
TString GetValue() const
Definition MpdXMLNode.h:43
void SetValue(TString val)
Definition MpdXMLNode.h:48
class for opening XML files
Definition MpdXMLNode.h:153
void CreateRootNode(TString name)
create new root node
Bool_t fOverwrite
Definition MpdXMLNode.h:156
TString fName
Definition MpdXMLNode.h:155
virtual ~MpdXMLFile()
destroy object (and save xml file if needed and Close was not called)
MpdXMLFile(TString name="", TString mode="read")
std::unique_ptr< MpdXMLNode > fRootNode
Definition MpdXMLNode.h:154
MpdXMLNode * GetRootNode() const
Definition MpdXMLNode.h:180
void SetRootNode(MpdXMLNode *node)
set new root node, old node will be overwritten
void ExportNode(XMLNodePointer_t &nodePointer, TXMLEngine &engine, const MpdXMLNode &node) const
void Close()
close and write xml (if needed)
class for representing XML node
Definition MpdXMLNode.h:56
void AddAttrib(MpdXMLAttrib *attrib)
add attribute to this class
TString GetValue() const
Definition MpdXMLNode.h:119
void Copy(TXMLNode *node)
copy data for node to this
MpdXMLNode & operator=(const MpdXMLNode &other)
assignement operator
virtual ~MpdXMLNode()
Int_t GetNAttributes() const
Definition MpdXMLNode.h:108
MpdXMLNode * GetChild(Int_t index) const
MpdXMLNode * GetChild(TString name, Int_t count=0) const
search for node with given name
void AddChild(MpdXMLNode *node)
add child node to this node, node is now owned by parent node
Definition MpdXMLNode.h:93
MpdXMLAttrib * GetAttrib(TString name) const
Int_t GetNChildren() const
Definition MpdXMLNode.h:103
MpdXMLAttrib * GetAttrib(Int_t index) const
TList fChildren
Definition MpdXMLNode.h:57
Int_t GetNChildren(TString name) const
search for child with given name
MpdXMLNode(const MpdXMLNode &other)
copy constructor
void SetValue(TString value)
Definition MpdXMLNode.h:87
MpdXMLNode(TString name="", TString value="")
default constructor
TList fAttrib
Definition MpdXMLNode.h:58
virtual void SetTitle(const char *title="")
const char * GetTitle() const override
virtual void SetName(const char *name)