chromium/third_party/blink/renderer/build/scripts/templates/fields/pointer.tmpl

{% import 'templates/fields/base.tmpl' as base %}
{% from 'templates/fields/field.tmpl' import getter_expression, setter_expression, encode, decode, getter_method_name, setter_method_name, move_if_changed %}

{% macro wrapped_type(field) -%}
  {% if field.builder and not field.group.parent and field.wrapper_pointer_name == 'Member' -%}
      {#- Since the builder is STACK_ALLOCATED, we can (and must) store
          top-level pointers that are normally wrapped with Member
          as raw pointers. -#}
      {{field.type_name}}*
  {%- else -%}
    {{field.wrapper_pointer_name}}<{{field.type_name}}>
  {%- endif %}
{%- endmacro %}

{% macro unwrap_pointer(field) -%}
  {% if field.wrapper_pointer_name == 'Member' -%}
    {%- if field.builder and not field.group.parent -%}
      {#- Intentionally empty. In the builder, we avoid top-level Members
          and instead just store raw pointers. Nothing to unwrap. -#}
    {%- else -%}
      {#- Member -#}
      .Get()
    {%- endif -%}
  {%- else -%}
    {#- Assumed scoped_refptr, unique_ptr, etc -#}
    .get()
  {%- endif %}
{%- endmacro %}

{# The standard base.decl_getter_method would generate a function that
   returns 'const T&', but we prefer 'T*' for this field type. #}
{% macro decl_getter_method(field, visibility) -%}
{% if field.getter_visibility == visibility %}
{{field.type_name}}* {{getter_method_name(field)}}() const {
  return {{decode(field, getter_expression(field))}}{{unwrap_pointer(field)}};
}
{% endif %}
{%- endmacro %}

{# The standard base.decl_setter_method would generate a function which
   accepts 'const T&', which is not what we want. This custom setter accepts
   WrapperType<T> instead. #}
{% macro decl_setter_method(field, visibility) -%}
{% if field.setter_visibility == visibility and field.builder %}
void {{setter_method_name(field)}}({{wrapped_type(field)}} v) {
  {{move_if_changed(field, encode(field, "v"))|indent(2)}}
}
{% endif %}
{%- endmacro %}

{% macro decl_public_methods(field) -%}
{{decl_getter_method(field, 'public')}}
{{decl_setter_method(field, 'public')}}
{%- endmacro %}

{% macro decl_protected_methods(field) -%}
{{decl_getter_method(field, 'protected')}}
{{decl_setter_method(field, 'protected')}}
{%- endmacro %}