CustusX  22.04-rc5
An IGT application
cxXMLNodeWrapper.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 #ifndef CXXMLNODEWRAPPER_H
12 #define CXXMLNODEWRAPPER_H
13 
14 #include "cxResourceExport.h"
15 
16 #include <QDomNode>
17 #include <QStringList>
18 #include <vector>
19 
20 namespace cx
21 {
22 
34 class cxResource_EXPORT XMLNodeAdder
35 {
36 public:
37  XMLNodeAdder(QDomNode node);
38 
43  XMLNodeAdder descend(QString path);
44 
45  QDomElement addTextToElement(QString name, QString text);
46 
47  template<class T>
48  void addObjectToElement(QString name, T object)
49  {
50  QDomElement element = this->addElement(name);
51  object->addXml(element);
52  }
53 
54  QDomElement addElement(QString name);
55  QDomNode node();
56 
57 private:
58  QDomNode mNode;
59  QDomDocument document();
60 };
61 
67 class cxResource_EXPORT XMLNodeParser
68 {
69 public:
70  XMLNodeParser(QDomNode node);
74  XMLNodeParser descend(QString path);
75  QDomNode node();
76 
77  QString parseTextFromElement(QString name);
78  double parseDoubleFromElementWithDefault(QString name, double defaultValue);
79  QStringList parseTextFromDuplicateElements(QString name);
80  std::vector<QDomElement> getDuplicateElements(QString name);
81 
82  template<class T>
83  void parseObjectFromElement(QString name, T object)
84  {
85  object->parseXml(mNode.namedItem(name));
86  }
87 
88  QDomElement parseElement(QString name);
89 
90 private:
91  QDomNode mNode;
92 };
93 
98 } // namespace cx
99 
100 
101 #endif // CXXMLNODEWRAPPER_H
void addObjectToElement(QString name, T object)
void parseObjectFromElement(QString name, T object)
Namespace for all CustusX production code.