bpp-core3  3.0.0
VectorExceptions.h
Go to the documentation of this file.
1 //
2 // File: VectorExceptions.h
3 // Authors:
4 // Julien Dutheil
5 // Francois Gindraud (2017)
6 // Created: 2003-06-26 00:00:00
7 // Last modified: 2017-06-27 00:00:00
8 //
9 
10 /*
11  Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
12 
13  This software is a computer program whose purpose is to provide classes
14  for numerical calculus.
15 
16  This software is governed by the CeCILL license under French law and
17  abiding by the rules of distribution of free software. You can use,
18  modify and/ or redistribute the software under the terms of the CeCILL
19  license as circulated by CEA, CNRS and INRIA at the following URL
20  "http://www.cecill.info".
21 
22  As a counterpart to the access to the source code and rights to copy,
23  modify and redistribute granted by the license, users are provided only
24  with a limited warranty and the software's author, the holder of the
25  economic rights, and the successive licensors have only limited
26  liability.
27 
28  In this respect, the user's attention is drawn to the risks associated
29  with loading, using, modifying and/or developing or reproducing the
30  software by the user in light of its specific status of free software,
31  that may mean that it is complicated to manipulate, and that also
32  therefore means that it is reserved for developers and experienced
33  professionals having in-depth computer knowledge. Users are therefore
34  encouraged to load and test the software's suitability as regards their
35  requirements in conditions enabling the security of their systems and/or
36  data to be ensured and, more generally, to use and operate it in the
37  same conditions as regards security.
38 
39  The fact that you are presently reading this means that you have had
40  knowledge of the CeCILL license and that you accept its terms.
41 */
42 
43 #ifndef BPP_NUMERIC_VECTOREXCEPTIONS_H
44 #define BPP_NUMERIC_VECTOREXCEPTIONS_H
45 
46 #include <string>
47 #include <vector>
48 
49 #include "../Exceptions.h"
50 
51 namespace bpp
52 {
54 template<class T>
55 class VectorException : public Exception
56 {
57 protected:
58  const std::vector<T>* vect_;
59 
60 public:
61  VectorException(const std::string& text, const std::vector<T>* vect = nullptr)
62  : Exception("VectorException: " + text)
63  , vect_(vect){}
64  VectorException(const VectorException&) = default;
66 
67  const std::vector<T>* getVector() const { return vect_; }
68 };
69 
71 template<class T>
73 {
74 public:
75  EmptyVectorException(const std::string& text, const std::vector<T>* vect = nullptr)
76  : VectorException<T>("EmptyVectorException: " + text, vect){}
77 };
78 
81 {
82 private:
83  std::size_t dimension_;
84  std::size_t correctDimension_;
85 
86 public:
87  DimensionException(const std::string& text, size_t dimension, size_t correctDimension)
88  : Exception("DimensionException (found " + std::to_string(dimension) + ", should be " +
89  std::to_string(correctDimension) + ") " + text)
90  , dimension_(dimension)
91  , correctDimension_(correctDimension){}
92 
93  size_t getDimension() const { return dimension_; }
94  size_t getCorrectDimension() const { return correctDimension_; }
95 };
96 
98 template<class T>
100 {
101 private:
102  const T* element_;
103 
104 public:
105  ElementNotFoundException(const std::string& text, const std::vector<T>* vect = nullptr, const T* element = nullptr)
106  : VectorException<T>("ElementNotFoundException: " + text, vect)
107  , element_(element)
108  {}
111 
112  const T* getElement() const { return element_; }
113 };
114 } // end of namespace bpp.
115 #endif // BPP_NUMERIC_VECTOREXCEPTIONS_H
Exception thrown when a dimension problem occured.
DimensionException(const std::string &text, size_t dimension, size_t correctDimension)
size_t getCorrectDimension() const
size_t getDimension() const
Exception thrown when a given element was not found in the vector.
ElementNotFoundException & operator=(const ElementNotFoundException &)=default
ElementNotFoundException(const std::string &text, const std::vector< T > *vect=nullptr, const T *element=nullptr)
ElementNotFoundException(const ElementNotFoundException &)=default
Exception thrown when an empty vector was found.
EmptyVectorException(const std::string &text, const std::vector< T > *vect=nullptr)
Exception base class. Overload exception constructor (to control the exceptions mechanism)....
Definition: Exceptions.h:59
General Exception dealing with vectors.
const std::vector< T > * getVector() const
VectorException(const VectorException &)=default
VectorException & operator=(const VectorException &)=default
const std::vector< T > * vect_
VectorException(const std::string &text, const std::vector< T > *vect=nullptr)