dawn::wire::client: Make ObjectTypeToTypeEnum a template variable.
Bug: dawn:1451 Change-Id: I21cba4b245b2b574104471da973000d552f1c7de Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93604 Reviewed-by: Loko Kung <lokokung@google.com> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
35199a30ae
commit
a55b29e0bd
|
@ -20,10 +20,8 @@
|
||||||
|
|
||||||
namespace dawn::wire::client {
|
namespace dawn::wire::client {
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct ObjectTypeToTypeEnum {
|
static constexpr ObjectType ObjectTypeToTypeEnum = static_cast<ObjectType>(-1);
|
||||||
static constexpr ObjectType value = static_cast<ObjectType>(-1);
|
|
||||||
};
|
|
||||||
|
|
||||||
{% for type in by_category["object"] %}
|
{% for type in by_category["object"] %}
|
||||||
{% set Type = type.name.CamelCase() %}
|
{% set Type = type.name.CamelCase() %}
|
||||||
|
@ -43,9 +41,7 @@ namespace dawn::wire::client {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct ObjectTypeToTypeEnum<{{Type}}> {
|
static constexpr ObjectType ObjectTypeToTypeEnum<{{Type}}> = ObjectType::{{Type}};
|
||||||
static constexpr ObjectType value = ObjectType::{{Type}};
|
|
||||||
};
|
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
} // namespace dawn::wire::client
|
} // namespace dawn::wire::client
|
||||||
|
|
|
@ -44,7 +44,7 @@ class Client : public ClientBase {
|
||||||
// T::T(ObjectBaseParams, arg1, arg2, arg3)
|
// T::T(ObjectBaseParams, arg1, arg2, arg3)
|
||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
T* Make(Args&&... args) {
|
T* Make(Args&&... args) {
|
||||||
constexpr ObjectType type = ObjectTypeToTypeEnum<T>::value;
|
constexpr ObjectType type = ObjectTypeToTypeEnum<T>;
|
||||||
|
|
||||||
ObjectBaseParams params = {this, mObjectStores[type].ReserveHandle()};
|
ObjectBaseParams params = {this, mObjectStores[type].ReserveHandle()};
|
||||||
T* object = new T(params, std::forward<Args>(args)...);
|
T* object = new T(params, std::forward<Args>(args)...);
|
||||||
|
@ -56,13 +56,13 @@ class Client : public ClientBase {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void Free(T* obj) {
|
void Free(T* obj) {
|
||||||
Free(obj, ObjectTypeToTypeEnum<T>::value);
|
Free(obj, ObjectTypeToTypeEnum<T>);
|
||||||
}
|
}
|
||||||
void Free(ObjectBase* obj, ObjectType type);
|
void Free(ObjectBase* obj, ObjectType type);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T* Get(ObjectId id) {
|
T* Get(ObjectId id) {
|
||||||
return static_cast<T*>(mObjectStores[ObjectTypeToTypeEnum<T>::value].Get(id));
|
return static_cast<T*>(mObjectStores[ObjectTypeToTypeEnum<T>].Get(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChunkedCommandHandler implementation
|
// ChunkedCommandHandler implementation
|
||||||
|
|
Loading…
Reference in New Issue