A toolkit for working with phylogenetic data.
v0.19.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tree/formats/phyloxml/writer.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TREE_FORMATS_PHYLOXML_WRITER_H_
2 #define GENESIS_TREE_FORMATS_PHYLOXML_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 <functional>
35 #include <string>
36 #include <vector>
37 
38 namespace genesis {
39 
40 // =================================================================================================
41 // Forward declarations
42 // =================================================================================================
43 
44 namespace utils {
45  class XmlDocument;
46  class XmlElement;
47 }
48 
49 namespace tree {
50 
51 class Tree;
52 class TreeNode;
53 class TreeEdge;
54 class TreeSet;
55 
56 // =================================================================================================
57 // Phyloxml Writer
58 // =================================================================================================
59 
102 {
103 public:
104 
105  // -------------------------------------------------------------------------
106  // Typedefs and Enums
107  // -------------------------------------------------------------------------
108 
116  using prepare_writing_function = std::function< void(
117  Tree const& tree, utils::XmlDocument& xml
118  ) >;
119 
126  using finish_writing_function = std::function< void(
127  Tree const& tree, utils::XmlDocument& xml
128  ) >;
129 
137  using node_to_element_function = std::function< void(
138  TreeNode const& node, utils::XmlElement& element
139  ) >;
140 
148  using edge_to_element_function = std::function< void(
149  TreeEdge const& edge, utils::XmlElement& element
150  ) >;
151 
152  // -------------------------------------------------------------------------
153  // Constructor and Rule of Five
154  // -------------------------------------------------------------------------
155 
156  PhyloxmlWriter() = default;
157  virtual ~PhyloxmlWriter() = default;
158 
159  PhyloxmlWriter(PhyloxmlWriter const&) = default;
160  PhyloxmlWriter(PhyloxmlWriter&&) = default;
161 
162  PhyloxmlWriter& operator= (PhyloxmlWriter const&) = default;
164 
165  // ---------------------------------------------------------------------
166  // Writing
167  // ---------------------------------------------------------------------
168 
177  void to_file (const Tree& tree, const std::string filename) const;
178 
182  void to_string (const Tree& tree, std::string& ts) const;
183 
187  std::string to_string (const Tree& tree) const;
188 
192  void to_document (const Tree& tree, utils::XmlDocument& xml) const;
193 
194  // -------------------------------------------------------------------------
195  // Plugin Functions
196  // -------------------------------------------------------------------------
197 
201  std::vector<prepare_writing_function> prepare_writing_plugins;
202 
206  std::vector<finish_writing_function> finish_writing_plugins;
207 
212  std::vector<node_to_element_function> node_to_element_plugins;
213 
218  std::vector<edge_to_element_function> edge_to_element_plugins;
219 
220 };
221 
222 } // namespace tree
223 } // namespace genesis
224 
225 #endif // include guard
std::function< void(TreeNode const &node, utils::XmlElement &element) > node_to_element_function
Function type that translates from a TreeNode to an XmlElement.
std::function< void(TreeEdge const &edge, utils::XmlElement &element) > edge_to_element_function
Function type that translates from a TreeEdge to an XmlElement.
std::vector< node_to_element_function > node_to_element_plugins
Collect all functions to be called for each TreeNode in order to translate it to a Phyloxml represent...
Write a Tree to Phyloxml format.
void to_string(const Tree &tree, std::string &ts) const
Gives a Phyloxml string representation of the tree.
std::function< void(Tree const &tree, utils::XmlDocument &xml) > prepare_writing_function
Function type that allows to do some preparatory work with the Tree and XmlDocument before the actual...
std::vector< prepare_writing_function > prepare_writing_plugins
Collect all functions to be called before starting the actual tree writing.
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:95
virtual ~PhyloxmlWriter()=default
void to_file(const Tree &tree, const std::string filename) const
Writes the tree to a file in Phyloxml format.
void to_document(const Tree &tree, utils::XmlDocument &xml) const
Store the information of the tree into an Phyloxml-formatted XmlDocument.
PhyloxmlWriter & operator=(PhyloxmlWriter const &)=default
std::function< void(Tree const &tree, utils::XmlDocument &xml) > finish_writing_function
Function type that allows to do some finalizing work with the Tree and XmlDocument after the actual t...
std::vector< finish_writing_function > finish_writing_plugins
Collect all functions to be called after finishing the actual tree writing.
std::vector< edge_to_element_function > edge_to_element_plugins
Collect all functions to be called for each TreeEdge in order to translate it to a Phyloxml represent...