Resource index

@tj.corona
It looks like resource classes only provide a virtual method to obtain a Resource::Index. What would you think about adding

class Foo : public smtk::resource::Resource
{
  static constexpr Index TypeIndex =
    std::type_index(typeid(Foo)).hash_code());
};

to resources so that we can do things like ask a resource manager for resources of a compile-time-known type?

smtk::resource::Manager::Ptr mgr;
auto rsrcs = mgr->resources().get<IndexTag>().equal_range(Foo::TypeIndex);
for (rsrc : rsrcs)  { ... }

Makes sense to me. Better still would be to put it in DerivedFrom.h, so it doesn’t have to be placed in every resource (hooray for CRTP!).

Sadly, classes cannot provide constexpr to their own index (since typeid is ill-formed before the class is fully defined and thus no class member can hold its own Index). However, it is possible to provide a static method to compute it.

To close this out, here is the merge request that implemented this feature.

Privacy Notice