bpp-phyl3  3.0.0
TreeExceptions.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_PHYL_TREE_TREEEXCEPTIONS_H
6 #define BPP_PHYL_TREE_TREEEXCEPTIONS_H
7 
8 #include <Bpp/Exceptions.h>
9 #include <Bpp/Text/TextTools.h>
10 
11 
12 // From the STL:
13 #include <string>
14 
15 namespace bpp
16 {
17 class Node;
18 class Tree;
19 
24  public Exception
25 {
26 protected:
27  int nodeId_;
28 
29 public:
35  NodeException(const std::string& text, int nodeId) :
36  Exception("NodeException: " + text + "(id:" + TextTools::toString(nodeId) + ")"),
37  nodeId_(nodeId) {}
38 
39  virtual ~NodeException() {}
40 
41 public:
47  virtual int getNodeId() const { return nodeId_; }
48 };
49 
50 
55  public NodeException
56 {
57 private:
58  const Node* node_;
59 
60 public:
66  NodePException(const std::string& text, const Node* node = 0);
67 
73  NodePException(const std::string& text, int nodeId) :
74  NodeException(text, nodeId), node_(0) {}
75 
77  NodeException(nex),
78  node_(nex.node_)
79  {}
80 
82  {
83  NodeException::operator=(nex);
84  node_ = nex.node_;
85  return *this;
86  }
87 
88  virtual ~NodePException() {}
89 
90 public:
96  virtual const Node* getNode() const { return node_; }
102  virtual int getNodeId() const { return nodeId_; }
103 };
104 
109  public NodePException
110 {
111 private:
112  std::string propertyName_;
113 
114 public:
122  PropertyNotFoundException(const std::string& text, const std::string& propertyName, const Node* node = 0) :
123  NodePException("Property not found: " + propertyName + ". " + text, node),
124  propertyName_(propertyName) {}
125 
133  PropertyNotFoundException(const std::string& text, const std::string& propertyName, int nodeId) :
134  NodePException("Property not found: " + propertyName + ". " + text, nodeId),
135  propertyName_(propertyName) {}
136 
138 
139 public:
145  virtual const std::string& getPropertyName() const { return propertyName_; }
146 };
147 
152  public Exception
153 {
154 private:
155  std::string id_;
156 
157 public:
164  NodeNotFoundException(const std::string& text, const std::string& id);
165 
172  NodeNotFoundException(const std::string& text, int id);
173 
175 
176 public:
182  virtual std::string getId() const { return id_; }
183 };
184 
189  public Exception
190 {
191 private:
192  const Tree* tree_;
193 
194 public:
201  TreeException(const std::string& text, const Tree* tree = 0);
202 
204  Exception(tex),
205  tree_(tex.tree_)
206  {}
207 
209  {
210  Exception::operator=(tex);
211  tree_ = tex.tree_;
212  return *this;
213  }
214 
215  virtual ~TreeException() {}
216 
217 public:
223  virtual const Tree* getTree() const { return tree_; }
224 };
225 
230  public TreeException
231 {
232 public:
239  UnrootedTreeException(const std::string& text, const Tree* tree = 0);
240 
242 };
243 } // end of namespace bpp.
244 #endif // BPP_PHYL_TREE_TREEEXCEPTIONS_H
General exception thrown when something is wrong with a particular node.
NodeException(const std::string &text, int nodeId)
Build a new NodePException.
virtual ~NodeException()
virtual int getNodeId() const
Get the id of node that threw the exception.
Exception thrown when something is wrong with a particular node.
NodeNotFoundException(const std::string &text, const std::string &id)
Build a new NodeNotFoundException.
virtual std::string getId() const
Get the node id that threw the exception.
General exception thrown when something is wrong with a particular node.
NodePException(const std::string &text, const Node *node=0)
Build a new NodePException.
virtual const Node * getNode() const
Get the node that threw the exception.
virtual int getNodeId() const
Get the id of node that threw the exception.
NodePException(const NodePException &nex)
const Node * node_
NodePException & operator=(const NodePException &nex)
virtual ~NodePException()
NodePException(const std::string &text, int nodeId)
Build a new NodePException.
The phylogenetic node class.
Definition: Node.h:59
General exception thrown if a property could not be found.
PropertyNotFoundException(const std::string &text, const std::string &propertyName, const Node *node=0)
Build a new PropertyNotFoundException.
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.
General exception thrown when something wrong happened in a tree.
virtual const Tree * getTree() const
Get the tree that threw the exception.
virtual ~TreeException()
TreeException(const TreeException &tex)
const Tree * tree_
TreeException(const std::string &text, const Tree *tree=0)
Build a new TreeException.
TreeException & operator=(const TreeException &tex)
Interface for phylogenetic tree objects.
Definition: Tree.h:115
Exception thrown when a tree is expected to be rooted.
UnrootedTreeException(const std::string &text, const Tree *tree=0)
Build a new UnrootedTreeException.
std::string toString(T t)
Defines the basic types of data flow nodes.