bpp-core3  3.0.0
VectorExceptions.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_NUMERIC_VECTOREXCEPTIONS_H
6 #define BPP_NUMERIC_VECTOREXCEPTIONS_H
7 
8 #include <string>
9 #include <vector>
10 
11 #include "../Exceptions.h"
12 
13 namespace bpp
14 {
16 template<class T>
17 class VectorException : public Exception
18 {
19 protected:
20  const std::vector<T>* vect_;
21 
22 public:
23  VectorException(const std::string& text, const std::vector<T>* vect = nullptr)
24  : Exception("VectorException: " + text)
25  , vect_(vect){}
26  VectorException(const VectorException&) = default;
27  VectorException& operator=(const VectorException&) = default;
28 
29  const std::vector<T>* getVector() const { return vect_; }
30 };
31 
33 template<class T>
35 {
36 public:
37  EmptyVectorException(const std::string& text, const std::vector<T>* vect = nullptr)
38  : VectorException<T>("EmptyVectorException: " + text, vect){}
39 };
40 
43 {
44 private:
45  std::size_t dimension_;
46  std::size_t correctDimension_;
47 
48 public:
49  DimensionException(const std::string& text, size_t dimension, size_t correctDimension)
50  : Exception("DimensionException (found " + std::to_string(dimension) + ", should be " +
51  std::to_string(correctDimension) + ") " + text)
52  , dimension_(dimension)
53  , correctDimension_(correctDimension){}
54 
55  size_t getDimension() const { return dimension_; }
56  size_t getCorrectDimension() const { return correctDimension_; }
57 };
58 
60 template<class T>
62 {
63 private:
64  const T* element_;
65 
66 public:
67  ElementNotFoundException(const std::string& text, const std::vector<T>* vect = nullptr, const T* element = nullptr)
68  : VectorException<T>("ElementNotFoundException: " + text, vect)
69  , element_(element)
70  {}
73 
74  const T* getElement() const { return element_; }
75 };
76 } // end of namespace bpp.
77 #endif // BPP_NUMERIC_VECTOREXCEPTIONS_H
STL namespace.
Exception thrown when a given element was not found in the vector.
EmptyVectorException(const std::string &text, const std::vector< T > *vect=nullptr)
VectorException & operator=(const VectorException &)=default
const std::vector< T > * vect_
size_t getCorrectDimension() const
size_t getDimension() const
Exception thrown when an empty vector was found.
General Exception dealing with vectors.
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
Definition: Exceptions.h:20
ElementNotFoundException(const std::string &text, const std::vector< T > *vect=nullptr, const T *element=nullptr)
VectorException(const std::string &text, const std::vector< T > *vect=nullptr)
const std::vector< T > * getVector() const
DimensionException(const std::string &text, size_t dimension, size_t correctDimension)
Exception thrown when a dimension problem occured.