mdbx++: добавление перегрузок со std::string_view для методов open_map/create_map_/drop_map/clear_map/rename_map().

This commit is contained in:
Леонид Юрьев (Leonid Yuriev)
2024-03-30 17:38:53 +03:00
parent cce5c8249c
commit e9a49e3715
2 changed files with 182 additions and 20 deletions

View File

@@ -1605,12 +1605,83 @@ __cold bool txn::rename_map(const char *old_name, const char *new_name,
}
}
#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
__cold bool txn::drop_map(const ::std::string_view &name,
bool throw_if_absent) {
map_handle map;
const int err =
::mdbx_dbi_open2(handle_, mdbx::slice(name), MDBX_DB_ACCEDE, &map.dbi);
switch (err) {
case MDBX_SUCCESS:
drop_map(map);
return true;
case MDBX_NOTFOUND:
case MDBX_BAD_DBI:
if (!throw_if_absent)
return false;
MDBX_CXX17_FALLTHROUGH /* fallthrough */;
default:
MDBX_CXX20_UNLIKELY error::throw_exception(err);
}
}
__cold bool txn::clear_map(const ::std::string_view &name,
bool throw_if_absent) {
map_handle map;
const int err =
::mdbx_dbi_open2(handle_, mdbx::slice(name), MDBX_DB_ACCEDE, &map.dbi);
switch (err) {
case MDBX_SUCCESS:
clear_map(map);
return true;
case MDBX_NOTFOUND:
case MDBX_BAD_DBI:
if (!throw_if_absent)
return false;
MDBX_CXX17_FALLTHROUGH /* fallthrough */;
default:
MDBX_CXX20_UNLIKELY error::throw_exception(err);
}
}
__cold bool txn::rename_map(const ::std::string_view &old_name,
const ::std::string_view &new_name,
bool throw_if_absent) {
map_handle map;
const int err = ::mdbx_dbi_open2(handle_, mdbx::slice(old_name),
MDBX_DB_ACCEDE, &map.dbi);
switch (err) {
case MDBX_SUCCESS:
rename_map(map, new_name);
return true;
case MDBX_NOTFOUND:
case MDBX_BAD_DBI:
if (!throw_if_absent)
return false;
MDBX_CXX17_FALLTHROUGH /* fallthrough */;
default:
MDBX_CXX20_UNLIKELY error::throw_exception(err);
}
}
__cold bool txn::rename_map(const ::std::string &old_name,
const ::std::string &new_name,
bool throw_if_absent) {
return rename_map(::std::string_view(old_name), ::std::string_view(new_name),
throw_if_absent);
}
#else
__cold bool txn::rename_map(const ::std::string &old_name,
const ::std::string &new_name,
bool throw_if_absent) {
return rename_map(old_name.c_str(), new_name.c_str(), throw_if_absent);
}
#endif /* __cpp_lib_string_view >= 201606L */
//------------------------------------------------------------------------------
void cursor_managed::close() {