Documentation for OpenFLUID 2.2.2
Loading...
Searching...
No Matches
XML.hpp
Go to the documentation of this file.
1/*
2
3 This file is part of OpenFLUID software
4 Copyright(c) 2021-2026, INRAE
5
6
7 == GNU General Public License Usage ==
8
9 OpenFLUID is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 OpenFLUID is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21
22
23 == Other Usage ==
24
25 Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26 license, and requires a written agreement between You and INRA.
27 Licensees for Other Usage of OpenFLUID may use this file in accordance
28 with the terms contained in the written agreement between You and INRA.
29
30*/
31
32
33/**
34 @file XML.hpp
35
36 @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37 */
38
39
40#ifndef __OPENFLUID_THIRDPARTY_XML_HPP__
41#define __OPENFLUID_THIRDPARTY_XML_HPP__
42
43
44#include <string>
45
46#include <openfluid/thirdparty/tinyxml2-9.0.0/tinyxml2.h>
47
48
49namespace openfluid { namespace thirdparty {
50
51
52/**
53 Alias to embed the tinyXML2 third-party library as openfluid::thirdparty::xml
54*/
55namespace xml = tinyxml2;
56
57
58inline std::string getXMLAttribute(const xml::XMLElement* const Elt, const std::string& AttrName,
59 const std::string& DefaultValue = "")
60{
61 if (Elt != nullptr && Elt->Attribute(AttrName.c_str()) != nullptr)
62 {
63 return std::string(Elt->Attribute(AttrName.c_str()));
64 }
65 return DefaultValue;
66}
67
68
69// =====================================================================
70// =====================================================================
71
72
73inline std::string getXMLText(const xml::XMLElement* const Elt, const std::string& DefaultValue = "")
74{
75 if (Elt != nullptr && Elt->GetText() != nullptr)
76 {
77 return std::string(Elt->GetText());
78 }
79 return DefaultValue;
80}
81
82
83// =====================================================================
84// =====================================================================
85
86
87inline std::string getOpenFLUIDXMLFormat(const xml::XMLElement* const Elt)
88{
89 return getXMLAttribute(Elt,"format");
90}
91
92
93// =====================================================================
94// =====================================================================
95
96
97inline openfluid::thirdparty::xml::XMLElement* prepareOpenFLUIDXMLDoc(xml::XMLDocument& Doc,
98 const std::string& FormatVersion)
99{
100 auto Decl = Doc.NewDeclaration();
101 Doc.InsertFirstChild(Decl);
102 auto OFElt = Doc.NewElement("openfluid");
103 OFElt->SetAttribute("format",FormatVersion.c_str());
104 Doc.InsertEndChild(OFElt);
105
106 return OFElt;
107}
108
109
110} } // namespaces
111
112
113#endif /* __OPENFLUID_THIRDPARTY_XML_HPP__ */
std::string getOpenFLUIDXMLFormat(const xml::XMLElement *const Elt)
Definition XML.hpp:87
openfluid::thirdparty::xml::XMLElement * prepareOpenFLUIDXMLDoc(xml::XMLDocument &Doc, const std::string &FormatVersion)
Definition XML.hpp:97
std::string getXMLAttribute(const xml::XMLElement *const Elt, const std::string &AttrName, const std::string &DefaultValue="")
Definition XML.hpp:58
std::string getXMLText(const xml::XMLElement *const Elt, const std::string &DefaultValue="")
Definition XML.hpp:73
Definition ApplicationException.hpp:47