You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
883 B
42 lines
883 B
#include <unordered_map>
|
|
#include <string>
|
|
|
|
#include <init.hpp>
|
|
|
|
using ctor_map = std::unordered_map<std::string_view, std::function<Random* (const void*)>>;
|
|
|
|
static ctor_map* INIT_MAP=nullptr;
|
|
|
|
namespace rng::init
|
|
{
|
|
const std::function<Random* (const void*)>& apply_raw(std::string_view name, std::function<Random* (const void*)> fn) noexcept
|
|
{
|
|
if(!INIT_MAP) INIT_MAP = new ctor_map();
|
|
|
|
auto& map = *INIT_MAP;
|
|
map[name] = std::move(fn);
|
|
return map[name];
|
|
}
|
|
|
|
std::function<Random* (const void*)>& get(std::string_view name)
|
|
{
|
|
if(UNLIKELY(!INIT_MAP)) throw DCLookupFailed ( name );
|
|
auto& map = *INIT_MAP;
|
|
if(map.contains(name)) return map[name];
|
|
else throw DCLookupFailed ( name );
|
|
}
|
|
|
|
|
|
namespace {
|
|
__attribute__((destructor))
|
|
static void _rng_ctor__fini() noexcept{
|
|
if(LIKELY(INIT_MAP)) {
|
|
delete INIT_MAP;
|
|
INIT_MAP = nullptr;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|