gdpm/include/error.hpp
David J. Allen 8e82a22ebd Update API, README, added functions, and cleaned up implementations
- Changed the remote API
- Added `export` and changed `remote` commands
- Update README.md file
- Removed dependence on `zig c++` in `bin/build.sh` script
- Added error codes to use in place of ints
- Other minor changes
2023-05-12 22:27:45 -06:00

39 lines
806 B
C++

#include <string>
#include "log.hpp"
namespace gdpm::error_codes{
enum {
UNKNOWN = 0,
NOT_FOUND = 1,
};
inline std::string to_string(int error_code) {
return "";
}
};
namespace gdpm{
class error{
public:
error(int code = 0, const std::string& message = "", bool print_message = false):
m_code(code), m_message(message)
{
if(print_message)
print();
}
void set_code(int code) { m_code = code; }
void set_message(const std::string& message) { m_message = message; }
int get_code() const { return m_code; }
std::string get_message() const { return m_message; }
bool has_error() const { return m_code != 0; }
void print(){ log::println(GDPM_COLOR_LOG_ERROR "ERROR: {}" GDPM_COLOR_LOG_RESET, m_message); }
private:
int m_code;
std::string m_message;
};
}