1 #ifndef LIB_VCSN_ALGOS_REGISTRY_HH
2 # define LIB_VCSN_ALGOS_REGISTRY_HH
19 template <
typename Fun>
32 bool debug = getenv(
"VCSN_DYN");
38 std::cerr <<
"Register(" <<
name_ <<
").set(" << sig <<
")\n";
47 std::cerr <<
"Register(" <<
name_ <<
").get(" << sig <<
")\n";
48 auto i =
map_.find(sig);
59 res +=
" failed signature:\n";
61 res +=
" available versions:\n";
63 res +=
" " + p.first.to_string() +
"\n";
71 if (
auto fun =
get0(sig))
82 ": compilation succeeded, but function is unavailable\n",
89 ?
name_ +
": no such implementation\n"
98 template <
typename... Args>
101 -> decltype(std::declval<Fun>()(args...))
103 return (
get(sig))(std::forward<Args>(args)...);
106 template <
typename... Args>
109 -> decltype(std::declval<Fun>()(args...))
112 std::forward<Args>(args)...);
115 template <
typename T>
118 -> decltype(std::declval<Fun>()(ts))
121 for (
const auto& t: ts)
123 return (
get(sig))(ts);
130 using map_t = std::map<signature, Fun*>;
138 # define REGISTER_DEFINE(Name) \
142 Registry<Name ## _t>& \
143 Name ## _registry() \
145 static Registry<Name ## _t> instance{#Name}; \
150 Name ## _register(const signature& sig, Name ## _t fn) \
152 return Name ## _registry().set(sig, fn); \
156 #endif // !LIB_VCSN_ALGOS_REGISTRY_HH
An exception suited for our compilation errors.
bool debug
Whether log messages should be issued.
void compile(const std::string &ctx)
Compile, and load, a DSO with instantiations for ctx.
std::string name_
Function name (e.g., "determinize").
auto call(const signature &sig, Args &&...args) -> decltype(std::declval< Fun >()(args...))
Call function for signature sig.
signature vsignature(Args &&...args)
The signature of (Args...).
std::string signatures(const signature &sig) const
A message about a failed signature compilation.
std::map< signature, Fun * > map_t
Context name -> pointer to implementation.
Signature of a function call.
bool set(const signature &sig, Fun fn)
Register function fn for signature sig.
auto call(Args &&...args) -> decltype(std::declval< Fun >()(args...))
const Fun * get0(const signature &sig)
Get function for signature sig.
std::string assertions
If defined, static assertions that failed (ends with a eol).
Registry(const std::string &name)
Create a register for an algorithm.
auto call_variadic(const std::vector< T > &ts) -> decltype(std::declval< Fun >()(ts))
void require(bool b, Args &&...args)
If b is not verified, raise an error with args as message.
std::string to_string() const