Added automagic constructor inheritance.
This commit is contained in:
parent
3ac76f1fac
commit
3f0486b889
@ -23,6 +23,29 @@ typedef std::unordered_map<unsigned int, const char*> ErrorCodeMap;
|
|||||||
template<class ErrorType>
|
template<class ErrorType>
|
||||||
class ErrorBase : public std::exception {
|
class ErrorBase : public std::exception {
|
||||||
public:
|
public:
|
||||||
|
ErrorBase(
|
||||||
|
const unsigned int code,
|
||||||
|
unsigned int line=0,
|
||||||
|
std::string filename=""
|
||||||
|
) noexcept : ErrorBase(
|
||||||
|
code,
|
||||||
|
ErrorBase<ErrorType>::lookup(code),
|
||||||
|
line,
|
||||||
|
filename
|
||||||
|
) {}
|
||||||
|
ErrorBase(
|
||||||
|
const unsigned int code,
|
||||||
|
const std::exception& trace,
|
||||||
|
unsigned int line=0,
|
||||||
|
std::string filename=""
|
||||||
|
) noexcept : ErrorBase(
|
||||||
|
code,
|
||||||
|
ErrorBase<ErrorType>::lookup(code),
|
||||||
|
trace,
|
||||||
|
line,
|
||||||
|
filename
|
||||||
|
) {}
|
||||||
|
|
||||||
static std::string lookup(unsigned int);
|
static std::string lookup(unsigned int);
|
||||||
unsigned int code() const noexcept {
|
unsigned int code() const noexcept {
|
||||||
return static_cast<const ErrorType*>(this)->_code;
|
return static_cast<const ErrorType*>(this)->_code;
|
||||||
@ -71,29 +94,6 @@ protected:
|
|||||||
}
|
}
|
||||||
_msg += "\n Trace: " + what_msg;
|
_msg += "\n Trace: " + what_msg;
|
||||||
}
|
}
|
||||||
ErrorBase(
|
|
||||||
const unsigned int code,
|
|
||||||
unsigned int line=0,
|
|
||||||
std::string filename=""
|
|
||||||
) noexcept : ErrorBase(
|
|
||||||
code,
|
|
||||||
ErrorBase<ErrorType>::lookup(code),
|
|
||||||
line,
|
|
||||||
filename
|
|
||||||
) {}
|
|
||||||
|
|
||||||
ErrorBase(
|
|
||||||
const unsigned int code,
|
|
||||||
const std::exception& trace,
|
|
||||||
unsigned int line=0,
|
|
||||||
std::string filename=""
|
|
||||||
) noexcept : ErrorBase(
|
|
||||||
code,
|
|
||||||
ErrorBase<ErrorType>::lookup(code),
|
|
||||||
trace,
|
|
||||||
line,
|
|
||||||
filename
|
|
||||||
) {}
|
|
||||||
|
|
||||||
unsigned int _code;
|
unsigned int _code;
|
||||||
std::string _msg;
|
std::string _msg;
|
||||||
@ -105,9 +105,10 @@ public:
|
|||||||
GENERAL, UNDEFINED, BADERRORCODE
|
GENERAL, UNDEFINED, BADERRORCODE
|
||||||
};
|
};
|
||||||
|
|
||||||
Error(unsigned int code) : ErrorBase<Error>(code, ErrorBase<Error>::lookup(code)) {}
|
using ErrorBase<Error>::ErrorBase;
|
||||||
Error(unsigned int code, const std::exception& trace, unsigned int line=0, const std::string& filename="")
|
//Error(unsigned int code) : ErrorBase<Error>(code, ErrorBase<Error>::lookup(code)) {}
|
||||||
: ErrorBase<Error>(code, ErrorBase<Error>::lookup(code), trace, line, filename) {}
|
//Error(unsigned int code, const std::exception& trace, unsigned int line=0, const std::string& filename="")
|
||||||
|
// : ErrorBase<Error>(code, ErrorBase<Error>::lookup(code), trace, line, filename) {}
|
||||||
|
|
||||||
friend ErrorBase<Error>;
|
friend ErrorBase<Error>;
|
||||||
|
|
||||||
|
|||||||
@ -7,11 +7,13 @@ using namespace nb;
|
|||||||
|
|
||||||
class TestError : public ErrorBase<TestError> {
|
class TestError : public ErrorBase<TestError> {
|
||||||
public:
|
public:
|
||||||
TestError(unsigned int code, unsigned int line=0, const std::string& filename="")
|
//TestError(unsigned int code, unsigned int line=0, const std::string& filename="")
|
||||||
: ErrorBase<TestError>(code, ErrorBase<TestError>::lookup(code)) {}
|
// : ErrorBase<TestError>(code, ErrorBase<TestError>::lookup(code)) {}
|
||||||
TestError(unsigned int code, const std::exception& trace, unsigned int line=0, const std::string& filename="")
|
//TestError(unsigned int code, const std::exception& trace, unsigned int line=0, const std::string& filename="")
|
||||||
: ErrorBase<TestError>(code, ErrorBase<TestError>::lookup(code), trace, line, filename) {}
|
// : ErrorBase<TestError>(code, ErrorBase<TestError>::lookup(code), trace, line, filename) {}
|
||||||
|
|
||||||
|
using ErrorBase<TestError>::ErrorBase;
|
||||||
|
|
||||||
enum ErrorCodes : unsigned int {
|
enum ErrorCodes : unsigned int {
|
||||||
A, B, C, D
|
A, B, C, D
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user