26 #ifndef CASADI_XML_NODE_HPP
27 #define CASADI_XML_NODE_HPP
32 #include "exception.hpp"
33 #include "casadi_common.hpp"
61 bool has_attribute(
const std::string& att_name)
const;
66 void set_attribute(
const std::string& att_name,
const std::string& att);
72 set_attribute(att_name, std::to_string(att));
78 void set_attribute(
const std::string& att_name,
double att);
83 void set_attribute(
const std::string& att_name,
const std::vector<casadi_int>& att);
88 std::vector<std::string> child_names()
const;
93 std::vector<std::string> attribute_names()
const;
101 auto it = this->attributes.find(att_name);
102 casadi_assert(it != this->attributes.end(),
"Could not find attribute " + att_name);
105 read(it->second, &ret);
113 T attribute(
const std::string& att_name,
const T& def_att)
const {
115 auto it = this->attributes.find(att_name);
116 if (it == this->attributes.end()) {
122 read(it->second, &ret);
140 const XmlNode& operator[](
const std::string& childname)
const;
145 XmlNode& operator[](
const std::string& childname);
150 bool has_child(
const std::string& childname)
const;
155 size_t size()
const {
return this->children.size();}
161 void get(T* val)
const { read(this->text, val);}
166 static void read(
const std::string&
str, std::string* val);
171 static void read(
const std::string&
str,
bool* val);
176 static void read(
const std::string&
str, casadi_int* val);
181 static void read(
const std::string&
str,
size_t* val);
186 static void read(
const std::string&
str,
double* val);
191 static void read(
const std::string&
str, std::vector<casadi_int>* val);
196 static void read(
const std::string&
str, std::vector<std::string>* val);
201 CASADI_EXPORT
friend std::ostream&
operator<<(std::ostream &stream,
const XmlNode& node);
206 void dump(std::ostream &stream, casadi_int indent = 0)
const;
std::ostream & operator<<(std::ostream &stream, const XmlNode &node)
std::string str(const T &v)
String representation, any type.
T attribute(const std::string &att_name, const T &def_att) const
Get an attribute by its name, default value if not found.
std::vector< XmlNode > children
void set_attribute(const std::string &att_name, casadi_int att)
Add an integer attribute.
T attribute(const std::string &att_name) const
Get an attribute by its name.
void get(T *val) const
Get value of text field.
std::map< std::string, std::string > attributes
XmlNode & operator[](size_t i)
Get a reference to a child by its index.
const XmlNode & operator[](size_t i) const
Get a reference to a child by its index.
size_t size() const
Get the number of children.