aGrUM 3.2.0
a C++ library for (probabilistic) graphical models
XmlDocument.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2026 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
58
59#ifndef GUM_XML_DOCUMENT_H
60#define GUM_XML_DOCUMENT_H
61
62#include <exception>
63#include <memory>
64#include <string>
65#include <vector>
66
67#include <agrum/config.h>
68
69namespace gum {
70
72 class GUM_PUBLIC_BN XmlException: public std::exception {
73 public:
74 explicit XmlException(std::string message);
75
76 const char* what() const noexcept override;
77
78 private:
79 std::string _message_;
80 };
81
89 class GUM_PUBLIC_BN XmlElement {
90 public:
91 XmlElement() = default;
92
93 bool isNull() const noexcept { return _handle_ == nullptr; }
94
96 XmlElement firstChildElement(const std::string& tag) const;
97
99 XmlElement firstChildElement(const std::string& tag, bool throwIfNotFound) const;
100
102 std::vector< XmlElement > children(const std::string& tag) const;
103
104 std::string textOrDefault(const std::string& defaultValue) const;
105
107 std::string attribute(const std::string& name) const;
108
111 bool attribute(const std::string& name, std::string* out, bool throwIfNotFound = false) const;
112
113 private:
114 friend class XmlDocument;
115
116 explicit XmlElement(void* ticppElement) noexcept : _handle_(ticppElement) {}
117
118 void* _handle_ = nullptr;
119 };
120
125 class GUM_PUBLIC_BN XmlDocument {
126 public:
127 XmlDocument();
128 explicit XmlDocument(const std::string& filePath);
130
132 XmlDocument& operator=(XmlDocument&&) noexcept;
133 XmlDocument(const XmlDocument&) = delete;
134 XmlDocument& operator=(const XmlDocument&) = delete;
135
137 void parse(const std::string& content);
138
140 void loadFile();
141
142 bool noChildren() const;
143
145 XmlElement firstChildElement(const std::string& tag) const;
146
147 private:
148 struct Impl;
149 std::unique_ptr< Impl > _pimpl_;
150 };
151
152} /* namespace gum */
153
154#endif // GUM_XML_DOCUMENT_H
XmlDocument(XmlDocument &&) noexcept
XmlElement firstChildElement(const std::string &tag) const
std::unique_ptr< Impl > _pimpl_
void loadFile()
Loads the file passed to the constructor.
void parse(const std::string &content)
bool noChildren() const
A non-owning handle to an XML element, opaque over ticpp::Element.
Definition XmlDocument.h:89
void * _handle_
opaque ticpp::Element*, never exposed
XmlElement()=default
bool isNull() const noexcept
Definition XmlDocument.h:93
XmlElement(void *ticppElement) noexcept
friend class XmlDocument
std::string _message_
Definition XmlDocument.h:79
XmlException(std::string message)
const char * what() const noexcept override
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
const float MultiDimFunctionGraph< float >::defaultValue
STL namespace.