chromium/mojo/public/tools/bindings/generators/cpp_templates/module-forward.h.tmpl

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

{%- from 'cpp_macros.tmpl' import
  include_guard, namespace_begin, namespace_end %}

{%- set header_guard = include_guard('FORWARD', module.path, variant) %}

{%- macro kythe_annotation(name) %}
{%- if enable_kythe_annotations %}
// @generated_from: {{name}}
{%- endif %}
{%- endmacro %}

#ifndef {{header_guard}}
#define {{header_guard}}

{% if all_enums|length -%}
#include <stdint.h>
{%- endif %}

{% if structs|length or unions|length -%}
#include "mojo/public/cpp/bindings/struct_forward.h"
{%- endif %}

{% if not disallow_interfaces and interfaces|length -%}
#include "mojo/public/cpp/bindings/deprecated_interface_types_forward.h"
{%- endif %}

{% if not disallow_native_types and structs|length %}
#include "mojo/public/interfaces/bindings/native_struct.mojom-forward.h"
{%- endif %}

{%- if export_header and module.constants|length %}
#include "{{export_header}}"
{%- endif %}

{% if enable_kythe_annotations -%}
#ifdef KYTHE_IS_RUNNING
#pragma kythe_inline_metadata "Metadata comment"
#endif
{%- endif %}

{% if not disallow_native_types and uses_native_types and all_enums|length -%}
namespace mojo {
enum class NativeEnum;
}  // namespace mojo
{%- endif %}

{%- if variant %}
{{namespace_begin(namespaces_as_array)}}

{%- from "enum_macros.tmpl" import enum_forward%}
{%- for enum in all_enums %}
{%-   if enum|is_native_only_kind %}
using {{enum|get_name_for_kind(flatten_nested_kind=True)}} = mojo::NativeEnum;
{%-   else %}
{{enum_forward(enum)}}
{%-   endif %}
{%- endfor %}

{%- for interface in interfaces %}
class {{interface.name}}InterfaceBase;
{%- endfor %}

{{namespace_end(namespaces_as_array)}}
{%- endif %}

{{namespace_begin(namespaces_as_array, variant)}}

{%- set module_prefix = "%s"|format(namespaces_as_array|join(".")) %}

{#- These are non-variant header only. #}
{%- if not variant %}

{#--- Struct Forward Declarations -#}
{%- for struct in structs %}
{%-   if struct|is_native_only_kind %}
using {{struct.name}}DataView = mojo::native::NativeStructDataView;
{%-   else %}
class {{struct.name}}DataView;
{%-   endif %}
{%  endfor %}

{#--- Union Forward Declarations -#}
{%- for union in unions %}
class {{union.name}}DataView;
{%- endfor %}

{#--- Enums #}
{%- from "enum_macros.tmpl" import enum_forward%}
{%- for enum in all_enums %}
{%-   if enum|is_native_only_kind %}
using {{enum|get_name_for_kind(flatten_nested_kind=True)}} = mojo::NativeEnum;
{%-   else %}
{{enum_forward(enum)}}
{%-   endif %}
{%- endfor %}

{%- endif %}

{#--- Enum and interface base aliases #}
{%- if variant %}
{%-   if enum or interfaces %}
// Aliases for definition in the parent namespace.
{%-   endif %}
{%-   for enum in enums %}
using {{enum.name}} = {{enum.name}};
{%-   endfor %}
{%-   for interface in interfaces %}
using {{interface.name}}InterfaceBase = {{interface.name}}InterfaceBase;
{%-   endfor %}
{%- endif %}

{#--- Constants that do not rely on other headers (basic types) #}
{%- for constant in module.constants %}
{%-  if not constant.kind|is_enum_kind %}
{{ kythe_annotation("%s.%s"|format(module_prefix, constant.name)) }}
{{constant|format_constant_declaration}};
{%- endif %}
{%- endfor %}

{#--- Struct Forward Declarations -#}
{%  for struct in structs %}
{%-   if struct|is_native_only_kind %}
using {{struct.name}} = mojo::native::NativeStruct;
using {{struct.name}}Ptr = mojo::native::NativeStructPtr;
{%-   else %}
class {{struct.name}};
{%-     if struct|should_inline %}
using {{struct.name}}Ptr = mojo::InlinedStructPtr<{{struct.name}}>;
{%-     else %}
using {{struct.name}}Ptr = mojo::StructPtr<{{struct.name}}>;
{%-     endif %}
{%-   endif %}
{%  endfor %}

{#--- Union Forward Declarations -#}
{%  for union in unions %}
class {{union.name}};
{%    if union|should_inline_union %}
using {{union.name}}Ptr = mojo::InlinedStructPtr<{{union.name}}>;
{%    else %}
using {{union.name}}Ptr = mojo::StructPtr<{{union.name}}>;
{%    endif %}
{%- endfor %}


{#--- Interface Forward Declarations -#}
{%  for interface in interfaces %}
class {{interface.name}};
{%  endfor %}


{{namespace_end(namespaces_as_array, variant)}}

{#- TODO(tikuta): Use forward declaration of native enum/struct here. #}

#endif  // {{header_guard}}