bpp-seq3  3.0.0
AlphabetExceptions.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #include <Bpp/Text/TextTools.h>
6 
7 #include "Alphabet.h"
8 #include "AlphabetExceptions.h"
9 
10 using namespace bpp;
11 
12 using namespace std;
13 
14 /******************************************************************************
15 * Alphabet exceptions: *
16 ******************************************************************************/
17 
18 AlphabetException::AlphabetException(const std::string& text, const Alphabet* alpha) :
19  Exception("AlphabetException: " + text + "(" + (alpha->getAlphabetType()) + ")"),
20  alphabet_(alpha) {}
21 
22 AlphabetException::AlphabetException(const std::string& text, shared_ptr<const Alphabet> alpha) :
23  Exception("AlphabetException: " + text + "(" + (alpha->getAlphabetType()) + ")"),
24  alphabet_(alpha.get()) {}
25 
26 /******************************************************************************/
27 
28 BadCharException::BadCharException(const std::string& badChar, const std::string& text, const Alphabet* alpha) :
29  AlphabetException("BadCharException: " + badChar + ". " + text, alpha),
30  c_(badChar) {}
31 
32 BadCharException::BadCharException(const std::string& badChar, const std::string& text, shared_ptr<const Alphabet> alpha) :
33  AlphabetException("BadCharException: " + badChar + ". " + text, alpha),
34  c_(badChar) {}
35 
36 string BadCharException::getBadChar() const { return c_; }
37 
38 /******************************************************************************/
39 
40 BadIntException::BadIntException(int badInt, const std::string& text, const Alphabet* alpha) :
41  AlphabetException("BadIntException: " + TextTools::toString(badInt) + ". " + text, alpha),
42  i_(badInt) {}
43 
44 BadIntException::BadIntException(int badInt, const std::string& text, shared_ptr<const Alphabet> alpha) :
45  AlphabetException("BadIntException: " + TextTools::toString(badInt) + ". " + text, alpha),
46  i_(badInt) {}
47 
48 int BadIntException::getBadInt() const { return i_; }
49 
50 /******************************************************************************/
51 
52 AlphabetMismatchException::AlphabetMismatchException(const std::string& text, const Alphabet* alpha1, const Alphabet* alpha2) :
53  Exception("AlphabetMismatchException: " + text + "(" + alpha1->getAlphabetType() + ", " + alpha2->getAlphabetType() + ")"),
54  alphabet1_(alpha1),
55  alphabet2_(alpha2) {}
56 
57 /******************************************************************************/
58 
59 AlphabetMismatchException::AlphabetMismatchException(const std::string& text, shared_ptr<const Alphabet> alpha1, shared_ptr<const Alphabet> alpha2) :
60  Exception("AlphabetMismatchException: " + text + "(" + alpha1->getAlphabetType() + ", " + alpha2->getAlphabetType() + ")"),
61  alphabet1_(alpha1.get()),
62  alphabet2_(alpha2.get()) {}
63 
64 /******************************************************************************/
65 
67  AlphabetException("CharStateNotSupportedException: " + text, alpha) {}
68 
69 /******************************************************************************/
70 
71 CharStateNotSupportedException::CharStateNotSupportedException(const string& text, shared_ptr<const Alphabet> alpha) :
72  AlphabetException("CharStateNotSupportedException: " + text, alpha) {}
73 
74 /******************************************************************************/
The alphabet exception base class.
AlphabetException(const std::string &text, const Alphabet *alpha)
Build a new AlphabetException object.
AlphabetMismatchException(const std::string &text, const Alphabet *alpha1, const Alphabet *alpha2)
Build a new AlphabetMismatchException object.
The Alphabet interface.
Definition: Alphabet.h:99
virtual std::string getBadChar() const
Get the character that threw the exception.
BadCharException(const std::string &badChar, const std::string &text, const Alphabet *alpha)
Build a new BadCharException.
virtual int getBadInt() const
Get the integer that threw the exception.
BadIntException(int badInt, const std::string &text, const Alphabet *alpha)
Build a new BadIntException.
CharStateNotSupportedException(const std::string &text, const Alphabet *alpha)
Build a new CharStateNotSupportedException.
std::string toString(T t)
This alphabet is used to deal NumericAlphabet.