mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 00:17:03 +00:00
Make templates webgpu_cpp.h and webgpu_cpp_print.h flexible
Rename webgpu_cpp.h to api_cpp.h and webgpu_cpp_print.h to api_cpp_print.h. BUG=dawn:1201 Change-Id: Icceee0fd70fb6497a9e2b0891b5c5843787593f9 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/71720 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Junwei Fu <junwei.fu@intel.com>
This commit is contained in:
92
generator/templates/api_cpp_print.h
Normal file
92
generator/templates/api_cpp_print.h
Normal file
@@ -0,0 +1,92 @@
|
||||
//* Copyright 2021 The Dawn Authors
|
||||
//*
|
||||
//* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
//* you may not use this file except in compliance with the License.
|
||||
//* You may obtain a copy of the License at
|
||||
//*
|
||||
//* http://www.apache.org/licenses/LICENSE-2.0
|
||||
//*
|
||||
//* Unless required by applicable law or agreed to in writing, software
|
||||
//* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
//* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
//* See the License for the specific language governing permissions and
|
||||
//* limitations under the License.
|
||||
|
||||
{% set API = metadata.api.upper() %}
|
||||
{% set api = API.lower() %}
|
||||
#ifndef {{API}}_CPP_PRINT_H_
|
||||
#define {{API}}_CPP_PRINT_H_
|
||||
|
||||
#include "dawn/{{api}}_cpp.h"
|
||||
|
||||
#include <iomanip>
|
||||
#include <ios>
|
||||
#include <ostream>
|
||||
#include <type_traits>
|
||||
|
||||
namespace {{metadata.namespace}} {
|
||||
|
||||
{% for type in by_category["enum"] %}
|
||||
template <typename CharT, typename Traits>
|
||||
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& o, {{as_cppType(type.name)}} value) {
|
||||
switch (value) {
|
||||
{% for value in type.values %}
|
||||
case {{as_cppType(type.name)}}::{{as_cppEnum(value.name)}}:
|
||||
o << "{{as_cppType(type.name)}}::{{as_cppEnum(value.name)}}";
|
||||
break;
|
||||
{% endfor %}
|
||||
default:
|
||||
o << "{{as_cppType(type.name)}}::" << std::showbase << std::hex << std::setfill('0') << std::setw(4) << static_cast<typename std::underlying_type<{{as_cppType(type.name)}}>::type>(value);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
{% endfor %}
|
||||
|
||||
{% for type in by_category["bitmask"] %}
|
||||
template <typename CharT, typename Traits>
|
||||
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& o, {{as_cppType(type.name)}} value) {
|
||||
o << "{{as_cppType(type.name)}}::";
|
||||
if (!static_cast<bool>(value)) {
|
||||
{% for value in type.values if value.value == 0 %}
|
||||
// 0 is often explicitly declared as None.
|
||||
o << "{{as_cppEnum(value.name)}}";
|
||||
{% else %}
|
||||
o << std::showbase << std::hex << std::setfill('0') << std::setw(4) << 0;
|
||||
{% endfor %}
|
||||
return o;
|
||||
}
|
||||
|
||||
bool moreThanOneBit = !HasZeroOrOneBits(value);
|
||||
if (moreThanOneBit) {
|
||||
o << "(";
|
||||
}
|
||||
|
||||
bool first = true;
|
||||
{% for value in type.values if value.value != 0 %}
|
||||
if (value & {{as_cppType(type.name)}}::{{as_cppEnum(value.name)}}) {
|
||||
if (!first) {
|
||||
o << "|";
|
||||
}
|
||||
first = false;
|
||||
o << "{{as_cppEnum(value.name)}}";
|
||||
value &= ~{{as_cppType(type.name)}}::{{as_cppEnum(value.name)}};
|
||||
}
|
||||
{% endfor %}
|
||||
|
||||
if (static_cast<bool>(value)) {
|
||||
if (!first) {
|
||||
o << "|";
|
||||
}
|
||||
o << std::showbase << std::hex << std::setfill('0') << std::setw(4) << static_cast<typename std::underlying_type<{{as_cppType(type.name)}}>::type>(value);
|
||||
}
|
||||
|
||||
if (moreThanOneBit) {
|
||||
o << ")";
|
||||
}
|
||||
return o;
|
||||
}
|
||||
{% endfor %}
|
||||
|
||||
} // namespace {{metadata.namespace}}
|
||||
|
||||
#endif // {{API}}_CPP_PRINT_H_
|
||||
Reference in New Issue
Block a user