bpp-phyl  2.2.0
NexusIoTree.h
Go to the documentation of this file.
1 //
2 // File: NexusIOTree.h
3 // Created by: Julien Dutheil
4 // Created on: Wed May 27 19:06 2009
5 //
6 
7 /*
8 Copyright or © or Copr. CNRS, (November 16, 2004)
9 
10 This software is a computer program whose purpose is to provide classes
11 for phylogenetic data analysis.
12 
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".
18 
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
23 liability.
24 
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.
35 
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.
38 */
39 
40 #ifndef _NEXUSIOTREE_H_
41 #define _NEXUSIOTREE_H_
42 
43 #include "IoTree.h"
44 #include "../TreeTemplate.h"
45 
46 namespace bpp
47 {
48 
62  public virtual AbstractITree,
63  public virtual AbstractOTree,
64  public virtual AbstractIMultiTree,
65  public virtual AbstractOMultiTree
66 {
67  public:
68 
73 
74  virtual ~NexusIOTree() {}
75 
76  public:
77 
83  const std::string getFormatName() const;
84  const std::string getFormatDescription() const;
85  /* @} */
86 
92 #if defined(NO_VIRTUAL_COV)
93  Tree* read(const std::string& path) const throw (Exception)
94  {
95  return AbstractITree::read(path);
96  }
97 #else
98  TreeTemplate<Node>* read(const std::string& path) const throw (Exception)
99  {
100  return dynamic_cast<TreeTemplate<Node>*>(AbstractITree::read(path));
101  }
102 #endif
103 
104 #if defined(NO_VIRTUAL_COV)
105  Tree*
106 #else
108 #endif
109  read(std::istream& in) const throw (Exception);
117  void write(const Tree& tree, const std::string& path, bool overwrite = true) const throw (Exception)
118  {
119  AbstractOTree::write(tree, path, overwrite);
120  }
121  void write(const Tree& tree, std::ostream& out) const throw (Exception)
122  {
123  write_(tree, out);
124  }
132  void read(const std::string& path, std::vector<Tree*>& trees) const throw (Exception)
133  {
134  AbstractIMultiTree::read(path, trees);
135  }
136  void read(std::istream& in, std::vector<Tree*>& trees) const throw (Exception);
144  void write(const std::vector<Tree*>& trees, const std::string& path, bool overwrite = true) const throw (Exception)
145  {
146  AbstractOMultiTree::write(trees, path, overwrite);
147  }
148  void write(const std::vector<Tree*>& trees, std::ostream& out) const throw (Exception)
149  {
150  write_(trees, out);
151  }
154  protected:
155  void write_(const Tree& tree, std::ostream& out) const throw (Exception);
156 
157  template<class N>
158  void write_(const TreeTemplate<N>& tree, std::ostream& out) const throw (Exception);
159 
160  void write_(const std::vector<Tree*>& trees, std::ostream& out) const throw (Exception);
161 
162  template<class N>
163  void write_(const std::vector<TreeTemplate<N>*>& trees, std::ostream& out) const throw (Exception);
164 
165 };
166 
167 } //end of namespace bpp.
168 
169 #endif //_NEXUSIOTREE_H_
170 
void write(const std::vector< Tree *> &trees, std::ostream &out) const =0
Write trees to a stream.
a simple parser for reading trees from a Nexus file.
Definition: NexusIoTree.h:61
void write(const std::vector< Tree *> &trees, std::ostream &out) const
Write trees to a stream.
Definition: NexusIoTree.h:148
void write(const Tree &tree, std::ostream &out) const =0
Write a tree to a stream.
Partial implementation of the ITree interface.
Definition: IoTree.h:134
const std::string getFormatDescription() const
Definition: NexusIoTree.cpp:68
TreeTemplate< Node > * read(const std::string &path) const
Read a tree from a file.
Definition: NexusIoTree.h:98
void write(const Tree &tree, std::ostream &out) const
Write a tree to a stream.
Definition: NexusIoTree.h:121
The phylogenetic tree class.
Interface for phylogenetic tree objects.
Definition: Tree.h:148
virtual ~NexusIOTree()
Definition: NexusIoTree.h:74
void write(const std::vector< Tree *> &trees, const std::string &path, bool overwrite=true) const
Write trees to a file.
Definition: NexusIoTree.h:144
void read(const std::string &path, std::vector< Tree *> &trees) const
Read trees from a file.
Definition: NexusIoTree.h:132
const std::string getFormatName() const
Definition: NexusIoTree.cpp:64
virtual Tree * read(std::istream &in) const =0
Read a tree from a stream.
virtual void read(std::istream &in, std::vector< Tree *> &trees) const =0
Read trees from a stream.
Partial implementation of the OTree interface.
Definition: IoTree.h:156
NexusIOTree()
Build a new Nexus tree parser.
Definition: NexusIoTree.h:72
Partial implementation of the OTree interface.
Definition: IoTree.h:274
Partial implementation of the IMultiTree interface.
Definition: IoTree.h:253
void write_(const Tree &tree, std::ostream &out) const
void write(const Tree &tree, const std::string &path, bool overwrite=true) const
Write a tree to a file.
Definition: NexusIoTree.h:117