Entropy Piano Tuner  1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
eptexception.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2015 Haye Hinrichsen, Christoph Wick
3  *
4  * This file is part of Entropy Piano Tuner.
5  *
6  * Entropy Piano Tuner is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * Entropy Piano Tuner is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * Entropy Piano Tuner. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
20 #ifndef EPTEXCEPTION_H
21 #define EPTEXCEPTION_H
22 
23 #include <exception>
24 #include <assert.h>
25 #include <string>
26 #include "prerequisites.h"
27 #include "../config.h"
28 
29 // Check for assert mode
30 
31 // RELEASE_EXCEPTIONS mode
32 #if EPT_ASSERT_MODE == 1
33 # ifdef _DEBUG
34 # define EptAssert( a, b ) assert( (a) && (b) )
35 
36 # else
37 # define EptAssert( a, b ) if( !(a) ) EPT_EXCEPT( EptException::ERR_RT_ASSERTION_FAILED, (b), __func__ )
38 
39 # endif
40 
41 // EXCEPTIONS mode
42 #elif OGRE_ASSERT_MODE == 2
43 # define EptAssert( a, b ) if( !(a) ) EPT_EXCEPT( EptException::ERR_RT_ASSERTION_FAILED, (b), __func__ )
44 
45 // STANDARD mode
46 #else
47 # define EptAssert( a, b ) assert( (a) && (b) )
48 
49 #endif
50 
51 class EptException : public std::exception
52 {
53 protected:
54  long mLine;
55  int mNumber;
56  std::string mTypeName;
57  std::string mDescription;
58  std::string mSource;
59  std::string mFile;
60  mutable std::string mFullDesc;
61 public:
62 
73  };
74 
76  EptException( int number, const std::string& description, const std::string& source );
77 
79  EptException( int number, const std::string& description, const std::string& source, const char* file, long line );
80 
82  EptException(const EptException&) = default;
83 
85  ~EptException() throw() {}
86 
88  EptException& operator = (const EptException&) = default;
89 
91  virtual const std::string& getFullDescription(void) const;
92 
94  virtual int getNumber(void) const throw();
95 
97  virtual const std::string &getSource() const { return mSource; }
98 
100  virtual const std::string &getFile() const { return mFile; }
101 
103  virtual long getLine() const { return mLine; }
104 
106  virtual const std::string &getDescription(void) const { return mDescription; }
107 
109  const char* what() const throw() { return getFullDescription().c_str(); }
110 
111 private:
112  static std::string toString(int code);
113 
114 };
115 
116 
117 
118 #ifndef EPT_EXCEPT
119 #define EPT_EXCEPT(num, desc) throw EptException(num, desc, __func__, __FILE__, __LINE__ );
120 #endif
121 
122 #endif // EPTEXCEPTION_H
static std::string toString(int code)
virtual const std::string & getDescription(void) const
Returns a string with only the 'description' field of this exception.
Definition: eptexception.h:106
const char * what() const
Override std::exception::what.
Definition: eptexception.h:109
std::string mFile
Definition: eptexception.h:59
virtual int getNumber(void) const
Gets the error code.
~EptException()
Needed for compatibility with std::exception.
Definition: eptexception.h:85
EptException & operator=(const EptException &)=default
Assignment operator.
virtual long getLine() const
Gets line number.
Definition: eptexception.h:103
std::string mFullDesc
Definition: eptexception.h:60
virtual const std::string & getSource() const
Gets the source function.
Definition: eptexception.h:97
std::string mSource
Definition: eptexception.h:58
virtual const std::string & getFile() const
Gets source file name.
Definition: eptexception.h:100
std::string mTypeName
Definition: eptexception.h:56
std::string mDescription
Definition: eptexception.h:57
EptException(int number, const std::string &description, const std::string &source)
Default constructor.
virtual const std::string & getFullDescription(void) const
Returns a string with the full description of this error.