~ubuntu-branches/ubuntu/raring/libbpp-phyl/raring

« back to all changes in this revision

Viewing changes to src/Bpp/Phyl/TreeExceptions.h

  • Committer: Bazaar Package Importer
  • Author(s): Julien Dutheil
  • Date: 2011-06-09 11:00:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110609110000-yvx78svv6w7xxgph
Tags: upstream-2.0.2
ImportĀ upstreamĀ versionĀ 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
54
/**
 
55
 * @brief General exception thrown when something is wrong with a particular node.
 
56
 */
 
57
class NodeException :
 
58
  public Exception
 
59
{
 
60
protected:
 
61
  int nodeId_;
 
62
 
 
63
public:
 
64
  /**
 
65
   * @brief Build a new NodePException.
 
66
   * @param text A message to be passed to the exception hierarchy.
 
67
   * @param nodeId The id of the node that threw the exception.
 
68
   */
 
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:
 
76
  /**
 
77
   * @brief Get the id of node that threw the exception.
 
78
   *
 
79
   * @return The id of the faulty node.
 
80
   */
 
81
  virtual int getNodeId() const { return nodeId_; }
 
82
};
 
83
 
 
84
 
 
85
/**
 
86
 * @brief General exception thrown when something is wrong with a particular node.
 
87
 */
 
88
class NodePException :
 
89
  public NodeException
 
90
{
 
91
private:
 
92
  const Node* node_;
 
93
 
 
94
public:
 
95
  /**
 
96
   * @brief Build a new NodePException.
 
97
   * @param text A message to be passed to the exception hierarchy.
 
98
   * @param node A const pointer toward the node that threw the exception.
 
99
   */
 
100
  NodePException(const std::string& text, const Node* node = 0);
 
101
 
 
102
  /**
 
103
   * @brief Build a new NodePException.
 
104
   * @param text A message to be passed to the exception hierarchy.
 
105
   * @param nodeId The id of the node that threw the exception.
 
106
   */
 
107
  NodePException(const std::string& text, int nodeId) :
 
108
    NodeException(text, nodeId), node_(0) {}
 
109
 
 
110
  NodePException(const NodePException& nex) :
 
111
    NodeException(nex),
 
112
    node_(nex.node_)
 
113
  {}
 
114
 
 
115
  NodePException& operator=(const NodePException& nex)
 
116
  {
 
117
    NodeException::operator=(nex);
 
118
    node_ = nex.node_;
 
119
    return *this;
 
120
  }
 
121
 
 
122
  virtual ~NodePException() throw () {}
 
123
 
 
124
public:
 
125
  /**
 
126
   * @brief Get the node that threw the exception.
 
127
   *
 
128
   * @return A pointer toward the faulty node.
 
129
   */
 
130
  virtual const Node* getNode() const { return node_; };
 
131
  /**
 
132
   * @brief Get the id of node that threw the exception.
 
133
   *
 
134
   * @return The id of the faulty node.
 
135
   */
 
136
  virtual int getNodeId() const { return nodeId_; }
 
137
};
 
138
 
 
139
/**
 
140
 * @brief General exception thrown if a property could not be found.
 
141
 */
 
142
class PropertyNotFoundException :
 
143
  public NodePException
 
144
{
 
145
private:
 
146
  std::string propertyName_;
 
147
 
 
148
public:
 
149
  /**
 
150
   * @brief Build a new PropertyNotFoundException.
 
151
   *
 
152
   * @param text A message to be passed to the exception hierarchy.
 
153
   * @param propertyName The name of the property.
 
154
   * @param node A const pointer toward the node that threw the exception.
 
155
   */
 
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
 
 
160
  /**
 
161
   * @brief Build a new PropertyNotFoundException.
 
162
   *
 
163
   * @param text A message to be passed to the exception hierarchy.
 
164
   * @param propertyName The name of the property.
 
165
   * @param nodeId The id of the node that threw the exception.
 
166
   */
 
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:
 
174
  /**
 
175
   * @brief Get the name of the property that could not be found.
 
176
   *
 
177
   * @return The name of the missing property.
 
178
   */
 
179
  virtual const std::string& getPropertyName() const { return propertyName_; }
 
180
};
 
181
 
 
182
/**
 
183
 * @brief Exception thrown when something is wrong with a particular node.
 
184
 */
 
185
class NodeNotFoundException :
 
186
  public Exception
 
187
{
 
188
private:
 
189
  std::string id_;
 
190
 
 
191
public:
 
192
  /**
 
193
   * @brief Build a new NodeNotFoundException.
 
194
   *
 
195
   * @param text A message to be passed to the exception hierarchy.
 
196
   * @param id   A string describing the node.
 
197
   */
 
198
  NodeNotFoundException(const std::string& text, const std::string& id);
 
199
 
 
200
  /**
 
201
   * @brief Build a new NodeNotFoundException.
 
202
   *
 
203
   * @param text A message to be passed to the exception hierarchy.
 
204
   * @param id   A node identifier.
 
205
   */
 
206
  NodeNotFoundException(const std::string& text, int id);
 
207
 
 
208
  virtual ~NodeNotFoundException() throw () {}
 
209
 
 
210
public:
 
211
  /**
 
212
   * @brief Get the node id that threw the exception.
 
213
   *
 
214
   * @return The id of the node.
 
215
   */
 
216
  virtual std::string getId() const { return id_; }
 
217
};
 
218
 
 
219
/**
 
220
 * @brief General exception thrown when something wrong happened in a tree.
 
221
 */
 
222
class TreeException :
 
223
  public Exception
 
224
{
 
225
private:
 
226
  const Tree* tree_;
 
227
 
 
228
public:
 
229
  /**
 
230
   * @brief Build a new TreeException.
 
231
   *
 
232
   * @param text A message to be passed to the exception hierarchy.
 
233
   * @param tree A const pointer toward the tree that threw the exception.
 
234
   */
 
235
  TreeException(const std::string& text, const Tree* tree = 0);
 
236
 
 
237
  TreeException(const TreeException& tex) :
 
238
    Exception(tex),
 
239
    tree_(tex.tree_)
 
240
  {}
 
241
 
 
242
  TreeException& operator=(const TreeException& tex)
 
243
  {
 
244
    Exception::operator=(tex);
 
245
    tree_ = tex.tree_;
 
246
    return *this;
 
247
  }
 
248
 
 
249
  virtual ~TreeException() throw () {}
 
250
 
 
251
public:
 
252
  /**
 
253
   * @brief Get the tree that threw the exception.
 
254
   *
 
255
   * @return The faulty tree
 
256
   */
 
257
  virtual const Tree* getTree() const { return tree_; }
 
258
};
 
259
 
 
260
/**
 
261
 * @brief Exception thrown when a tree is expected to be rooted.
 
262
 */
 
263
class UnrootedTreeException :
 
264
  public TreeException
 
265
{
 
266
public:
 
267
  /**
 
268
   * @brief Build a new UnrootedTreeException.
 
269
   *
 
270
   * @param text A message to be passed to the exception hierarchy.
 
271
   * @param tree A const pointer toward the tree that threw the exception.
 
272
   */
 
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