{# Opens a C++ namespace built from `namespaces` and `variant`.
- if `variant` is not supplied, or empty/false then only `namespaces`
is used.
- if an empty namespace would result, then nothing is emitted. #}
{%- macro namespace_begin(namespaces, variant) %}
{%- set full_namespace = namespaces|join("::") %}
{%- if namespaces|length and variant %}
{%- set full_namespace = (full_namespace, variant)|join("::") %}
{%- elif variant %}
{%- set full_namespace = variant %}
{%- endif %}
{%- if full_namespace %}
namespace {{full_namespace}} {
{%- endif %}
{%- endmacro -%}
{# Closes a C++ namespace using the same rules as namespace_begin() #}
{%- macro namespace_end(namespaces, variant) %}
{%- set full_namespace = namespaces|join("::") %}
{%- if namespaces|length and variant %}
{%- set full_namespace = (full_namespace, variant)|join("::") %}
{%- elif variant %}
{%- set full_namespace = variant %}
{%- endif %}
{%- if full_namespace %}
} // {{full_namespace}}
{%- endif %}
{%- endmacro -%}
{# Creates a string path matching the module and variant, includes the
module name, and can be suffixed with '.h', '-forward.h' etc. #}
{%- macro variant_path(path, variant) -%}
{%- if variant -%}
{%- set variant_path = "%s-%s"|format(path, variant) -%}
{%- else -%}
{%- set variant_path = path -%}
{%- endif -%}
{{variant_path}}
{%- endmacro -%}
{# Creates a string matching the file's path for include guards #}
{%- macro include_guard(type, path, variant) -%}
{%- set upper_path = variant_path(path, variant)
|upper|replace("/","_")|replace(".","_")|replace("-", "_") -%}
{%- if type -%}
{%- set header_guard = "%s_%s_H_"|format(upper_path, type) -%}
{%- else -%}
{%- set header_guard = "%s_H_"|format(upper_path) -%}
{%- endif -%}
{{header_guard}}
{%- endmacro -%}