16 inline void gather_types(eval::AlgorithmTypes& target, std::vector<Meta>&& metas);
40 std::vector<decl::Arg> m_options;
42 ast::Value m_static_args;
44 std::vector<Meta> m_sub_metas;
46 inline void check_arg(
const std::string& argument_name) {
47 for (
auto& e : m_options) {
48 if (e.name() == argument_name) {
49 throw std::runtime_error(
"argument already defined");
54 friend inline void gather_types(eval::AlgorithmTypes& target,
67 const std::string&
name,
68 const std::string& doc =
""):
73 m_static_args(ast::Value(
std::string(name), {}))
81 std::string m_argument_name;
86 m_meta(meta), m_argument_name(argument_name) {}
93 inline void templated(
const std::string& accepted_type) {
96 m_meta.check_arg(m_argument_name);
97 Meta sub_meta = T::meta();
98 m_meta.m_sub_metas.push_back(sub_meta);
100 auto type = std::move(sub_meta.m_type);
102 m_meta.m_static_args.invokation_arguments().push_back(ast::Arg(
103 std::string(m_argument_name),
104 std::move(sub_meta).build_static_args_ast_value()
107 m_meta.m_options.push_back(decl::Arg(
108 std::string(m_argument_name),
125 template<
class T,
class D>
126 inline void templated(
const std::string& accepted_type) {
127 templated<T>(accepted_type);
129 std::string t_type = m_meta.m_options.back().type();
130 m_meta.m_options.pop_back();
132 Meta sub_meta = D::meta();
133 std::string d_type = sub_meta.m_type;
134 m_meta.m_sub_metas.push_back(sub_meta);
136 DCHECK_EQ(t_type, d_type);
138 m_meta.m_options.push_back(decl::Arg(
139 std::string(m_argument_name),
141 std::move(sub_meta.m_type),
142 std::move(sub_meta).build_ast_value_for_default()
151 m_meta.check_arg(m_argument_name);
152 m_meta.m_options.push_back(decl::Arg(
153 std::string(m_argument_name),
162 inline void dynamic(
const std::string& default_value) {
163 m_meta.check_arg(m_argument_name);
164 m_meta.m_options.push_back(decl::Arg(
165 std::string(m_argument_name),
168 ast::Value(std::string(default_value))
174 inline void dynamic(
const char* default_value) {
175 dynamic(std::string(default_value));
183 dynamic(default_value ?
"true" :
"false");
204 m_meta.check_arg(m_argument_name);
205 m_meta.m_options.push_back(decl::Arg(
206 std::string(m_argument_name),
222 inline decl::Algorithm build_def() && {
223 return decl::Algorithm(
225 std::move(m_options),
231 inline ast::Value build_ast_value_for_default() && {
232 std::vector<ast::Arg> options;
233 for (
auto& arg : m_options) {
234 options.push_back(ast::Arg(
236 std::move(arg.default_value())
240 return ast::Value(std::move(m_name), std::move(options));
243 inline ast::Value build_static_args_ast_value() && {
244 return std::move(m_static_args);
251 inline const std::string&
name()
const {
257 inline const std::string&
type()
const {
276 template<
typename text_t>
296 auto& target_type_algos = target[meta.type()];
300 auto decl_value = std::move(meta).build_def();
303 for (
auto& already_seen_algo : target_type_algos) {
304 if (already_seen_algo.name() == decl_value.name()) {
305 if (already_seen_algo != decl_value) {
306 std::stringstream ss;
307 ss <<
"Attempting to register the same algorithm twice";
308 ss <<
" with differing details:";
309 ss <<
" new: " << decl_value;
310 ss <<
" existing: " << already_seen_algo;
311 throw std::runtime_error(ss.str());
320 target_type_algos.push_back(std::move(decl_value));
327 std::vector<Meta>&& metas)
329 for (
auto& meta : metas) {
Contains the text compression and encoding framework.
std::string to_str(const T &v)
Represent a value as a string.