mirror of
https://github.com/matrix-construct/construct
synced 2024-09-28 19:58:53 +02:00
ircd::allocator: Add templated info get()/set() to suite.
This commit is contained in:
parent
210dc94521
commit
93ee6a9f04
1 changed files with 54 additions and 0 deletions
|
@ -43,6 +43,8 @@ namespace ircd::allocator
|
|||
string_view info(const mutable_buffer &, const string_view &opts = {});
|
||||
string_view get(const string_view &var, const mutable_buffer &val);
|
||||
string_view set(const string_view &var, const string_view &val, const mutable_buffer &cur = {});
|
||||
template<class T> T get(const string_view &var);
|
||||
template<class T> T set(const string_view &var, T val);
|
||||
bool trim(const size_t &pad = 0) noexcept; // malloc_trim(3)
|
||||
}
|
||||
|
||||
|
@ -773,3 +775,55 @@ allocator()
|
|||
{
|
||||
return ircd::allocator::twolevel<T, L0_SIZE>::allocator(*this);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T
|
||||
ircd::allocator::set(const string_view &var,
|
||||
T val)
|
||||
{
|
||||
const string_view in
|
||||
{
|
||||
reinterpret_cast<const char *>(std::addressof(val)),
|
||||
sizeof(val)
|
||||
};
|
||||
|
||||
const string_view &out
|
||||
{
|
||||
set(var, in, mutable_buffer
|
||||
{
|
||||
reinterpret_cast<char *>(std::addressof(val)),
|
||||
sizeof(val)
|
||||
})
|
||||
};
|
||||
|
||||
if(unlikely(size(out) != sizeof(val)))
|
||||
throw std::system_error
|
||||
{
|
||||
make_error_code(std::errc::no_such_file_or_directory)
|
||||
};
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T
|
||||
ircd::allocator::get(const string_view &var)
|
||||
{
|
||||
T val;
|
||||
const string_view &out
|
||||
{
|
||||
get(var, mutable_buffer
|
||||
{
|
||||
reinterpret_cast<char *>(std::addressof(val)),
|
||||
sizeof(val)
|
||||
})
|
||||
};
|
||||
|
||||
if(unlikely(size(out) != sizeof(val)))
|
||||
throw std::system_error
|
||||
{
|
||||
make_error_code(std::errc::no_such_file_or_directory)
|
||||
};
|
||||
|
||||
return val;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue