// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/* DO NOT EDIT. Generated from {{module.path}} */
{%- if variant -%}
{%- set variant_path = "%s-%s"|format(module.path, variant) -%}
{%- else -%}
{%- set variant_path = module.path -%}
{%- endif %}
#include "{{variant_path}}_impl_struct.h"
#include <utility>
#include "base/check.h"
{%- for struct in structs %}
{%- set struct_name = struct|get_name_for_kind %}
// Struct {{struct_name}}.
{{struct_name}}::{{struct_name}}() = default;
{{struct_name}}::{{struct_name}}(const {{struct_name}}&from) = default;
{{struct_name}}::{{struct_name}}({{struct_name}}&&from) = default;
{{struct_name}}::~{{struct_name}}() = default;
{{struct_name}}Ptr {{struct_name}}_Create() {
return new {{struct_name}}();
}
void {{struct_name}}_Destroy({{struct_name}}Ptr self) {
delete self;
}
// Struct {{struct_name}} setters.
{%- for packed_field in struct.packed.packed_fields_in_ordinal_order %}
{%- set kind = packed_field.field.kind %}
{%- if kind|is_array_kind %}
void {{struct_name}}_{{packed_field.field.name}}_add({{struct_name}}Ptr self, const {{kind.kind|c_wrapper_type}} element) {
DCHECK(self);
{%- if kind.kind|is_struct_kind %}
self->{{packed_field.field.name}}.push_back(*element);
{%- else %}
self->{{packed_field.field.name}}.push_back(element);
{%- endif %}
}
{%- else %}
void {{struct_name}}_{{packed_field.field.name}}_set({{struct_name}}Ptr self, const {{packed_field.field.kind|c_wrapper_type}} {{packed_field.field.name}}) {
DCHECK(self);
{%- if kind|is_struct_kind %}
self->{{packed_field.field.name}}.reset();
if ({{packed_field.field.name}} != nullptr)
self->{{packed_field.field.name}}.emplace(*{{packed_field.field.name}});
{%- else %}
self->{{packed_field.field.name}} = {{packed_field.field.name}};
{%- endif %}
}
{%- endif %}
{%- if kind|is_struct_kind %}
void {{struct_name}}_{{packed_field.field.name}}_move({{struct_name}}Ptr self, {{packed_field.field.kind|c_wrapper_type}} {{packed_field.field.name}}) {
DCHECK(self);
self->{{packed_field.field.name}}.reset();
if ({{packed_field.field.name}} != nullptr)
self->{{packed_field.field.name}}.emplace(std::move(*{{packed_field.field.name}}));
}
{%- endif %}
{% endfor %}
// Struct {{struct_name}} getters.
{%- for packed_field in struct.packed.packed_fields_in_ordinal_order %}
{%- set kind = packed_field.field.kind %}
{%- if kind|is_array_kind %}
uint32_t {{struct_name}}_{{packed_field.field.name}}_size({{struct_name}}Ptr self) {
DCHECK(self);
return self->{{packed_field.field.name}}.size();
}
{{kind.kind|c_wrapper_type}} {{struct_name}}_{{packed_field.field.name}}_at(const {{struct_name}}Ptr self, uint32_t index) {
DCHECK(self);
DCHECK(index < self->{{packed_field.field.name}}.size());
{%- if kind.kind|is_struct_kind %}
return &(self->{{packed_field.field.name}}[index]);
{%- elif kind.kind|is_string_kind %}
return self->{{packed_field.field.name}}[index].c_str();
{%- else %}
return self->{{packed_field.field.name}}[index];
{%- endif %}
}
void {{struct_name}}_{{packed_field.field.name}}_clear({{struct_name}}Ptr self) {
DCHECK(self);
self->{{packed_field.field.name}}.clear();
}
{%- else %}
{{packed_field.field.kind|c_wrapper_type}} {{struct_name}}_{{packed_field.field.name}}_get(const {{struct_name}}Ptr self) {
DCHECK(self);
{%- if kind|is_struct_kind %}
if (self->{{packed_field.field.name}} == std::nullopt)
return nullptr;
return &self->{{packed_field.field.name}}.value();
{%- elif kind|is_string_kind %}
return self->{{packed_field.field.name}}.c_str();
{%- else %}
return self->{{packed_field.field.name}};
{%- endif %}
}
{%- endif %}
{% endfor %}
{%- endfor %}