Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions include/cpp_lmdb/environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class environment_base {
cmp<typename KeyValueTrait::key_trait>));
}

if constexpr (key_value_trait_helper<
KeyValueTrait>::has_value_cmp_fun) {
if constexpr (
key_value_trait_helper<KeyValueTrait>::has_value_cmp_fun) {
LMDB_CALL_API(api.mdb_set_dupsort(
transaction->get(),
db_index,
Expand Down Expand Up @@ -179,8 +179,8 @@ template <
auto make_environment(
char const *const environment_path,
db_file_mode_t const db_file_mode,
LmdbApi &&api = LmdbApi{})
LMDB_NOEXCEPT->LMDB_RESULT((environment_t<is_readonly(flags), LmdbApi>))
LmdbApi &&api = LmdbApi{}) noexcept
-> std::expected<environment_t<is_readonly(flags), LmdbApi>, error_t>
{
MDB_env *env{nullptr};
LMDB_CALL_API(api.mdb_env_create(&env));
Expand Down
63 changes: 1 addition & 62 deletions include/cpp_lmdb/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "lmdb.h"

// std
#include <exception>
#include <expected>

namespace lmdb
Expand Down Expand Up @@ -32,70 +31,10 @@ enum class error_t : int {
bad_dbi = MDB_BAD_DBI,
};

#ifdef CPP_LMDB_EXCEPTIONS_ENABLED

class lmdb_exception : public std::exception {
public:
lmdb_exception(error_t error) noexcept : _error{error}
{}

auto what() const noexcept -> char const* override
{
return "";
}

auto error() const noexcept -> error_t
{
return _error;
}

private:
error_t _error;
};

#endif // CPP_LMDB_EXCEPTIONS_ENABLED

} // namespace lmdb

template <typename T>
struct extract_parantesized_arg;
template <typename T, typename A>
struct extract_parantesized_arg<T(A)> {
using arg = A;
};

#ifdef CPP_LMDB_EXCEPTIONS_ENABLED

#define LMDB_RESULT(res_type) \
typename extract_parantesized_arg<void(res_type)>::arg
#define LMDB_NOEXCEPT
// #define LMDB_NOEXCEPT_COND(cond) noexcept(cond)

#define LMDB_REPORT_ERROR(code) \
throw ::lmdb::lmdb_exception \
{ \
code \
}

#else

#define LMDB_RESULT(res_type) \
std::expected< \
typename extract_parantesized_arg<void(res_type)>::arg, \
::lmdb::error_t>

#define LMDB_NOEXCEPT noexcept

#define LMDB_REPORT_ERROR(code) \
return std::unexpected \
{ \
code \
}

#endif

#define LMDB_CALL_API(expr) \
do { \
if (auto const result = (expr); result != MDB_SUCCESS) \
LMDB_REPORT_ERROR(::lmdb::error_t{result}); \
return std::unexpected{::lmdb::error_t{result}}; \
} while (false)
2 changes: 0 additions & 2 deletions test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ add_executable(
test_environment.cpp
test_transaction.cpp
test_key_value_traits.cpp
test_error_handling_exceptions.cpp
test_error_handling_expected.cpp
)

enable_testing()
Expand Down
58 changes: 0 additions & 58 deletions test/unit/test_error_handling_exceptions.cpp

This file was deleted.

65 changes: 0 additions & 65 deletions test/unit/test_error_handling_expected.cpp

This file was deleted.

Loading