sdskv-common.hpp 982 Bytes
Newer Older
1 2 3
#ifndef __SDSKV_COMMON_HPP
#define __SDSKV_COMMON_HPP

Matthieu Dorier's avatar
Matthieu Dorier committed
4 5
#include <sdskv-common.h>

6 7
namespace sdskv {

Matthieu Dorier's avatar
Matthieu Dorier committed
8
const char* const sdskv_error_messages[] = {
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
    "",
    "Allocation error",
    "Invalid argument",
    "Mercury error",
    "Could not create database",
    "Invalid database name",
    "Invalid database id",
    "Invalid provider id",
    "Error writing in the database",
    "Unknown key",
    "Provided buffer size too small",
    "Error erasing from the database",
    "Migration error",
    "Function not implemented",
    "Invalid comparison function",
    "REMI error",
    "Argobots error"
};

class exception : public std::exception {

    std::string m_msg;
    int m_error;

    public:

    exception(int error)
    : m_msg(std::string("[SDSKV] ") + sdskv_error_messages[-error])
    , m_error(error) {}

Matthieu Dorier's avatar
Matthieu Dorier committed
39
    virtual const char* what() const noexcept override {
40 41 42 43 44 45 46 47 48 49 50
        return m_msg.c_str();
    }

    int error() const {
        return m_error;
    }
};

}

#endif