tinyxml_interface.hpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl,
6  * KU Leuven. All rights reserved.
7  * Copyright (C) 2011-2014 Greg Horn
8  *
9  * CasADi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * CasADi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with CasADi; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 
26 #ifndef CASADI_TINYXML_INTERFACE_HPP
27 #define CASADI_TINYXML_INTERFACE_HPP
28 
39 #include <tinyxml2.h>
40 #include "casadi/core/xml_file_internal.hpp"
41 #include <casadi/interfaces/tinyxml/casadi_xmlfile_tinyxml_export.h>
42 
43 typedef tinyxml2::XMLNode TiXmlNode;
44 typedef tinyxml2::XMLDocument TiXmlDocument;
45 typedef tinyxml2::XMLElement TiXmlElement;
46 typedef tinyxml2::XMLAttribute TiXmlAttribute;
47 typedef tinyxml2::XMLError XMLError;
48 
49 namespace casadi {
50 
55  class TinyXmlInterface : public XmlFileInternal {
56  public:
57 
58  // Create an XML file
59  TinyXmlInterface();
60 
62  static XmlFileInternal* creator()
63  { return new TinyXmlInterface();}
64 
65  // Get name of the plugin
66  const char* plugin_name() const override { return "tinyxml";}
67 
68  // Get name of the class
69  std::string class_name() const override { return "TinyXmlInterface";}
70 
71  // Parse an XML file
72  XmlNode parse(const std::string& filename) override;
73 
74  // Save a parsed XML file to disk
75  void dump(const std::string& filename, const XmlNode& node) override;
76 
77  // Read an XML tree
78  XmlNode import_node(TiXmlNode* n);
79 
80  // Write an XML tree
81  void export_node(TiXmlNode* n, const XmlNode& node);
82 
83  // Destructor
84  ~TinyXmlInterface() override;
85 
87  static const std::string meta_doc;
88 
90  TiXmlDocument doc_;
91  };
92 
93 } // namespace casadi
94 
96 
97 #endif // CASADI_TINYXML_INTERFACE_HPP
The casadi namespace.