A toolkit for working with phylogenetic data.
v0.18.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
utils/formats/xml/writer.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_FORMATS_XML_WRITER_H_
2 #define GENESIS_UTILS_FORMATS_XML_WRITER_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2017 Lucas Czech
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
34 #include <string>
35 #include <unordered_map>
36 
37 namespace genesis {
38 namespace utils {
39 
40 // =================================================================================================
41 // Forward declarations
42 // =================================================================================================
43 
44 class XmlComment;
45 class XmlMarkup;
46 class XmlElement;
47 class XmlDocument;
48 \
49 // =================================================================================================
50 // Xml Writer
51 // =================================================================================================
52 
56 class XmlWriter
57 {
58  typedef std::unordered_map<std::string, std::string> StringMapType;
59 
60  // ---------------------------------------------------------------------
61  // Printing
62  // ---------------------------------------------------------------------
63 
64 public:
65  void to_file ( const XmlDocument& document, const std::string& filename);
66  void to_string ( const XmlDocument& document, std::string& output);
67  std::string to_string ( const XmlDocument& document);
68 
69  // -----------------------------------------------------
70  // Internal
71  // -----------------------------------------------------
72 
73 protected:
74  void print_comment (std::string& xml, const XmlComment* value);
75  void print_markup (std::string& xml, const XmlMarkup* value);
76  void print_element (std::string& xml, const XmlElement* value, const int indent_level);
77 
78  std::string print_attributes_list (StringMapType attr);
79 
80  // -----------------------------------------------------
81  // Members
82  // -----------------------------------------------------
83 
84 public:
85 
89  int indent = 4;
90 };
91 
92 } // namespace utils
93 } // namespace genesis
94 
95 #endif // include guard
int indent
Indent used for printing the XML elements.
void print_element(std::string &xml, const XmlElement *value, const int indent_level)
Print an XML element.
void to_file(const XmlDocument &document, const std::string &filename)
Write an XML file from an XmlDocument. Return true iff successful.
void to_string(const XmlDocument &document, std::string &output)
Give the XML string representation of a XmlDocument.
void print_comment(std::string &xml, const XmlComment *value)
Print an XML comment.
void print_markup(std::string &xml, const XmlMarkup *value)
Print an XML markup (simple text).
std::string print_attributes_list(StringMapType attr)
Print a list of XML attributes.