3
// Created by: Julien Dutheil
4
// Created on: Thu Oct 23 15:19:06 2003
8
Copyright or Ā© or Copr. CNRS, (November 16, 2004)
10
This software is a computer program whose purpose is to provide classes
11
for phylogenetic data analysis.
13
This software is governed by the CeCILL license under French law and
14
abiding by the rules of distribution of free software. You can use,
15
modify and/ or redistribute the software under the terms of the CeCILL
16
license as circulated by CEA, CNRS and INRIA at the following URL
17
"http://www.cecill.info".
19
As a counterpart to the access to the source code and rights to copy,
20
modify and redistribute granted by the license, users are provided only
21
with a limited warranty and the software's author, the holder of the
22
economic rights, and the successive licensors have only limited
25
In this respect, the user's attention is drawn to the risks associated
26
with loading, using, modifying and/or developing or reproducing the
27
software by the user in light of its specific status of free software,
28
that may mean that it is complicated to manipulate, and that also
29
therefore means that it is reserved for developers and experienced
30
professionals having in-depth computer knowledge. Users are therefore
31
encouraged to load and test the software's suitability as regards their
32
requirements in conditions enabling the security of their systems and/or
33
data to be ensured and, more generally, to use and operate it in the
34
same conditions as regards security.
36
The fact that you are presently reading this means that you have had
37
knowledge of the CeCILL license and that you accept its terms.
50
#include <Bpp/Exceptions.h>
51
#include <Bpp/Io/IoFormat.h>
57
* @brief General interface for tree I/O.
60
public virtual IOFormat
67
virtual const std::string getDataType() const { return "Tree"; }
71
* @brief General interface for tree readers.
82
* @brief Read a tree from a file.
84
* @param path The file path.
85
* @return A new tree object.
86
* @throw Exception If an error occured.
88
virtual Tree* read(const std::string& path) const throw (Exception) = 0;
90
* @brief Read a tree from a stream.
92
* @param in The input stream.
93
* @return A new tree object.
94
* @throw Exception If an error occured.
96
virtual Tree* read(std::istream& in) const throw (Exception) = 0;
100
* @brief General interface for tree writers.
103
public virtual IOTree
111
* @brief Write a tree to a file.
113
* @param tree A tree object.
114
* @param path The file path.
115
* @param overwrite Tell if existing file must be overwritten.
116
* Otherwise append to the file.
117
* @throw Exception If an error occured.
119
virtual void write(const Tree& tree, const std::string& path, bool overwrite) const throw (Exception) = 0;
121
* @brief Write a tree to a stream.
123
* @param tree A tree object.
124
* @param out The output stream.
125
* @throw Exception If an error occured.
127
virtual void write(const Tree& tree, std::ostream& out) const throw (Exception) = 0;
131
* @brief Partial implementation of the ITree interface.
138
virtual ~AbstractITree() {}
141
virtual Tree* read(std::istream& in) const throw (Exception) = 0;
142
virtual Tree* read(const std::string& path) const throw (Exception)
144
std::ifstream input(path.c_str(), std::ios::in);
145
Tree* tree = read(input);
153
* @brief Partial implementation of the OTree interface.
160
virtual ~AbstractOTree() {}
163
void write(const Tree& tree, std::ostream& out) const throw (Exception) = 0;
164
virtual void write(const Tree& tree, const std::string& path, bool overwrite) const throw (Exception)
166
// Open file in specified mode
167
std::ofstream output(path.c_str(), overwrite ? (std::ios::out) : (std::ios::out|std::ios::app));
180
* @brief General interface for multiple trees readers.
183
public virtual IOTree
187
virtual ~IMultiTree() {}
191
* @brief Read trees from a file.
193
* @param path The file path.
194
* @param trees The output trees container.
195
* @throw Exception If an error occured.
197
virtual void read(const std::string& path, std::vector<Tree*>& trees) const throw (Exception) = 0;
199
* @brief Read trees from a stream.
201
* @param in The input stream.
202
* @param trees The output trees container.
203
* @throw Exception If an error occured.
205
virtual void read(std::istream& in, std::vector<Tree*>& trees) const throw (Exception) = 0;
209
* @brief General interface for tree writers.
212
public virtual IOTree
216
virtual ~OMultiTree() {}
220
* @brief Write trees to a file.
222
* @param trees A vector of tree objects.
223
* @param path The file path.
224
* @param overwrite Tell if existing file must be overwritten.
225
* Otherwise append to the file.
226
* @throw Exception If an error occured.
228
virtual void write(const std::vector<Tree*>& trees, const std::string& path, bool overwrite) const throw (Exception) = 0;
230
* @brief Write trees to a stream.
232
* @param trees A vector of tree objects.
233
* @param out The output stream.
234
* @throw Exception If an error occured.
236
virtual void write(const std::vector<Tree*>& trees, std::ostream& out) const throw (Exception) = 0;
240
* @brief Partial implementation of the IMultiTree interface.
242
class AbstractIMultiTree:
243
public virtual IMultiTree
246
AbstractIMultiTree() {}
247
virtual ~AbstractIMultiTree() {}
250
virtual void read(std::istream& in, std::vector<Tree*>& trees) const throw (Exception) = 0;
251
virtual void read(const std::string& path, std::vector<Tree*>& trees) const throw (Exception)
253
std::ifstream input(path.c_str(), std::ios::in);
261
* @brief Partial implementation of the OTree interface.
263
class AbstractOMultiTree:
264
public virtual OMultiTree
267
AbstractOMultiTree() {}
268
virtual ~AbstractOMultiTree() {}
271
void write(const std::vector<Tree*>& trees, std::ostream& out) const throw (Exception) = 0;
272
virtual void write(const std::vector<Tree*>& trees, const std::string& path, bool overwrite) const throw (Exception)
274
// Open file in specified mode
275
std::ofstream output(path.c_str(), overwrite ? (std::ios::out) : (std::ios::out|std::ios::app));
276
write(trees, output);
281
} //end of namespace bpp.