21 #ifndef LIBCXML_CXML_H
22 #define LIBCXML_CXML_H
24 #include <glibmm/ustring.h>
25 #include <boost/optional.hpp>
26 #include <boost/filesystem.hpp>
27 #include <boost/algorithm/string/erase.hpp>
47 class Error :
public std::exception
53 Error (std::string
const & message) : _message (message) {}
61 char const *
what () const noexcept
override {
62 return _message.c_str ();
73 template <
typename P,
typename Q>
80 BOOST_STATIC_ASSERT (
sizeof(Q) == 0);
85 raw_convert (std::string v);
89 raw_convert (std::string v);
93 raw_convert (std::string v);
97 raw_convert (std::string v);
101 raw_convert (std::string v);
105 raw_convert (std::string v);
109 raw_convert (std::string v);
113 raw_convert (std::string v);
125 Node (xmlpp::Node* node);
127 std::string name ()
const;
151 std::string string_child (std::string c)
const;
152 boost::optional<std::string> optional_string_child (std::string)
const;
154 bool bool_child (std::string)
const;
155 boost::optional<bool> optional_bool_child (std::string)
const;
158 T number_child (std::string c)
const
160 auto s = string_child (c);
161 boost::erase_all (s,
" ");
162 return raw_convert<T> (s);
166 boost::optional<T> optional_number_child (std::string c)
const
168 auto s = optional_string_child (c);
174 boost::erase_all (t,
" ");
175 return raw_convert<T> (t);
190 std::string string_attribute (std::string)
const;
191 boost::optional<std::string> optional_string_attribute (std::string)
const;
193 bool bool_attribute (std::string)
const;
194 boost::optional<bool> optional_bool_attribute (std::string)
const;
197 T number_attribute (std::string c)
const
199 std::string s = string_attribute (c);
200 boost::erase_all (s,
" ");
201 return raw_convert<T> (s);
205 boost::optional<T> optional_number_attribute (std::string c)
const
207 auto s = optional_string_attribute (c);
209 return boost::optional<T> ();
213 boost::erase_all (t,
" ");
214 return raw_convert<T> (t);
226 std::shared_ptr<Node> node_child (std::string)
const;
227 std::shared_ptr<Node> optional_node_child (std::string)
const;
229 std::vector<std::shared_ptr<Node>> node_children ()
const;
230 std::vector<std::shared_ptr<Node>> node_children (std::string)
const;
232 xmlpp::Node* node ()
const {
236 bool is_text()
const;
242 mutable std::vector<Glib::ustring> _taken;
245 typedef std::shared_ptr<cxml::Node> NodePtr;
246 typedef std::shared_ptr<const cxml::Node> ConstNodePtr;
252 explicit Document(std::string root_name);
253 Document (std::string root_name, boost::filesystem::path);
260 void read_file (boost::filesystem::path);
261 void read_string (std::string);
263 std::string root_name ()
const {
268 void take_root_node ();
270 xmlpp::DomParser* _parser;
271 std::string _root_name;
275 xmlpp::Element* add_child(xmlpp::Element* parent, std::string
const& name, std::string
const& ns_prefix = {});
276 void add_text_child(xmlpp::Element* parent, std::string
const& name, std::string
const& text);
An error.
Definition: cxml.h:48
Error(std::string const &message)
Definition: cxml.h:53
char const * what() const noexcept override
Definition: cxml.h:61
~Error()
Definition: cxml.h:56
A wrapper for a xmlpp::Node which simplifies parsing.
Definition: cxml.h:117
void ignore_child(std::string) const
Definition: cxml.cc:162
std::string namespace_prefix() const
Definition: cxml.cc:249
std::string content() const
Definition: cxml.cc:228
void done() const
Definition: cxml.cc:218
std::string namespace_uri() const
Definition: cxml.cc:243