A toolkit for working with phylogenetic data.
v0.24.0
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-2020 Lucas Czech and HITS gGmbH
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 
35 
36 #include <functional>
37 #include <string>
38 #include <vector>
39 
40 namespace genesis {
41 
42 // =================================================================================================
43 // Forward declarations
44 // =================================================================================================
45 
46 namespace utils {
47  class XmlDocument;
48  class XmlElement;
49 }
50 
51 namespace tree {
52 
53 class Tree;
54 class TreeNode;
55 class TreeEdge;
56 class TreeSet;
57 
58 // =================================================================================================
59 // Phyloxml Writer
60 // =================================================================================================
61 
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;
163  PhyloxmlWriter& operator= (PhyloxmlWriter&&) = default;
164 
165  // ---------------------------------------------------------------------
166  // Writing
167  // ---------------------------------------------------------------------
168 
175  void write( Tree const& tree, std::shared_ptr<utils::BaseOutputTarget> target ) const;
176 
180  void to_document ( Tree const& tree, utils::XmlDocument& xml) const;
181 
182  // -------------------------------------------------------------------------
183  // Plugin Functions
184  // -------------------------------------------------------------------------
185 
189  std::vector<prepare_writing_function> prepare_writing_plugins;
190 
194  std::vector<finish_writing_function> finish_writing_plugins;
195 
200  std::vector<node_to_element_function> node_to_element_plugins;
201 
206  std::vector<edge_to_element_function> edge_to_element_plugins;
207 
208 };
209 
210 } // namespace tree
211 } // namespace genesis
212 
213 #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.
Container namespace for all symbols of genesis in order to keep them separate when used as a library...
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:97
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...