blob: c0e73437853cc974edd147db4ea8925344b7cf13 [file] [log] [blame]
#include "{header}.h"
{{ if readwrite }}
#include <server_configurable_flags/get_flags.h>
{{ endif }}
{{ if for_test }}
#include <unordered_map>
{{ endif }}
namespace {cpp_namespace} \{
{{ if for_test }}
class flag_provider : public flag_provider_interface \{
private:
std::unordered_map<std::string, bool> overrides_;
public:
flag_provider()
: overrides_()
\{}
{{ for item in class_elements}}
virtual bool {item.flag_name}() override \{
auto it = overrides_.find("{item.flag_name}");
if (it != overrides_.end()) \{
return it->second;
} else \{
{{ if item.readwrite- }}
return server_configurable_flags::GetServerConfigurableFlag(
"aconfig_flags.{item.device_config_namespace}",
"{item.device_config_flag}",
"{item.default_value}") == "true";
{{ -else- }}
return {item.default_value};
{{ -endif }}
}
}
virtual void {item.flag_name}(bool val) override \{
overrides_["{item.flag_name}"] = val;
}
{{ endfor }}
virtual void reset_flags() override \{
overrides_.clear();
}
};
{{ -else- }}
class flag_provider : public flag_provider_interface \{
public:
{{ for item in class_elements}}
virtual bool {item.flag_name}() override \{
{{ if item.readwrite- }}
return server_configurable_flags::GetServerConfigurableFlag(
"aconfig_flags.{item.device_config_namespace}",
"{item.device_config_flag}",
"{item.default_value}") == "true";
{{ -else- }}
return {item.default_value};
{{ -endif }}
}
{{ endfor }}
};
{{ -endif }}
std::unique_ptr<flag_provider_interface> provider_ =
std::make_unique<flag_provider>();
}
{{ for item in class_elements}}
bool {header}_{item.flag_name}() \{
{{ if for_test }}
return {cpp_namespace}::{item.flag_name}();
{{ -else- }}
{{ if not item.readwrite- }}
return {item.default_value};
{{ -else- }}
return {cpp_namespace}::{item.flag_name}();
{{ -endif }}
{{ -endif }}
}
{{ if for_test }}
void set_{header}_{item.flag_name}(bool val) \{
{cpp_namespace}::{item.flag_name}(val);
}
{{ -endif }}
{{ endfor -}}
{{ if for_test }}
void {header}_reset_flags() \{
{cpp_namespace}::reset_flags();
}
{{ -endif }}