Commit 77bcf64a authored by T.J. Corona's avatar T.J. Corona Committed by Kitware Robot

Merge topic 'resource-index' into release

260a723b Add a static field for resource index
Acked-by: Kitware Robot's avatarKitware Robot <>
Acked-by: David Thompson's avatarDavid Thompson <>
Merge-request: !1475
parents 49a3b7bb 260a723b
Pipeline #129574 running with stage
......@@ -34,12 +34,17 @@ class DerivedFrom : public Parent
typedef Parent ParentResource;
/// A static index for this resource type.
/// NOTE: because we are using CRTP, it is possible to make this value static
/// and redefined for each resource type, regardless of inheritance.
static const Resource::Index type_index;
/// given a resource index, return whether or not this resource is or is
/// derived from the resource described by the index.
virtual bool isOfType(const Resource::Index& index) const override
return std::type_index(typeid(Self)).hash_code() == index ? true
: ParentResource::isOfType(index);
return DerivedFrom<Self, Parent>::type_index == index ? true : ParentResource::isOfType(index);
/// given a resource's unique name, return whether or not this resource is or
......@@ -57,6 +62,10 @@ protected:
template <typename Self, typename Parent>
const Resource::Index DerivedFrom<Self, Parent>::type_index =
......@@ -184,5 +184,13 @@ int TestResourceManager(int, char** const)
smtkTest(resourceASet.size() == 3,
"Resource manager should have three resources of type ResourceA registered.");
// Test fetching resources by exact index; this will only
// return instances that are of the given class not including subclasses.
auto indexA = ResourceA::type_index;
auto resourcesByIndex =
int count = std::distance(resourcesByIndex.first, resourcesByIndex.second);
smtkTest(count == 2, "Fetched " << count << " instead of 2 resources by type-index failed.");
return 0;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment