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.cpp
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 #include "eptexception.h"
21 #include <sstream>
22 #include "../system/log.h"
23 
24 EptException::EptException(int num, const std::string& desc, const std::string& src) :
25  mLine( 0 ),
26  mNumber( num ),
27  mDescription( desc ),
28  mSource( src )
29 {
30  if (Log::getSingletonPtr()) {
31  Log::error(desc.c_str(), 0, src.c_str(), "unknown");
32  }
33 }
34 
35 EptException::EptException(int num, const std::string& desc, const std::string& src, const char* fil, long lin) :
36  mLine( lin ),
37  mNumber( num ),
38  mTypeName(toString(num)),
39  mDescription( desc ),
40  mSource( src ),
41  mFile( fil )
42 {
43  if (Log::getSingletonPtr()) {
44  Log::error(getFullDescription().c_str(), mLine, mSource.c_str(), mFile.c_str());
45  }
46 }
47 
48 const std::string& EptException::getFullDescription(void) const
49 {
50  if (mFullDesc.empty())
51  {
52 
53  std::stringstream desc;
54 
55  desc << "EPT EXCEPTION(" << mNumber << ":" << mTypeName << "): "
56  << mDescription
57  << " in " << mSource;
58 
59  if( mLine > 0 )
60  {
61  desc << " at " << mFile << " (mLine " << mLine << ")";
62  }
63 
64  mFullDesc = desc.str();
65  }
66 
67  return mFullDesc;
68 }
69 
70 int EptException::getNumber(void) const throw()
71 {
72  return mNumber;
73 }
74 
75 std::string EptException::toString(int code) {
76  switch (code) {
77  case ERR_CANNOT_WRITE_TO_FILE: return "ErrCannotWriteToFile";
78  case ERR_CANNOT_READ_FROM_FILE: return "ErrCannotReadFromFile";
79  case ERR_INVALID_STATE: return "ErrInvalidState";
80  case ERR_INVALIDPARAMS: return "ErrInvalidParams";
81  case ERR_RENDERINGAPI_ERROR: return "ErrRenderingApiError";
82  case ERR_INTERNAL_ERROR: return "ErrInternalError";
83  case ERR_RT_ASSERTION_FAILED: return "ErrRtAssertionFailed";
85  default:
86  return "ErrNotInplemented";
87  }
88 }
static std::string toString(int code)
static void error(const char *text, int line, const char *file, const char *function)
Definition: log.cpp:90
std::string mFile
Definition: eptexception.h:59
virtual int getNumber(void) const
Gets the error code.
std::string mFullDesc
Definition: eptexception.h:60
static Log * getSingletonPtr()
Definition: log.h:92
std::string mSource
Definition: eptexception.h:58
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.