A library for working with phylogenetic and population genetic data.
v0.27.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;
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
genesis::tree::PhyloxmlWriter::node_to_element_function
std::function< void(TreeNode const &node, utils::XmlElement &element) > node_to_element_function
Function type that translates from a TreeNode to an XmlElement.
Definition: tree/formats/phyloxml/writer.hpp:139
genesis::tree::PhyloxmlWriter::edge_to_element_plugins
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...
Definition: tree/formats/phyloxml/writer.hpp:206
genesis::tree::PhyloxmlWriter::node_to_element_plugins
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...
Definition: tree/formats/phyloxml/writer.hpp:200
genesis::utils::XmlElement
Definition: xml/document.hpp:149
genesis::tree::PhyloxmlWriter::write
void write(Tree const &tree, std::shared_ptr< utils::BaseOutputTarget > target) const
Write a Tree to an output target, using the Phyloxml format.
Definition: tree/formats/phyloxml/writer.cpp:56
genesis::tree::PhyloxmlWriter::to_document
void to_document(Tree const &tree, utils::XmlDocument &xml) const
Store the information of the tree into an Phyloxml-formatted XmlDocument.
Definition: tree/formats/phyloxml/writer.cpp:63
genesis::tree::Tree
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:97
genesis::tree::PhyloxmlWriter::~PhyloxmlWriter
virtual ~PhyloxmlWriter()=default
genesis::tree::TreeEdge
Definition: edge.hpp:60
genesis::tree::TreeNode
Definition: tree/tree/node.hpp:58
genesis::tree::PhyloxmlWriter
Write a Tree to Phyloxml format.
Definition: tree/formats/phyloxml/writer.hpp:101
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::tree::PhyloxmlWriter::prepare_writing_function
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...
Definition: tree/formats/phyloxml/writer.hpp:118
genesis::tree::PhyloxmlWriter::prepare_writing_plugins
std::vector< prepare_writing_function > prepare_writing_plugins
Collect all functions to be called before starting the actual tree writing.
Definition: tree/formats/phyloxml/writer.hpp:189
genesis::tree::PhyloxmlWriter::finish_writing_function
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...
Definition: tree/formats/phyloxml/writer.hpp:128
output_target.hpp
genesis::tree::PhyloxmlWriter::finish_writing_plugins
std::vector< finish_writing_function > finish_writing_plugins
Collect all functions to be called after finishing the actual tree writing.
Definition: tree/formats/phyloxml/writer.hpp:194
genesis::tree::PhyloxmlWriter::operator=
PhyloxmlWriter & operator=(PhyloxmlWriter const &)=default
genesis::tree::PhyloxmlWriter::edge_to_element_function
std::function< void(TreeEdge const &edge, utils::XmlElement &element) > edge_to_element_function
Function type that translates from a TreeEdge to an XmlElement.
Definition: tree/formats/phyloxml/writer.hpp:150
genesis::utils::XmlDocument
Definition: xml/document.hpp:219
genesis::tree::PhyloxmlWriter::PhyloxmlWriter
PhyloxmlWriter()=default