diff options
| author | jhurst <jhurst@cinecert.com> | 2015-11-10 19:40:55 +0000 |
|---|---|---|
| committer | jhurst <> | 2015-11-10 19:40:55 +0000 |
| commit | 02915821cfb49cb6851086f5d991cee58328102b (patch) | |
| tree | c71cb099421c6ecf71a5a5ac469ba5e7fcfc413d /src/KM_error.h | |
| parent | f758bec505d45084d2563f20514ab4a81b27283a (diff) | |
release
Diffstat (limited to 'src/KM_error.h')
| -rwxr-xr-x | src/KM_error.h | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/KM_error.h b/src/KM_error.h index 77a0846..8270cc0 100755 --- a/src/KM_error.h +++ b/src/KM_error.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2004-2014, John Hurst +Copyright (c) 2004-2015, John Hurst All rights reserved. Redistribution and use in source and binary forms, with or without @@ -34,6 +34,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef _KM_ERROR_H_ #define _KM_ERROR_H_ +#include <string> + #define KM_DECLARE_RESULT(sym, i, l) const Result_t RESULT_##sym = Result_t(i, #sym, l); namespace Kumu @@ -46,8 +48,7 @@ namespace Kumu class Result_t { int value; - const char* label; - const char* symbol; + std::string label, symbol, message; Result_t(); public: @@ -65,21 +66,26 @@ namespace Kumu static unsigned int End(); static const Result_t& Get(unsigned int); - Result_t(int v, const char* s, const char* l); + Result_t(int v, const std::string& s, const std::string& l); + Result_t(const Result_t& rhs); + const Result_t& operator=(const Result_t& rhs); ~Result_t(); + const Result_t operator()(const std::string& message) const; + const Result_t operator()(const int& line, const char* filename) const; + const Result_t operator()(const std::string& message, const int& line, const char* filename) const; + inline bool operator==(const Result_t& rhs) const { return value == rhs.value; } inline bool operator!=(const Result_t& rhs) const { return value != rhs.value; } - inline bool Success() const { return ( value >= 0 ); } + inline bool Success() const { return ! ( value < 0 ); } inline bool Failure() const { return ( value < 0 ); } inline int Value() const { return value; } inline operator int() const { return value; } - - inline const char* Label() const { return label; } - inline operator const char*() const { return label; } - - inline const char* Symbol() const { return symbol; } + inline const char* Label() const { return label.c_str(); } + inline operator const char*() const { return label.c_str(); } + inline const char* Symbol() const { return symbol.c_str(); } + inline const char* Message() const { return message.c_str(); } }; KM_DECLARE_RESULT(FALSE, 1, "Successful but not true."); @@ -122,7 +128,7 @@ namespace Kumu // See Result_t above for an explanation of RESULT_* symbols. # define KM_TEST_NULL(p) \ if ( (p) == 0 ) { \ - return Kumu::RESULT_PTR; \ + return Kumu::RESULT_PTR(__LINE__, __FILE__); \ } // Returns RESULT_PTR if the given argument is NULL. See Result_t @@ -133,7 +139,7 @@ namespace Kumu # define KM_TEST_NULL_STR(p) \ KM_TEST_NULL(p); \ if ( (p)[0] == '\0' ) { \ - return Kumu::RESULT_NULL_STR; \ + return Kumu::RESULT_NULL_STR(__LINE__, __FILE__); \ } // RESULT_STATE is ambiguous. Use these everywhere it is assigned to provide some context |
