{%- import "method-macro.cc.j2" as method_macro %}
{%- set class_name = struct.name ~ "DataGenerator" -%}
std::unique_ptr<{{class_name}}> {{class_name}}::Create(
::ash::cros_healthd::connectivity::Context* context) {
return std::unique_ptr<{{class_name}}>(new {{class_name}}(context, false));
}
{{class_name}}::{{class_name}}(
::ash::cros_healthd::connectivity::Context* context, bool nullable)
: nullable_(nullable) {
{{method_macro.define_data_generator("", "context", struct.fields)}}
}
{{struct.name}}Ptr {{class_name}}::Generate() {
if (returned_null_ ||
(nullable_ && !{{method_macro.params_has_next("", struct.fields)}})) {
returned_null_ = true;
return nullptr;
}
return {{struct.name}}::New({{method_macro.generate_params(
"", struct.fields)}});
}
bool {{class_name}}::HasNext() {
return (
{{method_macro.params_has_next("", struct.fields)}} ||
(nullable_ && !returned_null_)
);
}