26 #include "tinyxml_interface.hpp"
31 int CASADI_XMLFILE_TINYXML_EXPORT
34 plugin->name =
"tinyxml";
36 plugin->version = CASADI_VERSION;
54 casadi_assert(!err,
"Cannot load " +
filename);
59 }
catch (std::exception& e) {
60 casadi_error(
"Cannot import " +
filename +
": " + std::string(e.what()));
67 doc_.InsertEndChild(
doc_.NewDeclaration());
71 }
catch (std::exception& e) {
72 casadi_error(
"Cannot export " +
filename +
": " + std::string(e.what()));
76 casadi_assert(!err,
"Cannot save " +
filename);
80 if (!n) casadi_error(
"Node is 0");
83 ret.
line = n->GetLineNum();
87 ret.
name = n->Value();
92 for (
const TiXmlAttribute* pAttrib=n->ToElement()->FirstAttribute();
93 pAttrib; pAttrib=pAttrib->Next()) {
96 }
else if (n->ToDocument()) {
99 casadi_error(
"TinyXmlInterface::import_node");
103 casadi_int num_children = 0;
104 for (TiXmlNode* child = n->FirstChild(); child !=
nullptr; child = child->NextSibling()) {
110 for (TiXmlNode* child = n->FirstChild(); child !=
nullptr; child = child->NextSibling()) {
111 if (child->ToElement()) {
113 }
else if (child->ToComment()) {
115 }
else if (child->ToText()) {
116 ret.
text = child->ToText()->Value();
117 }
else if (child->ToDeclaration()) {
119 }
else if (child->ToDocument()) {
122 casadi_error(
"Unknown node type");
134 TiXmlElement* tc =
doc_.NewElement(c.
name.c_str());
135 n->InsertEndChild(tc);
138 tc->SetAttribute(a.first.c_str(), a.second.c_str());
static void registerPlugin(const Plugin &plugin, bool needs_lock=true)
Register an integrator in the factory.
XmlNode import_node(TiXmlNode *n)
void dump(const std::string &filename, const XmlNode &node) override
void export_node(TiXmlNode *n, const XmlNode &node)
~TinyXmlInterface() override
XmlNode parse(const std::string &filename) override
TiXmlDocument doc_
XML file.
static const std::string meta_doc
A documentation string.
static XmlFileInternal * creator()
Create a new XmlFile.
void CASADI_XMLFILE_TINYXML_EXPORT casadi_load_xmlfile_tinyxml()
int CASADI_XMLFILE_TINYXML_EXPORT casadi_register_xmlfile_tinyxml(XmlFileInternal::Plugin *plugin)
std::string filename(const std::string &path)
void set_attribute(const std::string &att_name, const std::string &att)
Add an attribute.
std::vector< XmlNode > children
std::map< std::string, std::string > attributes