/*
-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
#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
class Result_t
{
int value;
- const char* label;
- const char* symbol;
+ std::string label, symbol, message;
Result_t();
public:
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.");
KM_DECLARE_RESULT(NOTAFILE, -19, "Filename not found.");
KM_DECLARE_RESULT(UNKNOWN, -20, "Unknown result code.");
KM_DECLARE_RESULT(DIR_CREATE, -21, "Unable to create directory.");
- // -22 is reserved
+ KM_DECLARE_RESULT(NOT_EMPTY, -22, "Unable to delete non-empty directory.");
+ // 23-100 are reserved
} // 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
# 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