/* * LMDB Abstraction Layer. * Copyright (C) 2023 Yury Gubich * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "exceptions.h" LMDBAL::Exception::Exception(): std::exception() {} LMDBAL::Exception::~Exception() {} const char* LMDBAL::Exception::what() const noexcept( true ) { std::string* msg = new std::string(getMessage()); return msg->c_str(); } LMDBAL::Directory::Directory(const std::string& p_path): Exception(), path(p_path) {} std::string LMDBAL::Directory::getMessage() const { return "Can't create directory for database at " + path;} LMDBAL::Closed::Closed( const std::string& p_operation, const std::string& p_dbName, const std::optional& p_tableName ): Exception(), operation(p_operation), dbName(p_dbName), tableName(p_tableName) {} std::string LMDBAL::Closed::getMessage() const { std::string msg = "An attempt to perform operation " + operation + " on closed database " + dbName; if (tableName.has_value()) msg += + " on table " + tableName.value(); return msg; } LMDBAL::Opened::Opened(const std::string& p_dbName, const std::string& p_action): Exception(), dbName(p_dbName), action(p_action) {} std::string LMDBAL::Opened::getMessage() const { return "An attempt to " + action + " (the database " + dbName + ") but it's can't be done because the Base is already opened"; } LMDBAL::NotFound::NotFound( const std::string& p_key, const std::string& p_dbName, const std::string& p_tableName ): Exception(), key(p_key), dbName(p_dbName), tableName(p_tableName) {} std::string LMDBAL::NotFound::getMessage() const { return "Element for id " + key + " wasn't found " + " in database " + dbName + " in table " + tableName;} LMDBAL::StorageDuplicate::StorageDuplicate( const std::string& p_dbName, const std::string& p_tableName ): dbName(p_dbName), tableName(p_tableName) {} std::string LMDBAL::StorageDuplicate::getMessage() const { return "An attempt to add a storage (or cache) " + tableName + " to database " + dbName + " but the database already has a storage with given name"; } LMDBAL::Exist::Exist( const std::string& p_key, const std::string& p_dbName, const std::string& p_tableName ): Exception(), key(p_key), dbName(p_dbName), tableName(p_tableName) {} std::string LMDBAL::Exist::getMessage() const { return "An attempt to insert element with key " + key + " to database " + dbName + " to table " + tableName + " but it already has an element with given id"; } LMDBAL::Unknown::Unknown( const std::string& p_dbName, const std::string& message, const std::optional& p_tableName ): Exception(), dbName(p_dbName), tableName(p_tableName), msg(message) {} std::string LMDBAL::Unknown::getMessage() const { std::string result = "Unknown error in database " + dbName; if (tableName.has_value()) result += " in table " + tableName.value(); result += ": " + msg; return result; }