Commit 55b1b526 authored by T.J. Corona's avatar T.J. Corona

Introduce resource manager.

parent 9b7de0b3
......@@ -19,6 +19,8 @@
#include <functional>
#include <map>
#include <set>
#include <string>
#include <typeindex>
#include <vector>
namespace smtk
......@@ -228,6 +230,7 @@ typedef smtk::shared_ptr<smtk::common::View> ViewPtr;
namespace resource
{
typedef smtk::shared_ptr<smtk::resource::Manager> ManagerPtr;
typedef smtk::shared_ptr<smtk::resource::Resource> ResourcePtr;
typedef smtk::shared_ptr<smtk::resource::Component> ComponentPtr;
typedef std::set<smtk::resource::ComponentPtr> ComponentSet;
......
......@@ -262,7 +262,7 @@ CollectionPtr Attribute::collection() const
return this->m_definition->collection();
}
smtk::resource::ResourcePtr Attribute::resource() const
const smtk::resource::ResourcePtr Attribute::resource() const
{
return this->collection();
}
......
......@@ -211,7 +211,7 @@ public:
bool isValid() const;
smtk::attribute::CollectionPtr collection() const;
smtk::resource::ResourcePtr resource() const override;
const smtk::resource::ResourcePtr resource() const override;
smtk::model::ManagerPtr modelManager() const;
void setUserData(const std::string& key, smtk::simulation::UserDataPtr value)
......
......@@ -45,7 +45,7 @@ Collection::~Collection()
}
}
smtk::resource::Resource::Type Collection::resourceType() const
smtk::resource::Resource::Type Collection::type() const
{
return smtk::resource::Resource::ATTRIBUTE;
}
......
......@@ -38,8 +38,8 @@ class Definition;
class SMTKCORE_EXPORT Collection : public smtk::resource::Resource
{
public:
smtkTypeMacro(Collection);
smtkCreateMacro(Collection);
smtkTypeMacro(smtk::attribute::Collection);
smtkCreateMacro(smtk::attribute::Collection);
smtkSharedFromThisMacro(smtk::resource::Resource);
enum CopyOptions
......@@ -52,7 +52,7 @@ public:
~Collection() override;
smtk::resource::Resource::Type resourceType() const override;
smtk::resource::Resource::Type type() const override;
smtk::attribute::DefinitionPtr createDefinition(
const std::string& typeName, const std::string& baseTypeName = "");
......
......@@ -29,7 +29,6 @@ PySharedPtrClass< smtk::attribute::Collection, smtk::resource::Resource > pybind
{
PySharedPtrClass< smtk::attribute::Collection, smtk::resource::Resource > instance(m, "Collection");
instance
.def("deepcopy", (smtk::attribute::Collection & (smtk::attribute::Collection::*)(::smtk::attribute::Collection const &)) &smtk::attribute::Collection::operator=)
.def("addAdvanceLevel", &smtk::attribute::Collection::addAdvanceLevel, py::arg("level"), py::arg("label"), py::arg("l_color") = 0)
.def("addView", &smtk::attribute::Collection::addView, py::arg("arg0"))
.def("advanceLevelColor", &smtk::attribute::Collection::advanceLevelColor, py::arg("level"))
......@@ -76,7 +75,7 @@ PySharedPtrClass< smtk::attribute::Collection, smtk::resource::Resource > pybind
.def("refModelManager", &smtk::attribute::Collection::refModelManager)
.def("removeAttribute", &smtk::attribute::Collection::removeAttribute, py::arg("att"))
.def("rename", &smtk::attribute::Collection::rename, py::arg("att"), py::arg("newName"))
.def("resourceType", &smtk::attribute::Collection::resourceType)
.def("type", &smtk::attribute::Collection::type)
.def("setAdvanceLevelColor", &smtk::attribute::Collection::setAdvanceLevelColor, py::arg("level"), py::arg("l_color"))
.def("setRefModelManager", &smtk::attribute::Collection::setRefModelManager, py::arg("refModelMgr"))
.def("updateCategories", &smtk::attribute::Collection::updateCategories)
......
......@@ -20,7 +20,7 @@ int main()
smtk::attribute::CollectionPtr sysptr = smtk::attribute::Collection::create();
smtk::attribute::Collection& collection(*sysptr.get());
std::cout << "Collection Created\n";
smtk::resource::Resource::Type t = collection.resourceType();
smtk::resource::Resource::Type t = collection.type();
if (t != smtk::resource::Resource::ATTRIBUTE)
{
std::cout << "ERROR: Returned wrong resource type";
......
......@@ -27,7 +27,7 @@ if __name__ == '__main__':
collection = smtk.attribute.Collection.create()
print 'Collection created'
t = collection.resourceType()
t = collection.type()
if t != smtk.resource.Resource.ATTRIBUTE:
print 'ERROR: Returned wrong resource type'
status = -1
......
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#ifndef pybind_smtk_common_Resource_h
#define pybind_smtk_common_Resource_h
#include <pybind11/pybind11.h>
#include "smtk/common/Resource.h"
namespace py = pybind11;
PySharedPtrClass< smtk::common::Resource > pybind11_init_smtk_common_Resource(py::module &m)
{
PySharedPtrClass< smtk::common::Resource > instance(m, "Resource");
instance
.def("deepcopy", (smtk::common::Resource & (smtk::common::Resource::*)(::smtk::common::Resource const &)) &smtk::common::Resource::operator=)
.def("resourceType", &smtk::common::Resource::resourceType)
.def_static("type2String", &smtk::common::Resource::type2String, py::arg("t"))
.def_static("string2Type", &smtk::common::Resource::string2Type, py::arg("s"))
;
py::enum_<smtk::common::Resource::Type>(instance, "Type")
.value("ATTRIBUTE", smtk::common::Resource::Type::ATTRIBUTE)
.value("MODEL", smtk::common::Resource::Type::MODEL)
.value("MESH", smtk::common::Resource::Type::MESH)
.value("NUMBER_OF_TYPES", smtk::common::Resource::Type::NUMBER_OF_TYPES)
.export_values();
return instance;
}
#endif
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#ifndef pybind_smtk_common_Component_h
#define pybind_smtk_common_Component_h
#include <pybind11/pybind11.h>
#include "smtk/common/Component.h"
#include "smtk/common/Resource.h"
#include "smtk/common/UUID.h"
#include "smtk/common/pybind11/PybindUUIDTypeCaster.h"
namespace py = pybind11;
PySharedPtrClass< smtk::common::Component > pybind11_init_smtk_common_ResourceComponent(py::module &m)
{
PySharedPtrClass< smtk::common::Component > instance(m, "ResourceComponent");
instance
.def("deepcopy", (smtk::common::Component & (smtk::common::ResourceComponent::*)(::smtk::common::ResourceComponent const &)) &smtk::common::ResourceComponent::operator=)
.def("classname", &smtk::common::Component::classname)
.def("id", &smtk::common::Component::id)
.def("resource", &smtk::common::Component::resource)
;
return instance;
}
#endif
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#ifndef pybind_smtk_common_Set_h
#define pybind_smtk_common_Set_h
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "smtk/common/Set.h"
#include "smtk/common/Resource.h"
namespace py = pybind11;
py::class_< smtk::common::Set > pybind11_init_smtk_common_Set(py::module &m)
{
py::class_< smtk::common::Set > instance(m, "Set");
py::enum_<smtk::common::Set::Role>(instance, "Role")
.value("NOT_DEFINED", smtk::common::Set::Role::NOT_DEFINED)
.value("TEMPLATE", smtk::common::Set::Role::TEMPLATE)
.value("SCENARIO", smtk::common::Set::Role::SCENARIO)
.value("INSTANCE", smtk::common::Set::Role::INSTANCE)
.export_values();
py::enum_<smtk::common::Set::State>(instance, "ResourceState")
.value("NOT_LOADED", smtk::common::Set::State::NOT_LOADED)
.value("LOADED", smtk::common::Set::State::LOADED)
.value("LOAD_ERROR", smtk::common::Set::State::LOAD_ERROR)
.export_values();
instance
.def(py::init<::smtk::common::Set const &>())
.def(py::init<>())
.def("deepcopy", (smtk::common::Set & (smtk::common::Set::*)(::smtk::common::ResourceSet const &)) &smtk::common::ResourceSet::operator=)
.def("add", &smtk::common::Set::addResource, py::arg("resource"), py::arg("id"), py::arg("link") = "", py::arg("arg3") = ::smtk::common::Set::Role::NOT_DEFINED)
.def("addInfo", &smtk::common::Set::addInfo, py::arg("id"), py::arg("type"), py::arg("role"), py::arg("state"), py::arg("link") = "")
.def("get", &smtk::common::Set::get, py::arg("id"), py::arg("resource"))
.def("get", [](const smtk::common::Set& set, std::string id){ smtk::common::ResourcePtr resource; set.get(id, resource); return resource; })
.def("linkStartPath", &smtk::common::Set::linkStartPath)
.def("numberOfResources", &smtk::common::Set::numberOfResources)
.def("resourceIds", &smtk::common::Set::resourceIds)
.def("resourceInfo", &smtk::common::Set::resourceInfo, py::arg("id"), py::arg("type"), py::arg("role"), py::arg("state"), py::arg("link"))
.def_static("role2String", &smtk::common::Set::role2String, py::arg("role"))
.def("setLinkStartPath", &smtk::common::Set::setLinkStartPath, py::arg("path"))
.def_static("state2String", &smtk::common::Set::state2String, py::arg("state"))
.def_static("string2Role", &smtk::common::Set::string2Role, py::arg("s"))
;
return instance;
}
#endif
......@@ -79,7 +79,7 @@ int main(int argc, const char* argv[])
smtk::resource::ResourcePtr resource;
resources.get("att0", resource);
smtk::resource::Resource::Type resType = resource->resourceType();
smtk::resource::Resource::Type resType = resource->type();
std::cout << "att0 type: " << smtk::resource::Resource::type2String(resType) << std::endl;
} // if (argc > 2)
......
......@@ -149,7 +149,7 @@ int main(int /* argc */, const char* /* argv */ [])
std::cerr << "get() failed" << std::endl;
status += 1;
}
rtype = resource->resourceType();
rtype = resource->type();
if (rtype != smtk::resource::Resource::ATTRIBUTE)
{
std::cerr << "Incorrect resource type " << rtype << ", should be "
......
......@@ -79,7 +79,7 @@ def TestResourceSetReader(readFromFile):
# print ('dir'), dir(resources)
# print help(resources.get)
res0 = resources.get('att0')
print 'type', res0.resourceType()
print 'type', res0.type()
# print dir(res0)
return status
......
......@@ -31,7 +31,7 @@ def RSTest():
collection1 = smtk.attribute.Collection.New()
print collection1
print collection1.resourceType()
print collection1.type()
result = resourceSet.add(
collection1, "collection1", "", smtk.resource.Set.TEMPLATE)
......@@ -94,7 +94,7 @@ def RSTest():
if resource == None:
print("get() failed")
status = status + 1
rtype = resource.resourceType()
rtype = resource.type()
if rtype != smtk.resource.Resource.ATTRIBUTE:
print(
"Incorrect resource type %s, should be smtk.resource.Resource.ATTRIBUTE" % rtype)
......
......@@ -109,7 +109,7 @@ EntityPtr Entity::setup(BitFlags entFlags, int dim, Manager::Ptr resource, bool
return shared_from_this();
}
ResourcePtr Entity::resource() const
const ResourcePtr Entity::resource() const
{
return std::dynamic_pointer_cast<smtk::resource::Resource>(this->m_resource.lock());
}
......
......@@ -59,7 +59,7 @@ public:
EntityPtr setup(
BitFlags entityFlags, int dimension, ManagerPtr resource = nullptr, bool resetRelations = true);
ResourcePtr resource() const override;
const ResourcePtr resource() const override;
ManagerPtr modelResource() const;
/// Return the templated object (usually EntityRef or a subclass) that points to this component.
......
......@@ -90,7 +90,7 @@ public:
typedef storage_type::iterator iter_type;
typedef UUIDsToTessellations::iterator tess_iter_type;
smtkTypeMacro(Manager);
smtkTypeMacro(smtk::model::Manager);
smtkSharedPtrCreateMacro(smtk::resource::Resource);
Manager();
......@@ -128,7 +128,7 @@ public:
EntityPtr findEntity(const smtk::common::UUID& uid, bool trySessions = true) const;
smtk::resource::ComponentPtr find(const smtk::common::UUID& uid) const override;
Resource::Type resourceType() const override { return Resource::MODEL; }
Resource::Type type() const override { return smtk::resource::Resource::MODEL; }
virtual SessionInfoBits erase(
const smtk::common::UUID& uid, SessionInfoBits flags = smtk::model::SESSION_EVERYTHING);
......
......@@ -27,8 +27,8 @@ namespace model
class SMTKCORE_EXPORT StoredResource : public smtk::resource::Resource
{
public:
smtkTypeMacro(StoredResource);
smtkCreateMacro(StoredResource);
smtkTypeMacro(smtk::model::StoredResource);
smtkCreateMacro(smtk::model::StoredResource);
smtkSharedFromThisMacro(smtk::resource::Resource);
virtual ~StoredResource();
......@@ -42,7 +42,7 @@ public:
bool exists(const std::string& prefix = "") const;
Resource::Type resourceType() const override { return MODEL; }
Resource::Type type() const override { return smtk::resource::Resource::MODEL; }
smtk::resource::ComponentPtr find(const smtk::common::UUID& compId) const override;
bool addEntity(const EntityRef& ent);
......
......@@ -56,7 +56,6 @@ PySharedPtrClass< smtk::model::Manager, smtk::resource::Resource > pybind11_init
instance
.def(py::init<::smtk::model::Manager const &>())
.def(py::init<>())
.def("deepcopy", (smtk::model::Manager & (smtk::model::Manager::*)(::smtk::model::Manager const &)) &smtk::model::Manager::operator=)
.def("addAuxiliaryGeometry", (smtk::model::AuxiliaryGeometry (smtk::model::Manager::*)(int)) &smtk::model::Manager::addAuxiliaryGeometry, py::arg("dim") = -1)
.def("addAuxiliaryGeometry", (smtk::model::AuxiliaryGeometry (smtk::model::Manager::*)(::smtk::model::Model const &, int)) &smtk::model::Manager::addAuxiliaryGeometry, py::arg("parent"), py::arg("dim") = -1)
.def("addAuxiliaryGeometry", (smtk::model::AuxiliaryGeometry (smtk::model::Manager::*)(::smtk::model::AuxiliaryGeometry const &, int)) &smtk::model::Manager::addAuxiliaryGeometry, py::arg("parent"), py::arg("dim") = -1)
......@@ -200,7 +199,8 @@ PySharedPtrClass< smtk::model::Manager, smtk::resource::Resource > pybind11_init
.def("removeIntegerProperty", &smtk::model::Manager::removeIntegerProperty, py::arg("entity"), py::arg("propName"))
.def("removeStringProperty", &smtk::model::Manager::removeStringProperty, py::arg("entity"), py::arg("propName"))
.def("removeTessellation", &smtk::model::Manager::removeTessellation, py::arg("cellId"), py::arg("removeGen") = false)
.def("resourceType", &smtk::model::Manager::resourceType)
.def("index", (std::type_index (smtk::model::Manager::*)() const) &smtk::model::Manager::index)
.def("type", (::smtk::resource::Resource::Type (smtk::model::Manager::*)() const) &smtk::model::Manager::type)
.def("resources", &smtk::model::Manager::resources, py::arg("skipUpdate") = false)
.def("sessionData", &smtk::model::Manager::sessionData, py::arg("sessRef"))
.def_static("sessionFileTypes", &smtk::model::Manager::sessionFileTypes, py::arg("sname"), py::arg("engine") = std::string())
......@@ -245,7 +245,7 @@ PySharedPtrClass< smtk::model::Manager, smtk::resource::Resource > pybind11_init
.def("trigger", (void (smtk::model::Manager::*)(::smtk::model::ManagerEventType, ::smtk::model::EntityRef const &, ::smtk::model::EntityRef const &)) &smtk::model::Manager::trigger, py::arg("event"), py::arg("src"), py::arg("related"))
.def("trigger", (void (smtk::model::Manager::*)(::smtk::model::ManagerEventType, ::smtk::model::EntityRef const &, ::smtk::model::EntityRefArray const &)) &smtk::model::Manager::trigger, py::arg("event"), py::arg("src"), py::arg("related"))
.def("trigger", (void (smtk::model::Manager::*)(::smtk::model::OperatorEventType, ::smtk::model::Operator const &)) &smtk::model::Manager::trigger, py::arg("event"), py::arg("src"))
.def("type", &smtk::model::Manager::type, py::arg("ofEntity"))
.def("type", (smtk::model::BitFlags (smtk::model::Manager::*)(const ::smtk::common::UUID&) const) &smtk::model::Manager::type, py::arg("ofEntity"))
.def("unarrangeEntity", &smtk::model::Manager::unarrangeEntity, py::arg("entityId"), py::arg("arg1"), py::arg("index"), py::arg("removeIfLast") = false)
.def("unobserve", (void (smtk::model::Manager::*)(::smtk::model::ManagerEventType, ::smtk::model::ConditionCallback, void *)) &smtk::model::Manager::unobserve, py::arg("event"), py::arg("functionHandle"), py::arg("callData"))
.def("unobserve", (void (smtk::model::Manager::*)(::smtk::model::ManagerEventType, ::smtk::model::OneToOneCallback, void *)) &smtk::model::Manager::unobserve, py::arg("event"), py::arg("functionHandle"), py::arg("callData"))
......
# set up sources to build
set(resourceSrcs
Component.cxx
Manager.cxx
Resource.cxx
SelectionManager.cxx
Set.cxx
......@@ -8,7 +9,11 @@ set(resourceSrcs
set(resourceHeaders
Component.h
Manager.h
Metadata.h
Resource.h
Resource.h
Container.h
SelectionManager.h
Set.h
)
......
......@@ -38,7 +38,7 @@ class SMTKCORE_EXPORT Component : smtkEnableSharedPtr(Component)
public:
smtkTypeMacroBase(Component);
virtual ~Component();
virtual ResourcePtr resource() const = 0;
virtual const ResourcePtr resource() const = 0;
const common::UUID& id() const { return this->m_id; }
......
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#ifndef smtk_resource_Container_h
#define smtk_resource_Container_h
#include "smtk/resource/Metadata.h"
#include "smtk/resource/Resource.h"
#include <boost/multi_index/global_fun.hpp>
#include <boost/multi_index/mem_fun.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index_container.hpp>
namespace smtk
{
namespace resource
{
/// Tags used to access Container data.
struct IdTag
{
};
struct TypeTag
{
};
struct IndexTag
{
};
struct LocationTag
{
};
struct NameTag
{
};
/// Global access methods used to sort Container data.
namespace detail
{
inline const smtk::common::UUID& id(const ResourcePtr& r)
{
return r->id();
}
inline Resource::Type type(const ResourcePtr& r)
{
return r->type();
}
inline std::type_index index(const ResourcePtr& r)
{
return r->index();
}
inline const std::string& location(const ResourcePtr& r)
{
return r->location();
}
}
using namespace boost::multi_index;
/// A multi-index container for accessing resources. This class is primarily
/// intended to be used in the implementation of smtk::resource::Manager only.
typedef boost::multi_index_container<
ResourcePtr,
indexed_by<ordered_unique<tag<IdTag>,
global_fun<const ResourcePtr&, const smtk::common::UUID&, &detail::id> >,
ordered_non_unique<tag<TypeTag>,
global_fun<const ResourcePtr&, Resource::Type, &detail::type> >,
ordered_non_unique<tag<IndexTag>,
global_fun<const ResourcePtr&, std::type_index, &detail::index> >,
ordered_non_unique<tag<LocationTag>,
global_fun<const ResourcePtr&, const std::string&, &detail::location> > > >
Container;
/// A multi-index container for accessing resource metadata. This class is
/// primarily intended to be used in the implementation of
/// smtk::resource::Manager only.
typedef boost::multi_index_container<
Metadata, indexed_by<ordered_unique<tag<NameTag>,
const_mem_fun<Metadata, const std::string&, &Metadata::uniqueName> >,
ordered_unique<tag<IndexTag>,
const_mem_fun<Metadata, const std::type_index&, &Metadata::index> > > >
MetadataContainer;
}
}
#endif // smtk_resource_Resources_h
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#include "smtk/resource/Manager.h"
#include "smtk/common/UUIDGenerator.h"
namespace smtk
{
namespace resource
{
MetadataContainer Manager::s_metadata;
Manager::Manager()
{
}
Manager::~Manager()
{
}
smtk::resource::ResourcePtr Manager::create(const std::string& uniqueName)
{
// Locate the metadata associated with this resource type
auto metadata = s_metadata.get<NameTag>().find(uniqueName);
if (metadata != s_metadata.get<NameTag>().end())
{
// Create the resource using its index
return this->create(metadata->index());
}
return smtk::resource::ResourcePtr();
}
smtk::resource::ResourcePtr Manager::create(const Resource::Index& index)
{
smtk::common::UUID uuid;
// Though the chances are super small, we ensure here that the UUID associated
// to our new resource is unique to the manager's set of resources.
do
{
uuid = smtk::common::UUIDGenerator::instance().random();
} while (m_resources.find(uuid) != m_resources.end());
return this->create(index, uuid);
}
smtk::resource::ResourcePtr Manager::create(
const std::string& uniqueName, const smtk::common::UUID& uuid)
{
smtk::resource::ResourcePtr resource;
// Locate the metadata associated with this resource type
auto metadata = s_metadata.get<NameTag>().find(uniqueName);
if (metadata != s_metadata.get<NameTag>().end())
{
// Create the resource using its index
resource = metadata->create(uuid);
this->add(metadata->index(), resource);
}
return resource;
}
smtk::resource::ResourcePtr Manager::create(
const Resource::Index& index, const smtk::common::UUID& uuid)
{
smtk::resource::ResourcePtr resource;
// Locate the metadata associated with this resource type
auto metadata = s_metadata.get<IndexTag>().find(index);
if (metadata != s_metadata.get<IndexTag>().end())
{
// Create the resource with the appropriate UUID
resource = metadata->create(uuid);
this->add(index, resource);
}
return resource;
}
bool Manager::registerResource(Metadata& metadata)
{
auto alreadyRegisteredMetadata = s_metadata.get<IndexTag>().find(metadata.index());
if (alreadyRegisteredMetadata == s_metadata.get<IndexTag>().end())
{
auto size = s_metadata.get<IndexTag>().size();
s_metadata.get<IndexTag>().insert(metadata);
return s_metadata.get<IndexTag>().size() > size;
}
return false;
}
smtk::resource::ResourcePtr Manager::get(const smtk::common::UUID& id)
{
// No type casting is required, so we simply find and return the resource by
// key.
typedef Container::index<IdTag>::type ResourcesById;
ResourcesById& resources = m_resources.get<IdTag>();
ResourcesById::iterator resourceIt = resources.find(id);
if (resourceIt != resources.end())
{
return (*resourceIt)->shared_from_this();
}
return smtk::resource::ResourcePtr();
}
smtk::resource::ConstResourcePtr Manager::get(const smtk::common::UUID& id) const
{
// No type casting is required, so we simply find and return the resource by
// key.
typedef Container::index<IdTag>::type ResourcesById;
const ResourcesById& resources = m_resources.get<IdTag>();
ResourcesById::const_iterator resourceIt = resources.find(id);
if (resourceIt != resources.end())
{
return (*resourceIt)->shared_from_this();
}
return smtk::resource::ConstResourcePtr();
}
std::set<smtk::resource::ResourcePtr> Manager::find(const std::string& uniqueName)
{
std::set<smtk::resource::ResourcePtr> values;
std::set<Resource::Index> validIndices;
auto metadata = s_metadata.get<NameTag>().find(uniqueName);
if (metadata == s_metadata.get<NameTag>().end())
{
return values;
}
for (auto& metadatum : s_metadata)
{
if (metadatum.m_associatedIndices.find(metadata->index()) !=
metadatum.m_associatedIndices.end())
{
validIndices.insert(metadatum.index());
}
}
typedef Container::index<IndexTag>::type ResourcesByIndex;
ResourcesByIndex& resources = this->m_resources.get<IndexTag>();
for (auto& idx : validIndices)
{
auto resourceItRange = resources.equal_range(idx);
values.insert(resourceItRange.first, resourceItRange.second);
}
return values;
}
std::set<smtk::resource::ResourcePtr> Manager::find(const Resource::Index& index)
{
std::set<Resource::Index> validIndices;
for (auto& metadatum : s_metadata)
{
if (metadatum.m_associatedIndices.find(index) != metadatum.m_associatedIndices.end())
{
validIndices.insert(metadatum.index());
}
}
std::set<smtk::resource::ResourcePtr> values;
typedef Container::index<IndexTag>::type ResourcesByIndex;
ResourcesByIndex& resources = this->m_resources.get<IndexTag>();
for (auto& idx : validIndices)
{
auto resourceItRange = resources.equal_range(idx);
values.insert(resourceItRange.first, resourceItRange.second);
}
return values;
}
smtk::resource::ResourcePtr Manager::read(const Resource::Index& index, const std::string& url)
{
smtk::resource::ResourcePtr resource;
// Locate the metadata associated with this resource type
auto metadata = s_metadata.get<IndexTag>().find(index);