SMTK
@SMTK_VERSION@
Simulation Modeling Tool Kit
|
A resource Manager is responsible for tracking currently allocated resources, creating new resources and serializing/deserializing resources to/from disk. More...
#include <Manager.h>
Public Types | |
using | ResourceVisitor = std::function< smtk::common::Processing(Resource &)> |
The signature for visitor functions used to traverse managed resources. | |
Public Member Functions | |
smtkTypedefs (smtk::resource::Manager) | |
smtkCreateMacro (Manager) | |
template<typename ResourceType > | |
bool | registerResource (const std::function< ResourcePtr(const std::string &, const std::shared_ptr< smtk::common::Managers > &)> &read=nullptr, const std::function< bool(const ResourcePtr &, const std::shared_ptr< smtk::common::Managers > &)> &write=nullptr, const std::function< ResourcePtr(const smtk::common::UUID &, const std::shared_ptr< smtk::common::Managers > &)> &create=nullptr) |
Register a resource identified by its class type, read and write operations. | |
bool | registerResource (Metadata &&) |
Register a resource identified by its metadata. | |
template<typename ResourceType > | |
bool | unregisterResource () |
Unregister a resource identified by its class type. | |
bool | unregisterResource (const std::string &) |
Unregister a resource identified by its type name. | |
bool | unregisterResource (const Resource::Index &) |
Unregister a resource identified by its type index. | |
template<typename ResourceType > | |
bool | registered () const |
Check if a resource identified by its class type is registered. | |
bool | registered (const std::string &) const |
Check if a resource idenfified by its type name is registered. | |
bool | registered (const Resource::Index &) const |
Check if a resource identified by its type index is registered. | |
void | clear () |
Remove all resources. More... | |
ResourcePtr | create (const std::string &, const std::shared_ptr< smtk::common::Managers > &=nullptr) |
Construct a resource identified by its type name. | |
ResourcePtr | create (const Resource::Index &, const std::shared_ptr< smtk::common::Managers > &=nullptr) |
Construct a resource identified by its type index. | |
template<typename ResourceType > | |
smtk::shared_ptr< ResourceType > | create (const std::shared_ptr< smtk::common::Managers > &=nullptr) |
Construct a resource identified by its class type. | |
ResourcePtr | create (const std::string &, const smtk::common::UUID &, const std::shared_ptr< smtk::common::Managers > &=nullptr) |
Construct a resource with a given UUID identified by its type name. | |
ResourcePtr | create (const Resource::Index &, const smtk::common::UUID &, const std::shared_ptr< smtk::common::Managers > &=nullptr) |
Construct a resource with a given UUID identified by its type index. | |
template<typename ResourceType > | |
smtk::shared_ptr< ResourceType > | create (const smtk::common::UUID &, const std::shared_ptr< smtk::common::Managers > &=nullptr) |
Construct a resource with a given UUID identified by its class type. | |
ResourcePtr | get (const smtk::common::UUID &id) |
Returns the resource that relates to the given uuid. More... | |
ConstResourcePtr | get (const smtk::common::UUID &id) const |
template<typename ResourceType > | |
smtk::shared_ptr< ResourceType > | get (const smtk::common::UUID &) |
Returns the resource that relates to the given uuid. More... | |
template<typename ResourceType > | |
smtk::shared_ptr< const ResourceType > | get (const smtk::common::UUID &) const |
ResourcePtr | get (const std::string &url) |
Returns the resource that relates to the given url. More... | |
ConstResourcePtr | get (const std::string &url) const |
template<typename ResourceType > | |
smtk::shared_ptr< ResourceType > | get (const std::string &url) |
Returns the resource that relates to the given url. More... | |
template<typename ResourceType > | |
smtk::shared_ptr< const ResourceType > | get (const std::string &url) const |
std::set< ResourcePtr > | find (const std::string &typeName) |
Returns a set of resources that have a given type name. | |
std::set< ResourcePtr > | find (const Resource::Index &typeIndex, bool strict=false) |
Returns a set of resources that have a given type index. More... | |
template<typename ResourceType > | |
std::set< smtk::shared_ptr< ResourceType > > | find () |
Returns a set of resources that are of the type ResourceType. | |
ResourcePtr | read (const std::string &, const std::string &, const std::shared_ptr< smtk::common::Managers > &=nullptr) |
Read resource identified by its type index from file. | |
ResourcePtr | read (const Resource::Index &, const std::string &, const std::shared_ptr< smtk::common::Managers > &=nullptr) |
Read resource identified by its type index from file. | |
template<typename ResourceType > | |
smtk::shared_ptr< ResourceType > | read (const std::string &, const std::shared_ptr< smtk::common::Managers > &=nullptr) |
Read resource from file. | |
bool | write (const ResourcePtr &, const std::shared_ptr< smtk::common::Managers > &=nullptr) |
Write resource to file. More... | |
bool | write (const ResourcePtr &, const std::string &, const std::shared_ptr< smtk::common::Managers > &=nullptr) |
Write resource to file. More... | |
bool | add (const Resource::Index &, const ResourcePtr &) |
Add a resource identified by its type index. More... | |
template<typename ResourceType > | |
bool | add (const smtk::shared_ptr< ResourceType > &) |
Add a resource identified by its class type. More... | |
bool | add (const ResourcePtr &) |
Returns true if the resource was added or already is part of this manager. | |
bool | remove (const ResourcePtr &) |
Removes a resource from a given Manager. More... | |
bool | addLegacyReader (const std::string &, const std::function< ResourcePtr(const std::string &)> &) |
To maintain backwards compatibility, this method provides a means of registering an alias, or additional type name, to a resource type. More... | |
void | reviseId (const Resource::SetId &source, const Resource::SetId &destination) |
Change the ID of a managed resource. More... | |
void | reviseLocation (const smtk::common::UUID &uid, const Resource::SetLocation &source, const Resource::SetLocation &destination) |
Change the location of a managed resource. More... | |
smtk::common::Termination | visit (const ResourceVisitor &visitor) const |
Visit resources held by this manager. More... | |
bool | empty () const |
Does the manager hold any resources? | |
std::size_t | size () const |
Return the number of resources held by the manager. More... | |
PersistentObjectPtr | search (const smtk::common::UUID &uid) const |
Search all managed resources for an object with the given UUID. More... | |
MetadataContainer & | metadata () |
Return the map of metadata. | |
Observers & | observers () |
Return the observers associated with this manager. More... | |
const Observers & | observers () const |
Metadata::Observers & | metadataObservers () |
Return the metadata observers associated with this manager. | |
const Metadata::Observers & | metadataObservers () const |
GarbageCollectorPtr | garbageCollector () |
Return a garbage collector used to clean up ephemeral objects after their use. | |
const std::unordered_map< smtk::string::Token, smtk::string::Token > & | objectTypeLabels () const |
Return a map from the type-name of any subclass of PersistentObject to a user-presentable label. More... | |
std::unordered_map< smtk::string::Token, smtk::string::Token > & | objectTypeLabels () |
A resource Manager is responsible for tracking currently allocated resources, creating new resources and serializing/deserializing resources to/from disk.
Resource types must first be registered with the Manager before resources of they can be manipulated by the manager.
bool smtk::resource::Manager::add | ( | const Resource::Index & | index, |
const ResourcePtr & | resource | ||
) |
Add a resource identified by its type index.
Returns true if the resource was added or already is part of this manager. If the resource is currently part of a different manager, we will reparent it to this manager.
bool smtk::resource::Manager::add | ( | const smtk::shared_ptr< ResourceType > & | resource | ) |
Add a resource identified by its class type.
Returns true if the resource was added or already is part of this manager.
bool smtk::resource::Manager::addLegacyReader | ( | const std::string & | alias, |
const std::function< ResourcePtr(const std::string &)> & | read | ||
) |
To maintain backwards compatibility, this method provides a means of registering an alias, or additional type name, to a resource type.
There can be multiple aliases for each resource type, but an alias can only refer to a single resource type.
void smtk::resource::Manager::clear | ( | ) |
Remove all resources.
This doesn't explicitly release the memory of the resources, it only stops the tracking of the resources by the manager.
std::set< smtk::resource::ResourcePtr > smtk::resource::Manager::find | ( | const Resource::Index & | typeIndex, |
bool | strict = false |
||
) |
Returns a set of resources that have a given type index.
If strict is true, only resource with the exact typeIndex (instead of resources that also inherit typeIndex) will be returned.
smtk::shared_ptr< ResourceType > smtk::resource::Manager::get | ( | const smtk::common::UUID & | id | ) |
Returns the resource that relates to the given uuid.
If no association exists of this type, this will return a null pointer.
smtk::resource::ResourcePtr smtk::resource::Manager::get | ( | const smtk::common::UUID & | id | ) |
Returns the resource that relates to the given uuid.
If no association exists this will return a null pointer
smtk::resource::ResourcePtr smtk::resource::Manager::get | ( | const std::string & | url | ) |
Returns the resource that relates to the given url.
If no association exists this will return a null pointer
smtk::shared_ptr< ResourceType > smtk::resource::Manager::get | ( | const std::string & | url | ) |
Returns the resource that relates to the given url.
If no association exists of this type, this will return a null pointer.
|
inline |
Return a map from the type-name of any subclass of PersistentObject to a user-presentable label.
This is not intended to produce multiple names for a single object type; if that functionality is required (i.e., inspection of individual instances of a class to determine a name), then another service should be offered.
This is intended to be populated by plugin registrars and not saved to resources or projects as document state. The order in which plugin registrars is called is dictated by their Dependencies, so your application can force its registrar to be invoked after registrars that may provide conflicting names.
In general, you should use the map like so:
|
inline |
Return the observers associated with this manager.
Note that observers may query but not modify the resource manager since it will be read-locked by the method that triggers the observers.
bool smtk::resource::Manager::remove | ( | const ResourcePtr & | resource | ) |
Removes a resource from a given Manager.
This doesn't explicitly release the memory of the resource, it only stops the tracking of the resource by the manager.
void smtk::resource::Manager::reviseId | ( | const Resource::SetId & | source, |
const Resource::SetId & | destination | ||
) |
Change the ID of a managed resource.
This method cannot be called directly (only Resource can create its arguments). Instead, call Resource::setId(), which will invoke this method if the resource has a manager set.
void smtk::resource::Manager::reviseLocation | ( | const smtk::common::UUID & | uid, |
const Resource::SetLocation & | source, | ||
const Resource::SetLocation & | destination | ||
) |
Change the location of a managed resource.
This method cannot be called directly (only Resource can create its arguments). Instead, call Resource::setLocation(), which will invoke this method if the resource has a manager set.
PersistentObjectPtr smtk::resource::Manager::search | ( | const smtk::common::UUID & | uid | ) | const |
Search all managed resources for an object with the given UUID.
If a null value is returned, no object has the uid or the object is unmanaged.
This is a potentially expensive operation; avoid using it if possible. It is typically O(m*log(n)), where m is the number of resources held by the manager and n is number of components held by each resource. This method visits each resource held by the manager (hence the linear complexity in the number of resources). If the UUID corresponds to the resource's ID, the resource is returned. Otherwise, the resource is asked to return the matching object; the first non-null result is returned.
|
inline |
Return the number of resources held by the manager.
Note that because this number may be changed by other threads even before this method returns, it is only intended as a convenience for single-threaded tests.
smtk::common::Termination smtk::resource::Manager::visit | ( | const ResourceVisitor & | visitor | ) | const |
Visit resources held by this manager.
This method read-locks the resource manager container. This means that visitors may query the resource manager but they may not alter the state of the container. If that must happen, changes should be queued on a captured variable and performed after this function returns.
This method returns Termination::NORMAL when all resources were traversed and Termination::EARLY when a visitor halted iteration.
bool smtk::resource::Manager::write | ( | const ResourcePtr & | resource, |
const std::shared_ptr< smtk::common::Managers > & | managers = nullptr |
||
) |
Write resource to file.
The resource's write location is held by the resource itself.
bool smtk::resource::Manager::write | ( | const ResourcePtr & | resource, |
const std::string & | url, | ||
const std::shared_ptr< smtk::common::Managers > & | managers = nullptr |
||
) |
Write resource to file.
The resource's write location is passed as an input parameter.