A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tree_set.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TREE_TREE_SET_H_
2 #define GENESIS_TREE_TREE_SET_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 "genesis/tree/tree.hpp"
35 
36 #include <ostream>
37 #include <string>
38 #include <vector>
39 
40 namespace genesis {
41 namespace tree {
42 
43 // =================================================================================================
44 // Tree Set
45 // =================================================================================================
46 
47 class TreeSet
48 {
49 public:
50 
51  // -------------------------------------------------------------------------
52  // Typedefs
53  // -------------------------------------------------------------------------
54 
58  struct NamedTree
59  {
60  std::string name;
62  };
63 
64  using iterator = typename std::vector<NamedTree>::iterator;
65  using const_iterator = typename std::vector<NamedTree>::const_iterator;
66 
67  // -------------------------------------------------------------------------
68  // Constructors and Rule of Five
69  // -------------------------------------------------------------------------
70 
71  TreeSet() = default;
72  ~TreeSet() = default;
73 
74  TreeSet( TreeSet const& ) = default;
75  TreeSet( TreeSet&& ) = default;
76 
77  TreeSet& operator= ( TreeSet const& ) = default;
78  TreeSet& operator= ( TreeSet&& ) = default;
79 
80  void swap( TreeSet& other );
81 
82  // -------------------------------------------------------------------------
83  // Modifiers
84  // -------------------------------------------------------------------------
85 
86  void add( std::string const& name, Tree const& tree );
87  void add( std::string&& name, Tree&& tree );
88 
89  void remove_at( size_t index );
90  void clear();
91 
92  // -------------------------------------------------------------------------
93  // Accessors
94  // -------------------------------------------------------------------------
95 
96  iterator begin();
97  const_iterator begin() const;
98 
99  iterator end();
100  const_iterator end() const;
101 
102  NamedTree& at ( size_t index );
103  const NamedTree& at ( size_t index ) const;
104 
105  NamedTree& operator [] (const std::size_t index);
106  const NamedTree& operator [] (const std::size_t index) const;
107 
108  bool empty() const;
109  size_t size() const;
110 
111  // -------------------------------------------------------------------------
112  // Output
113  // -------------------------------------------------------------------------
114 
118  // friend std::ostream& operator << ( std::ostream& out, TreeSet const& tset )
119  // {
120  // // If provided with the optional parameter `full`, also dump all Trees.
121  // // TODO this was meant for full output. turn it into a printer instead!
122  // bool full = false;
123  //
124  // for (auto& ct : tset) {
125  // out << ct.name << "\n";
126  // // TODO
127  // if (full) {
128  // out << ct.tree.dump() << "\n";
129  // }
130  // }
131  // return out;
132  // }
133 
134  // -------------------------------------------------------------------------
135  // Data Members
136  // -------------------------------------------------------------------------
137 
138 private:
139 
140  // We use a vector of elements here, because we want to preserve the order in which
141  // elements are inserted into the TreeMap. This is not the case with simple maps.
142  std::vector<NamedTree> trees_;
143 
144 };
145 
146 } // namespace tree
147 } // namespace genesis
148 
149 #endif // include guard
NamedTree & operator[](const std::size_t index)
Definition: tree_set.cpp:118
typename std::vector< NamedTree >::const_iterator const_iterator
Definition: tree_set.hpp:65
bool empty() const
Return whether the TreeSet is empty.
Definition: tree_set.cpp:131
void clear()
Clear the TreeSet and destroy all contained Trees.
Definition: tree_set.cpp:79
Store a Tree together with a name for it.
Definition: tree_set.hpp:58
size_t size() const
Return the size of the TreeSet, i.e., the number of stored Trees.
Definition: tree_set.cpp:139
typename std::vector< NamedTree >::iterator iterator
Definition: tree_set.hpp:64
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:95
void remove_at(size_t index)
Remove the Tree at a certain index position.
Definition: tree_set.cpp:71
TreeSet & operator=(TreeSet const &)=default
Header of Tree class.
void add(std::string const &name, Tree const &tree)
Add a Tree with a name to the TreeSet.
Definition: tree_set.cpp:55
void swap(TreeSet &other)
Definition: tree_set.cpp:40
NamedTree & at(size_t index)
Definition: tree_set.cpp:108