Files
build/tools/aconfig/templates/cpp_exported_header.template
Dennis Shen d555bbfa80 aconfig: update c/c++ codegen
1, Current codegen would still include an empty flag value cache even if
there are no read write flags. This is important as the flag value cache
is a std::vector. Thus adding this cache would automatically pull in
libc++ dependency which we should not.

2, There lacks of c/c++ codegen unit tests to lock down the generated
code when a flag package contains only read only flags. It should not
include server_configurable_flags header. And it should not include the
flag cache.

Bug: b/316614694
Test: atest aconfig.test
Change-Id: Iee4366672932ee507694f5fc73b526c66fcf0e9b
2023-12-18 13:43:22 +00:00

95 lines
1.8 KiB
Plaintext

#pragma once
{{ if not for_test- }}
{{ if has_fixed_read_only- }}
#ifndef {package_macro}
#define {package_macro}(FLAG) {package_macro}_##FLAG
#endif
{{ for item in class_elements }}
{{ if item.is_fixed_read_only- }}
#ifndef {package_macro}_{item.flag_macro}
#define {package_macro}_{item.flag_macro} {item.default_value}
#endif
{{ -endif }}
{{ -endfor }}
{{ -endif }}
{{ -endif }}
#ifdef __cplusplus
#include <memory>
namespace {cpp_namespace} \{
class flag_provider_interface \{
public:
virtual ~flag_provider_interface() = default;
{{ for item in class_elements}}
virtual bool {item.flag_name}() = 0;
{{ if for_test- }}
virtual void {item.flag_name}(bool val) = 0;
{{ -endif }}
{{ -endfor }}
{{ if for_test }}
virtual void reset_flags() \{}
{{ -endif }}
};
extern std::unique_ptr<flag_provider_interface> provider_;
{{ for item in class_elements}}
inline bool {item.flag_name}() \{
{{ if for_test- }}
return provider_->{item.flag_name}();
{{ -else- }}
{{ if item.readwrite- }}
return provider_->{item.flag_name}();
{{ -else- }}
{{ if item.is_fixed_read_only- }}
return {package_macro}_{item.flag_macro};
{{ -else- }}
return {item.default_value};
{{ -endif }}
{{ -endif }}
{{ -endif }}
}
{{ if for_test- }}
inline void {item.flag_name}(bool val) \{
provider_->{item.flag_name}(val);
}
{{ -endif }}
{{ -endfor }}
{{ if for_test- }}
inline void reset_flags() \{
return provider_->reset_flags();
}
{{ -endif }}
}
extern "C" \{
#endif // __cplusplus
{{ for item in class_elements }}
bool {header}_{item.flag_name}();
{{ if for_test- }}
void set_{header}_{item.flag_name}(bool val);
{{ -endif }}
{{ -endfor }}
{{ if for_test- }}
void {header}_reset_flags();
{{ -endif }}
#ifdef __cplusplus
} // extern "C"
#endif