bpp-core  2.2.0
VectorExceptions.h
Go to the documentation of this file.
1 //
2 // File: VectorExceptions.h
3 // Created by: Julien Dutheil
4 // Created on: 2003
5 //
6 
7 /*
8 Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
9 
10 This software is a computer program whose purpose is to provide classes
11 for numerical calculus.
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 _VECTOREXCEPTIONS_H_
41 #define _VECTOREXCEPTIONS_H_
42 
43 #include "../Exceptions.h"
44 #include "../Text/TextTools.h"
45 
46 //From the STL/
47 #include <string>
48 #include <vector>
49 
50 namespace bpp
51 {
52 
56 template<class T>
58  public Exception
59 {
60 
61  protected:
62  const std::vector<T> * vect_;
63 
64  public:
65  VectorException(const std::string& text, const std::vector<T>* vect = 0) :
66  Exception("VectorException: " + text),
67  vect_(vect) {};
68 
71  {
72  Exception::operator=(ve);
73  vect_ = ve.vect_;
74  return *this;
75  }
76 
77  virtual ~VectorException() throw () {};
78 
79  public:
80  virtual const std::vector<T>* getVector() const { return vect_; }
81 };
82 
86 template<class T>
88  public VectorException<T>
89 {
90 
91  public:
92  EmptyVectorException(const std::string& text, const std::vector<T>* vect = 0) :
93  VectorException<T>("EmptyVectorException: " + text, vect) {};
94 
95  virtual ~EmptyVectorException() throw () {}
96 };
97 
102  public Exception
103 {
104  private:
105  size_t dimension_;
107 
108  public:
109  DimensionException(const std::string& text, size_t dimension, size_t correctDimension) :
110  Exception("DimensionException (found " + TextTools::toString(dimension) + ", should be " + TextTools::toString(correctDimension) + ") " + text),
111  dimension_(dimension),
112  correctDimension_(correctDimension) {};
113 
114  virtual ~DimensionException() throw () {}
115 
116  public:
117  virtual size_t getDimension() const { return dimension_; }
118  virtual size_t getCorrectDimension() const { return correctDimension_; }
119 };
120 
124 template<class T> class ElementNotFoundException :
125  public VectorException<T>
126 {
127 
128  private:
129  const T* element_;
130 
131  public:
132  ElementNotFoundException(const std::string& text, const std::vector<T>* vect = 0, const T* element = 0) :
133  VectorException<T>("ElementNotFoundException: " + text, vect),
134  element_(element) {};
135 
137  VectorException<T>(enfe), element_(enfe.element_) {}
138 
140  {
142  element_ = enfe.element_;
143  return *this;
144  }
145 
146  virtual ~ElementNotFoundException() throw () {};
147 
148  public:
149  virtual const T* getElement() const { return element_; }
150 };
151 
152 } //end of namespace bpp.
153 
154 #endif //_VECTOREXCEPTIONS_H_
155 
virtual size_t getDimension() const
ElementNotFoundException(const ElementNotFoundException &enfe)
EmptyVectorException(const std::string &text, const std::vector< T > *vect=0)
This class allows to perform a correspondence analysis.
VectorException(const VectorException &ve)
Exception thrown when a given element was not found in the vector.
virtual const T * getElement() const
const std::vector< T > * vect_
VectorException(const std::string &text, const std::vector< T > *vect=0)
ElementNotFoundException & operator=(const ElementNotFoundException &enfe)
Exception thrown when an empty vector was found.
ElementNotFoundException(const std::string &text, const std::vector< T > *vect=0, const T *element=0)
General Exception dealing with vectors.
virtual size_t getCorrectDimension() const
Exception base class.
Definition: Exceptions.h:57
virtual const std::vector< T > * getVector() const
DimensionException(const std::string &text, size_t dimension, size_t correctDimension)
Some utilitary functions that work on strings.
Definition: TextTools.h:58
Exception thrown when a dimension problem occured.
VectorException & operator=(const VectorException &ve)