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.
32 lines
964 B
32 lines
964 B
#pragma once
|
|
|
|
#include <utility>
|
|
#include <functional>
|
|
#include <string>
|
|
#include <stdexcept>
|
|
|
|
#include "common.h"
|
|
#include <rngxx.hpp>
|
|
|
|
namespace rng::init
|
|
{
|
|
struct DCLookupFailed final : std::exception{ inline DCLookupFailed(const std::string_view& n) : std::exception(), name(std::move(n)){} std::string name; };
|
|
|
|
const std::function<Random* (const void*)>& apply_raw(std::string_view name, std::function<Random* (const void*)> fn) noexcept;
|
|
|
|
template<typename T, typename _Ptr = void>
|
|
inline auto apply(std::string_view name, auto&& lam) noexcept
|
|
{
|
|
return apply_raw(name, [lam](const void* seed) -> Random* {
|
|
return static_cast<Random*>(lam(reinterpret_cast<const _Ptr*>(seed)));
|
|
});
|
|
}
|
|
|
|
std::function<Random* (const void*)>& get(std::string_view name);
|
|
}
|
|
|
|
// To add to dynamic CTOR map
|
|
#define RNGXX_APPLY_CTOR(ns, T, TSeed) \
|
|
const auto RNGXX_DCTOR_NAME(T) = rng::init::apply<ns::T, TSeed>(#T, [](const TSeed* ptr) { return new ns::T(*ptr); })
|
|
|