aconfig: update cpp codegen to use static methods

Update c++ codegen to static methods interface.

Bug: b/279483801
Test: atest aconfig.test
Change-Id: I78da3bbca6240bee660c692807930d00f2242b0a
This commit is contained in:
Dennis Shen
2023-06-09 18:01:56 +00:00
parent a0c6f31ef7
commit 4f78f10015
2 changed files with 23 additions and 38 deletions

View File

@@ -134,18 +134,12 @@ mod tests {
namespace com::example { namespace com::example {
class my_flag_one { static const bool my_flag_one() {
public: return false;
virtual const bool value() {
return false;
}
} }
class my_flag_two { static const bool my_flag_two() {
public: return true;
virtual const bool value() {
return true;
}
} }
} }
@@ -201,24 +195,18 @@ mod tests {
namespace com::example { namespace com::example {
class my_flag_one { static const bool my_flag_one() {
public: return GetServerConfigurableFlag(
virtual const bool value() { "ns",
return GetServerConfigurableFlag( "com.example.my_flag_one",
"ns", "false") == "true";
"com.example.my_flag_one",
"false") == "true";
}
} }
class my_flag_two { static const bool my_flag_two() {
public: return GetServerConfigurableFlag(
virtual const bool value() { "ns",
return GetServerConfigurableFlag( "com.example.my_flag_two",
"ns", "true") == "true";
"com.example.my_flag_two",
"true") == "true";
}
} }
} }

View File

@@ -6,18 +6,15 @@ using namespace server_configurable_flags;
{{ endif }} {{ endif }}
namespace {cpp_namespace} \{ namespace {cpp_namespace} \{
{{ for item in class_elements}} {{ for item in class_elements}}
class {item.flag_name} \{ static const bool {item.flag_name}() \{
public: {{ if item.readwrite- }}
virtual const bool value() \{ return GetServerConfigurableFlag(
{{ if item.readwrite- }} "{item.device_config_namespace}",
return GetServerConfigurableFlag( "{item.device_config_flag}",
"{item.device_config_namespace}", "{item.default_value}") == "true";
"{item.device_config_flag}", {{ -else- }}
"{item.default_value}") == "true"; return {item.default_value};
{{ -else- }} {{ -endif }}
return {item.default_value};
{{ -endif }}
}
} }
{{ endfor }} {{ endfor }}
} }