summaryrefslogtreecommitdiff
path: root/src/options
diff options
context:
space:
mode:
authorGereon Kremer <nafur42@gmail.com>2021-06-02 15:21:22 +0200
committerGitHub <noreply@github.com>2021-06-02 15:21:22 +0200
commit66cdf5254bc58ecff335321478e73c8c0d6df296 (patch)
tree6b38ac130e7e05479c599e32b40c8c9b6c4acdb6 /src/options
parent6d359817283f196034d8e36d0b9c1f10fb16d644 (diff)
Remove `Options::operator[]` (#6649)
This PR removes the next heavily specialized template function Options::operator[] in favor of direct access to the option data.
Diffstat (limited to 'src/options')
-rw-r--r--src/options/mkoptions.py28
-rw-r--r--src/options/options_template.cpp1
-rw-r--r--src/options/options_template.h4
3 files changed, 8 insertions, 25 deletions
diff --git a/src/options/mkoptions.py b/src/options/mkoptions.py
index 91a5c32e0..c355ff436 100644
--- a/src/options/mkoptions.py
+++ b/src/options/mkoptions.py
@@ -129,16 +129,6 @@ TPL_OPTION_STRUCT_RW = \
type operator()() const;
}} thread_local {name};"""
-TPL_DECL_OP_BRACKET = \
-"""template <> const options::{name}__option_t::type& Options::operator[](
- options::{name}__option_t) const;"""
-
-TPL_IMPL_OP_BRACKET = TPL_DECL_OP_BRACKET[:-1] + \
-"""
-{{
- return {module}.{name};
-}}"""
-
TPL_DECL_WAS_SET_BY_USER = \
"""template <> bool Options::wasSetByUser(options::{name}__option_t) const;"""
@@ -151,10 +141,8 @@ TPL_IMPL_WAS_SET_BY_USER = TPL_DECL_WAS_SET_BY_USER[:-1] + \
# Option specific methods
TPL_IMPL_OP_PAR = \
-"""inline {name}__option_t::type {name}__option_t::operator()() const
-{{
- return Options::current()[*this];
-}}"""
+"""inline {type} {name}__option_t::operator()() const
+{{ return Options::current().{module}.{name}; }}"""
# Mode templates
TPL_DECL_MODE_ENUM = \
@@ -591,7 +579,6 @@ def codegen_module(module, dst_dir, tpl_module_h, tpl_module_cpp):
# Generate module specialization
default_decl.append(TPL_DECL_SET_DEFAULT.format(module=module.id, name=option.name, funcname=capoptionname, type=option.type))
- specs.append(TPL_DECL_OP_BRACKET.format(name=option.name))
specs.append(TPL_DECL_WAS_SET_BY_USER.format(name=option.name))
if option.long and option.type not in ['bool', 'void'] and \
@@ -606,14 +593,13 @@ def codegen_module(module, dst_dir, tpl_module_h, tpl_module_cpp):
module.id, option.long, option.type))
# Generate module inlines
- inls.append(TPL_IMPL_OP_PAR.format(name=option.name))
+ inls.append(TPL_IMPL_OP_PAR.format(module=module.id, name=option.name, type=option.type))
### Generate code for {module.name}_options.cpp
# Accessors
default_impl.append(TPL_IMPL_SET_DEFAULT.format(module=module.id, name=option.name, funcname=capoptionname, type=option.type))
- accs.append(TPL_IMPL_OP_BRACKET.format(module=module.id, name=option.name))
accs.append(TPL_IMPL_WAS_SET_BY_USER.format(module=module.id, name=option.name))
# Global definitions
@@ -872,17 +858,17 @@ def codegen_all_modules(modules, build_dir, dst_dir, tpl_options_h, tpl_options_
'if ({}) {{'.format(cond))
if option.type == 'bool':
getoption_handlers.append(
- 'return (*this)[options::{}] ? "true" : "false";'.format(option.name))
+ 'return options.{}.{} ? "true" : "false";'.format(module.id, option.name))
elif option.type == 'std::string':
getoption_handlers.append(
- 'return (*this)[options::{}];'.format(option.name))
+ 'return options.{}.{};'.format(module.id, option.name))
elif is_numeric_cpp_type(option.type):
getoption_handlers.append(
- 'return std::to_string((*this)[options::{}]);'.format(option.name))
+ 'return std::to_string(options.{}.{});'.format(module.id, option.name))
else:
getoption_handlers.append('std::stringstream ss;')
getoption_handlers.append(
- 'ss << (*this)[options::{}];'.format(option.name))
+ 'ss << options.{}.{};'.format(module.id, option.name))
getoption_handlers.append('return ss.str();')
getoption_handlers.append('}')
diff --git a/src/options/options_template.cpp b/src/options/options_template.cpp
index 251072ba5..0d6b7f01b 100644
--- a/src/options/options_template.cpp
+++ b/src/options/options_template.cpp
@@ -563,6 +563,7 @@ void Options::setOptionInternal(const std::string& key,
std::string Options::getOption(const std::string& key) const
{
Trace("options") << "Options::getOption(" << key << ")" << std::endl;
+ const Options& options = *this;
${getoption_handlers}$
throw UnrecognizedOptionException(key);
diff --git a/src/options/options_template.h b/src/options/options_template.h
index 6e28aad85..6ce77d7a1 100644
--- a/src/options/options_template.h
+++ b/src/options/options_template.h
@@ -124,10 +124,6 @@ public:
*/
void setOption(const std::string& key, const std::string& optionarg);
- /** Get the value of the given option. Const access only. */
- template <class T>
- const typename T::type& operator[](T) const;
-
/**
* Gets the value of the given option by key and returns value as a string.
*
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback