List of all members | Public Member Functions | Static Public Member Functions | Public Attributes | Friends
casadi::XmlNode Struct Reference

#include <xml_node.hpp>

Detailed Description

Definition at line 39 of file xml_node.hpp.

Public Member Functions

bool has_attribute (const std::string &att_name) const
 Check if an attribute is present. More...
 
void set_attribute (const std::string &att_name, const std::string &att)
 Add an attribute. More...
 
void set_attribute (const std::string &att_name, casadi_int att)
 Add an integer attribute. More...
 
void set_attribute (const std::string &att_name, double att)
 Add an integer attribute. More...
 
void set_attribute (const std::string &att_name, const std::vector< casadi_int > &att)
 Add a vector attribute. More...
 
std::vector< std::string > child_names () const
 Names of children. More...
 
std::vector< std::string > attribute_names () const
 Names of attributes. More...
 
template<typename T >
attribute (const std::string &att_name) const
 Get an attribute by its name. More...
 
template<typename T >
attribute (const std::string &att_name, const T &def_att) const
 Get an attribute by its name, default value if not found. More...
 
const XmlNodeoperator[] (size_t i) const
 Get a reference to a child by its index. More...
 
XmlNodeoperator[] (size_t i)
 Get a reference to a child by its index. More...
 
const XmlNodeoperator[] (const std::string &childname) const
 Get a reference to a child by its name. More...
 
XmlNodeoperator[] (const std::string &childname)
 Get a reference to a child by its name. More...
 
bool has_child (const std::string &childname) const
 Check if a child is present. More...
 
size_t size () const
 Get the number of children. More...
 
template<typename T >
void get (T *val) const
 Get value of text field. More...
 
void dump (std::ostream &stream, casadi_int indent=0) const
 Dump representation. More...
 

Static Public Member Functions

static void read (const std::string &str, std::string *val)
 Read the string value of a string (i.e. copy) More...
 
static void read (const std::string &str, bool *val)
 Read the boolean value of a string. More...
 
static void read (const std::string &str, casadi_int *val)
 Read the integer value of a string. More...
 
static void read (const std::string &str, size_t *val)
 Read the size_t value of a string. More...
 
static void read (const std::string &str, double *val)
 Read the double value of a string. More...
 
static void read (const std::string &str, std::vector< casadi_int > *val)
 Read a vector of integer values of a string. More...
 
static void read (const std::string &str, std::vector< std::string > *val)
 Read a vector of string values of a string. More...
 

Public Attributes

std::map< std::string, std::string > attributes
 
std::vector< XmlNodechildren
 
std::string name
 
std::string comment
 
casadi_int line
 
std::string text
 

Friends

CASADI_EXPORT friend std::ostream & operator<< (std::ostream &stream, const XmlNode &node)
 Print to stream. More...
 

Member Function Documentation

◆ attribute() [1/2]

template<typename T >
T casadi::XmlNode::attribute ( const std::string &  att_name) const
inline

Extra doc: https://github.com/casadi/casadi/wiki/L_vg

Definition at line 99 of file xml_node.hpp.

99  {
100  // Find the attribute, if any
101  auto it = this->attributes.find(att_name);
102  casadi_assert(it != this->attributes.end(), "Could not find attribute " + att_name);
103  // Attribute found, read it
104  T ret;
105  read(it->second, &ret);
106  return ret;
107  }
std::map< std::string, std::string > attributes
Definition: xml_node.hpp:41
static void read(const std::string &str, std::string *val)
Read the string value of a string (i.e. copy)
Definition: xml_node.cpp:111

References casadi::T.

Referenced by casadi::DaeBuilderInternal::import_default_experiment(), casadi::DaeBuilderInternal::import_dynamic_equations(), casadi::DaeBuilderInternal::import_initial_equations(), casadi::DaeBuilderInternal::import_model_exchange(), casadi::DaeBuilderInternal::import_model_structure(), casadi::DaeBuilderInternal::import_model_variables(), casadi::DaeBuilderInternal::load_fmi_description(), casadi::DaeBuilderInternal::qualified_name(), casadi::DaeBuilderInternal::read_dependencies(), casadi::DaeBuilderInternal::read_dependencies_kind(), and set_attribute().

◆ attribute() [2/2]

template<typename T >
T casadi::XmlNode::attribute ( const std::string &  att_name,
const T &  def_att 
) const
inline

Extra doc: https://github.com/casadi/casadi/wiki/L_vh

Definition at line 113 of file xml_node.hpp.

113  {
114  // Find the attribute, if any
115  auto it = this->attributes.find(att_name);
116  if (it == this->attributes.end()) {
117  // No such attribute, return default value
118  return def_att;
119  } else {
120  // Attribute found, read it
121  T ret;
122  read(it->second, &ret);
123  return ret;
124  }
125  }

References casadi::T.

◆ attribute_names()

std::vector< std::string > casadi::XmlNode::attribute_names ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_vf

Definition at line 169 of file xml_node.cpp.

169  {
170  std::vector<std::string> ret;
171  ret.reserve(this->attributes.size());
172  for (auto& a : this->attributes) ret.push_back(a.first);
173  return ret;
174 }

References attributes.

◆ child_names()

std::vector< std::string > casadi::XmlNode::child_names ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_ve

Definition at line 162 of file xml_node.cpp.

162  {
163  std::vector<std::string> ret;
164  ret.reserve(this->children.size());
165  for (auto& c : this->children) ret.push_back(c.name);
166  return ret;
167 }
std::vector< XmlNode > children
Definition: xml_node.hpp:44

References children.

◆ dump()

void casadi::XmlNode::dump ( std::ostream &  stream,
casadi_int  indent = 0 
) const

Extra doc: https://github.com/casadi/casadi/wiki/L_vw

Definition at line 84 of file xml_node.cpp.

84  {
85  // Print name
86  stream << std::string(indent, ' ') << "Node: " << this->name << std::endl;
87 
88  // Print comment
89  if (!this->comment.empty()) {
90  stream << std::string(indent, ' ') << "----- comment starts ----- " << std::endl;
91  stream << this->comment << std::endl;
92  stream << std::string(indent, ' ') << "----- comment ends ----- " << std::endl;
93  }
94 
95  // Print text
96  if (!this->text.empty())
97  stream << std::string(indent+2, ' ') << "Text: " << this->text << std::endl;
98 
99  // Print attributes
100  for (auto it = this->attributes.begin(); it != this->attributes.end(); ++it)
101  stream << std::string(indent+2, ' ') << "attribute " << it->first
102  << " = " << it->second << std::endl;
103 
104  // Print Children
105  for (casadi_int i=0; i < size(); ++i) {
106  stream << std::string(indent, ' ') << "Child " << i << ":" << std::endl;
107  (*this)[i].dump(stream, indent+2);
108  }
109 }
std::string comment
Definition: xml_node.hpp:50
std::string text
Definition: xml_node.hpp:56
size_t size() const
Get the number of children.
Definition: xml_node.hpp:155
std::string name
Definition: xml_node.hpp:47

References attributes, comment, name, size(), and text.

◆ get()

template<typename T >
void casadi::XmlNode::get ( T *  val) const
inline

◆ has_attribute()

bool casadi::XmlNode::has_attribute ( const std::string &  att_name) const

Extra doc: https://github.com/casadi/casadi/wiki/L_vc

Definition at line 31 of file xml_node.cpp.

31  {
32  return this->attributes.find(att_name) != this->attributes.end();
33 }

References attributes.

Referenced by casadi::DaeBuilderInternal::read_dependencies(), and casadi::DaeBuilderInternal::read_dependencies_kind().

◆ has_child()

bool casadi::XmlNode::has_child ( const std::string &  childname) const

Extra doc: https://github.com/casadi/casadi/wiki/L_vm

Definition at line 35 of file xml_node.cpp.

35  {
36  // Linear search over the elements
37  for (auto& c : this->children) {
38  if (c.name == childname) return true;
39  }
40  // Not found
41  return false;
42 }

References children.

Referenced by casadi::DaeBuilderInternal::import_model_exchange(), casadi::DaeBuilderInternal::import_model_structure(), casadi::DaeBuilderInternal::import_model_variables(), and casadi::DaeBuilderInternal::load_fmi_description().

◆ operator[]() [1/4]

XmlNode & casadi::XmlNode::operator[] ( const std::string &  childname)

Extra doc: https://github.com/casadi/casadi/wiki/L_vl

Definition at line 44 of file xml_node.cpp.

44  {
45  // Linear search over the elements
46  auto it = this->children.begin();
47  for (; it != this->children.end(); ++it) {
48  if (it->name == childname) break;
49  }
50  // Check that the child was indeed found
51  casadi_assert(it != this->children.end(), "Could not find " + childname);
52  // Return a reference to the child
53  return *it;
54 }

References children.

◆ operator[]() [2/4]

const XmlNode & casadi::XmlNode::operator[] ( const std::string &  childname) const

Extra doc: https://github.com/casadi/casadi/wiki/L_vk

Definition at line 56 of file xml_node.cpp.

56  {
57  return const_cast<XmlNode*>(this)->operator[](childname); // NOLINT
58 }

◆ operator[]() [3/4]

XmlNode& casadi::XmlNode::operator[] ( size_t  i)
inline

Extra doc: https://github.com/casadi/casadi/wiki/L_vj

Definition at line 135 of file xml_node.hpp.

135 { return this->children.at(i);}

◆ operator[]() [4/4]

const XmlNode& casadi::XmlNode::operator[] ( size_t  i) const
inline

Extra doc: https://github.com/casadi/casadi/wiki/L_vi

Definition at line 130 of file xml_node.hpp.

130 { return this->children.at(i);}

◆ read() [1/7]

void casadi::XmlNode::read ( const std::string &  str,
bool *  val 
)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_vq

Definition at line 115 of file xml_node.cpp.

115  {
116  if (str == "true") {
117  *val = true;
118  } else if (str == "false") {
119  *val = false;
120  } else {
121  casadi_error("XML argument not 'true' or 'false'");
122  }
123 }
std::string str(const T &v)
String representation, any type.

References casadi::str().

◆ read() [2/7]

void casadi::XmlNode::read ( const std::string &  str,
casadi_int *  val 
)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_vr

Definition at line 130 of file xml_node.cpp.

130  {
131  std::istringstream buffer(str);
132  buffer >> *val;
133 }

References casadi::str().

◆ read() [3/7]

void casadi::XmlNode::read ( const std::string &  str,
double *  val 
)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_vs

Definition at line 135 of file xml_node.cpp.

135  {
136  std::istringstream buffer(str);
137  buffer >> *val;
138 }

References casadi::str().

◆ read() [4/7]

void casadi::XmlNode::read ( const std::string &  str,
size_t *  val 
)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_29u

Definition at line 125 of file xml_node.cpp.

125  {
126  std::istringstream buffer(str);
127  buffer >> *val;
128 }

References casadi::str().

◆ read() [5/7]

void casadi::XmlNode::read ( const std::string &  str,
std::string *  val 
)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_vp

Definition at line 111 of file xml_node.cpp.

111  {
112  *val = str;
113 }

References casadi::str().

◆ read() [6/7]

void casadi::XmlNode::read ( const std::string &  str,
std::vector< casadi_int > *  val 
)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_vt

Definition at line 140 of file xml_node.cpp.

140  {
141  val->clear();
142  std::istringstream buffer(str);
143  while (true) {
144  casadi_int v;
145  buffer >> v;
146  if (buffer.fail()) break;
147  val->push_back(v);
148  }
149 }

References casadi::str().

◆ read() [7/7]

void casadi::XmlNode::read ( const std::string &  str,
std::vector< std::string > *  val 
)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_vu

Definition at line 151 of file xml_node.cpp.

151  {
152  val->clear();
153  std::istringstream buffer(str);
154  while (true) {
155  std::string v;
156  buffer >> v;
157  if (buffer.fail()) break;
158  val->push_back(v);
159  }
160 }

References casadi::str().

◆ set_attribute() [1/4]

void casadi::XmlNode::set_attribute ( const std::string &  att_name,
casadi_int  att 
)
inline

Extra doc: https://github.com/casadi/casadi/wiki/L_252

Definition at line 71 of file xml_node.hpp.

71  {
72  set_attribute(att_name, std::to_string(att));
73  }
void set_attribute(const std::string &att_name, const std::string &att)
Add an attribute.
Definition: xml_node.cpp:60

◆ set_attribute() [2/4]

void casadi::XmlNode::set_attribute ( const std::string &  att_name,
const std::string &  att 
)

◆ set_attribute() [3/4]

void casadi::XmlNode::set_attribute ( const std::string &  att_name,
const std::vector< casadi_int > &  att 
)

Extra doc: https://github.com/casadi/casadi/wiki/L_254

Definition at line 64 of file xml_node.cpp.

64  {
65  std::stringstream ss;
66  if (!att.empty()) {
67  ss << att.at(0);
68  for (size_t i = 1; i < att.size(); ++i) ss << " " << att.at(i);
69  }
70  return set_attribute(att_name, ss.str());
71 }

References set_attribute().

◆ set_attribute() [4/4]

void casadi::XmlNode::set_attribute ( const std::string &  att_name,
double  att 
)

Extra doc: https://github.com/casadi/casadi/wiki/L_253

Definition at line 73 of file xml_node.cpp.

73  {
74  std::stringstream ss;
75  ss << std::scientific << std::setprecision(std::numeric_limits<double>::digits10 + 1) << att;
76  set_attribute(att_name, ss.str());
77 }

References set_attribute().

◆ size()

size_t casadi::XmlNode::size ( ) const
inline

Friends And Related Function Documentation

◆ operator<<

CASADI_EXPORT friend std::ostream& operator<< ( std::ostream &  stream,
const XmlNode node 
)
friend

Extra doc: https://github.com/casadi/casadi/wiki/L_vv

Definition at line 79 of file xml_node.cpp.

79  {
80  node.dump(stream);
81  return stream;
82 }

Member Data Documentation

◆ attributes

std::map<std::string, std::string> casadi::XmlNode::attributes

◆ children

std::vector<XmlNode> casadi::XmlNode::children

◆ comment

std::string casadi::XmlNode::comment

Definition at line 50 of file xml_node.hpp.

Referenced by dump(), and casadi::TinyXmlInterface::import_node().

◆ line

casadi_int casadi::XmlNode::line

Definition at line 53 of file xml_node.hpp.

Referenced by casadi::TinyXmlInterface::import_node().

◆ name

std::string casadi::XmlNode::name

◆ text

std::string casadi::XmlNode::text

The documentation for this struct was generated from the following files: