6 #include <boost/range/algorithm/sort.hpp>
20 template <
typename Fun>
33 bool debug = getenv(
"VCSN_DYN");
39 std::cerr <<
"Register(" <<
name_ <<
").set(" << sig <<
")\n";
48 std::cerr <<
"Register(" <<
name_ <<
").get(" << sig <<
")\n";
49 auto i =
map_.find(sig);
59 auto sigs = std::vector<std::string>();
60 sigs.reserve(
map_.size());
62 sigs.emplace_back(p.first.to_string());
66 res +=
" failed signature:\n";
68 res +=
" available versions:\n";
70 res +=
" " + s +
"\n";
90 ?
name_ +
": no such implementation\n"
98 ": compilation succeeded, "
99 "but function is unavailable\n",
108 template <
typename... Args>
111 -> decltype(std::declval<Fun>()(args...))
113 return (
get(sig))(std::forward<Args>(args)...);
116 template <
typename... Args>
119 -> decltype(std::declval<Fun>()(args...))
122 std::forward<Args>(args)...);
129 using map_t = std::unordered_map<signature, Fun*>;
137 #define REGISTRY_DEFINE(Name) \
141 Registry<Name ## _t>& \
142 Name ## _registry() \
144 static Registry<Name ## _t> instance{#Name}; \
149 Name ## _register(const signature& sig, Name ## _t fn) \
151 return Name ## _registry().set(sig, fn); \
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...).
Registry(const std::string &name)
Create a register for an algorithm.
std::unordered_map< signature, Fun * > map_t
Signature -> pointer to implementation.
std::string name_
Function name (e.g., "determinize").
void compile(const std::string &ctx)
Compile, and load, a DSO with instantiations for ctx.
An exception suited for our compilation errors.
std::string to_string() const
#define VCSN_REQUIRE(Cond,...)
A macro similar to require.
bool debug
Whether log messages should be issued.
bool set(const signature &sig, Fun *fn)
Register function fn for signature sig.
auto sort(const Aut &a) -> permutation_automaton< Aut >
std::string assertions
If defined, static assertions that failed (ends with a eol).
std::string signatures(const signature &sig) const
A message about a failed signature compilation.
const Fun * get0(const signature &sig)
Get function for signature sig.
auto call(Args &&...args) -> decltype(std::declval< Fun >()(args...))
Signature of a function call.