mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-14 09:06:11 +00:00
Castable: Minor tweaks
Prefix the fully-qualified Unique name in TINT_INSTANTIATE_CLASS_ID with :: as there might (however unlikely) be a nested 'tint' namespace. Move the test structures in castable_test back into the anonymous namespace. This means `TINT_INSTANTIATE_CLASS_ID` needs to sit outside the anonymous namespace, but prevents global namespace pollution. Change-Id: I035e9568c081fee120726106dc2150c4990c3881 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34567 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
f1f10e6571
commit
5f8061bd39
@ -24,7 +24,7 @@ namespace tint {
|
|||||||
/// Helper macro to instantiate the ClassID for `CLASS`.
|
/// Helper macro to instantiate the ClassID for `CLASS`.
|
||||||
#define TINT_INSTANTIATE_CLASS_ID(CLASS) \
|
#define TINT_INSTANTIATE_CLASS_ID(CLASS) \
|
||||||
template <> \
|
template <> \
|
||||||
const char tint::ClassID::Unique<CLASS>::token = 0
|
const char ::tint::ClassID::Unique<CLASS>::token = 0
|
||||||
|
|
||||||
/// ClassID represents a unique, comparable identifier for a C++ type.
|
/// ClassID represents a unique, comparable identifier for a C++ type.
|
||||||
class ClassID {
|
class ClassID {
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
namespace tint {
|
||||||
|
namespace {
|
||||||
|
|
||||||
struct Animal : public tint::Castable<Animal> {
|
struct Animal : public tint::Castable<Animal> {
|
||||||
explicit Animal(std::string n) : name(n) {}
|
explicit Animal(std::string n) : name(n) {}
|
||||||
const std::string name;
|
const std::string name;
|
||||||
@ -48,16 +51,6 @@ struct Gecko : public tint::Castable<Gecko, Reptile> {
|
|||||||
Gecko() : Base("Gecko") {}
|
Gecko() : Base("Gecko") {}
|
||||||
};
|
};
|
||||||
|
|
||||||
TINT_INSTANTIATE_CLASS_ID(Animal);
|
|
||||||
TINT_INSTANTIATE_CLASS_ID(Amphibian);
|
|
||||||
TINT_INSTANTIATE_CLASS_ID(Mammal);
|
|
||||||
TINT_INSTANTIATE_CLASS_ID(Reptile);
|
|
||||||
TINT_INSTANTIATE_CLASS_ID(Frog);
|
|
||||||
TINT_INSTANTIATE_CLASS_ID(Bear);
|
|
||||||
TINT_INSTANTIATE_CLASS_ID(Gecko);
|
|
||||||
|
|
||||||
namespace tint {
|
|
||||||
|
|
||||||
TEST(CastableBase, Is) {
|
TEST(CastableBase, Is) {
|
||||||
std::unique_ptr<CastableBase> frog = std::make_unique<Frog>();
|
std::unique_ptr<CastableBase> frog = std::make_unique<Frog>();
|
||||||
std::unique_ptr<CastableBase> bear = std::make_unique<Bear>();
|
std::unique_ptr<CastableBase> bear = std::make_unique<Bear>();
|
||||||
@ -146,4 +139,14 @@ TEST(Castable, As) {
|
|||||||
ASSERT_EQ(gecko->As<Reptile>(), static_cast<Reptile*>(gecko.get()));
|
ASSERT_EQ(gecko->As<Reptile>(), static_cast<Reptile*>(gecko.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TINT_INSTANTIATE_CLASS_ID(Animal);
|
||||||
|
TINT_INSTANTIATE_CLASS_ID(Amphibian);
|
||||||
|
TINT_INSTANTIATE_CLASS_ID(Mammal);
|
||||||
|
TINT_INSTANTIATE_CLASS_ID(Reptile);
|
||||||
|
TINT_INSTANTIATE_CLASS_ID(Frog);
|
||||||
|
TINT_INSTANTIATE_CLASS_ID(Bear);
|
||||||
|
TINT_INSTANTIATE_CLASS_ID(Gecko);
|
||||||
|
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
Loading…
x
Reference in New Issue
Block a user