bpp-phyl3  3.0.0
PhyloTreeExceptions.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_PHYLOTREEEXCEPTIONS_H
6 #define BPP_PHYL_TREE_PHYLOTREEEXCEPTIONS_H
7 
8 #include <Bpp/Exceptions.h>
9 #include <Bpp/Text/TextTools.h>
10 
11 
12 // From the STL:
13 #include <string>
14 #include <memory>
15 
16 namespace bpp
17 {
18 class PhyloNode;
19 class PhyloBranch;
20 class PhyloTree;
21 
26  public Exception
27 {
28 protected:
29  uint nodeId_;
30 
31 public:
37  PhyloNodeException(const std::string& text, uint nodeId) :
38  Exception("PhyloNodeException: " + text + "(id:" + TextTools::toString(nodeId) + ")"),
39  nodeId_(nodeId) {}
40 
41  virtual ~PhyloNodeException() {}
42 
43 public:
49  virtual uint getNodeId() const { return nodeId_; }
50 };
51 
52 
57  public PhyloNodeException
58 {
59 private:
60  const PhyloNode* node_;
61 
62 public:
69  PhyloNodePException(const std::string& text, const PhyloTree& tree, const std::shared_ptr<PhyloNode> node);
70 
76  PhyloNodePException(const std::string& text, const PhyloNode* node);
77 
83  PhyloNodePException(const std::string& text, uint nodeId) :
84  PhyloNodeException(text, nodeId), node_(0) {}
85 
87  PhyloNodeException(nex),
88  node_(nex.node_)
89  {}
90 
92  {
93  PhyloNodeException::operator=(nex);
94  node_ = nex.node_;
95  return *this;
96  }
97 
98  virtual ~PhyloNodePException() {}
99 
100 public:
106  virtual const PhyloNode* getNode() const { return node_; }
112  virtual uint getNodeId() const { return nodeId_; }
113 };
114 
119  public PhyloNodePException
120 {
121 private:
122  std::string propertyName_;
123 
124 public:
132  PhyloNodePropertyNotFoundException(const std::string& text, const std::string& propertyName, const PhyloTree& tree, const std::shared_ptr<PhyloNode> node) :
133  PhyloNodePException("Property not found: " + propertyName + ". " + text, tree, node),
134  propertyName_(propertyName) {}
135 
142  PhyloNodePropertyNotFoundException(const std::string& text, const std::string& propertyName, const PhyloNode* node) :
143  PhyloNodePException("Property not found: " + propertyName + ". " + text, node),
144  propertyName_(propertyName) {}
145 
153  PhyloNodePropertyNotFoundException(const std::string& text, const std::string& propertyName, uint nodeId) :
154  PhyloNodePException("Property not found: " + propertyName + ". " + text, nodeId),
155  propertyName_(propertyName) {}
156 
158 
159 public:
165  virtual const std::string& getPropertyName() const { return propertyName_; }
166 };
167 
172  public Exception
173 {
174 private:
175  std::string id_;
176 
177 public:
184  PhyloNodeNotFoundException(const std::string& text, const std::string& id);
185 
192  PhyloNodeNotFoundException(const std::string& text, uint id);
193 
195 
196 public:
202  virtual std::string getId() const { return id_; }
203 };
204 
209  public Exception
210 {
211 protected:
212  uint branchId_;
213 
214 public:
220  PhyloBranchException(const std::string& text, uint branchId) :
221  Exception("PhyloBranchException: " + text + "(id:" + TextTools::toString(branchId) + ")"),
222  branchId_(branchId) {}
223 
225 
226 public:
232  virtual uint getBranchId() const { return branchId_; }
233 };
234 
235 
240  public PhyloBranchException
241 {
242 private:
244 
245 public:
252  PhyloBranchPException(const std::string& text, const PhyloTree& tree, const std::shared_ptr<PhyloBranch> branch);
253 
259  PhyloBranchPException(const std::string& text, const PhyloBranch* branch);
260 
266  PhyloBranchPException(const std::string& text, uint branchId) :
267  PhyloBranchException(text, branchId), branch_(0) {}
268 
271  branch_(nex.branch_)
272  {}
273 
275  {
276  PhyloBranchException::operator=(nex);
277  branch_ = nex.branch_;
278  return *this;
279  }
280 
282 
283 public:
289  virtual const PhyloBranch* getBranch() const { return branch_; }
295  virtual uint getBranchId() const { return branchId_; }
296 };
297 
302  public PhyloBranchPException
303 {
304 private:
305  std::string propertyName_;
306 
307 public:
316  PhyloBranchPropertyNotFoundException(const std::string& text, const std::string& propertyName, const PhyloTree& tree, const std::shared_ptr<PhyloBranch> branch) :
317  PhyloBranchPException("Property not found: " + propertyName + ". " + text, tree, branch),
318  propertyName_(propertyName) {}
319 
327  PhyloBranchPropertyNotFoundException(const std::string& text, const std::string& propertyName, const PhyloBranch* branch) :
328  PhyloBranchPException("Property not found: " + propertyName + ". " + text, branch),
329  propertyName_(propertyName) {}
330 
338  PhyloBranchPropertyNotFoundException(const std::string& text, const std::string& propertyName, uint branchId) :
339  PhyloBranchPException("Property not found: " + propertyName + ". " + text, branchId),
340  propertyName_(propertyName) {}
341 
343 
344 public:
350  virtual const std::string& getPropertyName() const { return propertyName_; }
351 };
352 
357  public Exception
358 {
359 private:
360  std::string id_;
361 
362 public:
369  PhyloBranchNotFoundException(const std::string& text, const std::string& id);
370 
377  PhyloBranchNotFoundException(const std::string& text, uint id);
378 
380 
381 public:
387  virtual std::string getId() const { return id_; }
388 };
389 
394  public Exception
395 {
396 private:
397  const PhyloTree* tree_;
398 
399 public:
406  PhyloTreeException(const std::string& text, const PhyloTree* tree = 0);
407 
409  Exception(tex),
410  tree_(tex.tree_)
411  {}
412 
414  {
415  Exception::operator=(tex);
416  tree_ = tex.tree_;
417  return *this;
418  }
419 
420  virtual ~PhyloTreeException() {}
421 
422 public:
428  virtual const PhyloTree* getTree() const { return tree_; }
429 };
430 
435  public PhyloTreeException
436 {
437 public:
444  UnrootedPhyloTreeException(const std::string& text, const PhyloTree* tree = 0);
445 
447 };
448 } // end of namespace bpp.
449 #endif // BPP_PHYL_TREE_PHYLOTREEEXCEPTIONS_H
General exception thrown when something is wrong with a particular branch.
virtual uint getBranchId() const
Get the id of branch that threw the exception.
PhyloBranchException(const std::string &text, uint branchId)
Build a new PhyloBranchPException.
Exception thrown when something is wrong with a particular branch.
PhyloBranchNotFoundException(const std::string &text, const std::string &id)
Build a new PhyloBranchNotFoundException.
virtual std::string getId() const
Get the branch id that threw the exception.
General exception thrown when something is wrong with a particular branch.
PhyloBranchPException(const PhyloBranchPException &nex)
PhyloBranchPException(const std::string &text, const PhyloTree &tree, const std::shared_ptr< PhyloBranch > branch)
Build a new PhyloBranchPException.
virtual uint getBranchId() const
Get the id of branch that threw the exception.
virtual const PhyloBranch * getBranch() const
Get the branch that threw the exception.
PhyloBranchPException & operator=(const PhyloBranchPException &nex)
PhyloBranchPException(const std::string &text, uint branchId)
Build a new PhyloBranchPException.
General exception thrown if a property could not be found.
PhyloBranchPropertyNotFoundException(const std::string &text, const std::string &propertyName, const PhyloTree &tree, const std::shared_ptr< PhyloBranch > branch)
Build a new PropertyNotFoundException (Branch).
virtual const std::string & getPropertyName() const
Get the name of the property that could not be found.
PhyloBranchPropertyNotFoundException(const std::string &text, const std::string &propertyName, uint branchId)
Build a new PropertyNotFoundException.
PhyloBranchPropertyNotFoundException(const std::string &text, const std::string &propertyName, const PhyloBranch *branch)
Build a new PropertyNotFoundException (Branch).
General exception thrown when something is wrong with a particular node.
virtual uint getNodeId() const
Get the id of node that threw the exception.
PhyloNodeException(const std::string &text, uint nodeId)
Build a new PhyloNodeException.
Exception thrown when something is wrong with a particular node.
PhyloNodeNotFoundException(const std::string &text, const std::string &id)
Build a new PhyloNodeNotFoundException.
virtual std::string getId() const
Get the node id that threw the exception.
General exception thrown when something is wrong with a particular node.
PhyloNodePException(const std::string &text, const PhyloTree &tree, const std::shared_ptr< PhyloNode > node)
Build a new PhyloNodePException.
PhyloNodePException & operator=(const PhyloNodePException &nex)
virtual const PhyloNode * getNode() const
Get the node that threw the exception.
PhyloNodePException(const PhyloNodePException &nex)
PhyloNodePException(const std::string &text, uint nodeId)
Build a new PhyloNodePException.
virtual uint getNodeId() const
Get the id of node that threw the exception.
General exception thrown if a property could not be found.
PhyloNodePropertyNotFoundException(const std::string &text, const std::string &propertyName, const PhyloNode *node)
Build a new PropertyNotFoundException (Node).
PhyloNodePropertyNotFoundException(const std::string &text, const std::string &propertyName, const PhyloTree &tree, const std::shared_ptr< PhyloNode > node)
Build a new PropertyNotFoundException (Node).
PhyloNodePropertyNotFoundException(const std::string &text, const std::string &propertyName, uint 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.
PhyloTreeException & operator=(const PhyloTreeException &tex)
PhyloTreeException(const PhyloTreeException &tex)
virtual const PhyloTree * getTree() const
Get the tree that threw the exception.
PhyloTreeException(const std::string &text, const PhyloTree *tree=0)
Build a new PhyloTreeException.
Exception thrown when a tree is expected to be rooted.
UnrootedPhyloTreeException(const std::string &text, const PhyloTree *tree=0)
Build a new UnrootedPhyloTreeException.
std::string toString(T t)
Defines the basic types of data flow nodes.