bpp-phyl  2.2.0
TreeExceptions.h
Go to the documentation of this file.
1 //
2 // File: TreeExceptions.h
3 // Created by: Julien Dutheil
4 // Created on: Mon Nov 3 17:04:46 2003
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 _TREEEXCEPTIONS_H_
41 #define _TREEEXCEPTIONS_H_
42 
43 #include <Bpp/Exceptions.h>
44 #include <Bpp/Text/TextTools.h>
45 
46 // From the STL:
47 #include <string>
48 
49 namespace bpp
50 {
51 class Node;
52 class Tree;
53 
58  public Exception
59 {
60 protected:
61  int nodeId_;
62 
63 public:
69  NodeException(const std::string& text, int nodeId) :
70  Exception("NodeException: " + text + "(id:" + TextTools::toString(nodeId) + ")"),
71  nodeId_(nodeId) {}
72 
73  virtual ~NodeException() throw () {}
74 
75 public:
81  virtual int getNodeId() const { return nodeId_; }
82 };
83 
84 
89  public NodeException
90 {
91 private:
92  const Node* node_;
93 
94 public:
100  NodePException(const std::string& text, const Node* node = 0);
101 
107  NodePException(const std::string& text, int nodeId) :
108  NodeException(text, nodeId), node_(0) {}
109 
111  NodeException(nex),
112  node_(nex.node_)
113  {}
114 
116  {
117  NodeException::operator=(nex);
118  node_ = nex.node_;
119  return *this;
120  }
121 
122  virtual ~NodePException() throw () {}
123 
124 public:
130  virtual const Node* getNode() const { return node_; };
136  virtual int getNodeId() const { return nodeId_; }
137 };
138 
143  public NodePException
144 {
145 private:
146  std::string propertyName_;
147 
148 public:
156  PropertyNotFoundException(const std::string& text, const std::string& propertyName, const Node* node = 0) :
157  NodePException("Property not found: " + propertyName + ". " + text, node),
158  propertyName_(propertyName) {}
159 
167  PropertyNotFoundException(const std::string& text, const std::string& propertyName, int nodeId) :
168  NodePException("Property not found: " + propertyName + ". " + text, nodeId),
169  propertyName_(propertyName) {}
170 
171  virtual ~PropertyNotFoundException() throw () {}
172 
173 public:
179  virtual const std::string& getPropertyName() const { return propertyName_; }
180 };
181 
186  public Exception
187 {
188 private:
189  std::string id_;
190 
191 public:
198  NodeNotFoundException(const std::string& text, const std::string& id);
199 
206  NodeNotFoundException(const std::string& text, int id);
207 
208  virtual ~NodeNotFoundException() throw () {}
209 
210 public:
216  virtual std::string getId() const { return id_; }
217 };
218 
223  public Exception
224 {
225 private:
226  const Tree* tree_;
227 
228 public:
235  TreeException(const std::string& text, const Tree* tree = 0);
236 
238  Exception(tex),
239  tree_(tex.tree_)
240  {}
241 
243  {
244  Exception::operator=(tex);
245  tree_ = tex.tree_;
246  return *this;
247  }
248 
249  virtual ~TreeException() throw () {}
250 
251 public:
257  virtual const Tree* getTree() const { return tree_; }
258 };
259 
264  public TreeException
265 {
266 public:
273  UnrootedTreeException(const std::string& text, const Tree* tree = 0);
274 
275  virtual ~UnrootedTreeException() throw () {}
276 };
277 
278 } // end of namespace bpp.
279 
280 #endif // _TREEEXCEPTIONS_H_
281 
NodePException(const std::string &text, int nodeId)
Build a new NodePException.
NodePException(const NodePException &nex)
PropertyNotFoundException(const std::string &text, const std::string &propertyName, int nodeId)
Build a new PropertyNotFoundException.
virtual const std::string & getPropertyName() const
Get the name of the property that could not be found.
Interface for phylogenetic tree objects.
Definition: Tree.h:148
virtual int getNodeId() const
Get the id of node that threw the exception.
virtual ~NodeException()
virtual const Tree * getTree() const
Get the tree that threw the exception.
Exception thrown when something is wrong with a particular node.
virtual ~TreeException()
TreeException & operator=(const TreeException &tex)
General exception thrown when something wrong happened in a tree.
UnrootedTreeException(const std::string &text, const Tree *tree=0)
Build a new UnrootedTreeException.
The phylogenetic node class.
Definition: Node.h:90
virtual std::string getId() const
Get the node id that threw the exception.
NodeException(const std::string &text, int nodeId)
Build a new NodePException.
General exception thrown if a property could not be found.
NodeNotFoundException(const std::string &text, const std::string &id)
Build a new NodeNotFoundException.
NodePException & operator=(const NodePException &nex)
Exception thrown when a tree is expected to be rooted.
TreeException(const TreeException &tex)
virtual const Node * getNode() const
Get the node that threw the exception.
const Tree * tree_
PropertyNotFoundException(const std::string &text, const std::string &propertyName, const Node *node=0)
Build a new PropertyNotFoundException.
virtual int getNodeId() const
Get the id of node that threw the exception.
General exception thrown when something is wrong with a particular node.
TreeException(const std::string &text, const Tree *tree=0)
Build a new TreeException.
General exception thrown when something is wrong with a particular node.
NodePException(const std::string &text, const Node *node=0)
Build a new NodePException.
const Node * node_