Inviwo
0.9.10.1
Inviwo documentation
|
A resource manager to store data to avoid creating/loading the same dataset twice. More...
#include <resourcemanager.h>
Public Member Functions | |
template<typename T > | |
std::shared_ptr< T > | getResource (const std::string &key) |
Finds and returns the resource with given key and type. More... | |
template<typename T > | |
void | addResource (const std::string &key, std::shared_ptr< T > resource, bool overwrite=false) |
Adds a resource to the manager. More... | |
template<typename T > | |
bool | hasResource (const std::string &key) const |
Checks if a resource of type T with given key exists. More... | |
template<typename T > | |
void | removeResource (const std::string &key) |
Removes a resource from the manager. More... | |
void | removeResource (const std::string &key, const std::type_index &type) |
Removes a resource from the manager. More... | |
void | clear () |
Clears the resource manager. More... | |
bool | isEnabled () const |
Returns true if the resource manager is enabled. | |
void | setEnabled (bool enable=true) |
Enable or disable the resource manager Notifys observers by calling ResourceManagerObservable::notifyEnableChanged. More... | |
size_t | numberOfResources () const |
Public Member Functions inherited from inviwo::Observable< ResourceManagerObserver > | |
Observable (const Observable< ResourceManagerObserver > &other) | |
Observable (Observable< ResourceManagerObserver > &&other) | |
Observable< ResourceManagerObserver > & | operator= (const Observable< ResourceManagerObserver > &other) |
Observable< ResourceManagerObserver > & | operator= (Observable< ResourceManagerObserver > &&other) |
void | addObserver (ResourceManagerObserver *observer) |
void | removeObserver (ResourceManagerObserver *observer) |
virtual void | startBlockingNotifications () override final |
virtual void | stopBlockingNotifications () override final |
Additional Inherited Members | |
Protected Member Functions inherited from inviwo::ResourceManagerObservable | |
void | notifyResourceAdded (const std::string &key, const std::type_index &type, Resource *resource) |
void | notifyResourceRemoved (const std::string &key, const std::type_index &type, Resource *resource) |
void | notifyEnableChanged () |
Protected Member Functions inherited from inviwo::Observable< ResourceManagerObserver > | |
void | forEachObserver (C callback) |
Protected Member Functions inherited from inviwo::ObservableInterface | |
void | addObservationHelper (Observer *observer) |
void | removeObservationHelper (Observer *observer) |
A resource manager to store data to avoid creating/loading the same dataset twice.
To avoid loading the same data twice, resources are stored in a std::unordered_map are hashed by type and key. Key should uniquely describe the dataset, for example, when loading a file from disk the filename could be used.
Example Usage:
void inviwo::ResourceManager::addResource | ( | const std::string & | key, |
std::shared_ptr< T > | resource, | ||
bool | overwrite = false |
||
) |
Adds a resource to the manager.
key | key of the resource to add |
resource | a shared_ptr to the data to store |
overwrite | a flag to indicate if overwriting existing resources is allowed. |
inviwo::ResourceException | if resource with key and type T exists and overwrite is set to false |
void inviwo::ResourceManager::clear | ( | ) |
Clears the resource manager.
Does not release the memory if the data is used somewhere else.
std::shared_ptr< T > inviwo::ResourceManager::getResource | ( | const std::string & | key | ) |
Finds and returns the resource with given key and type.
key | key of the resource to find |
inviwo::ResourceException | if resource with key and type T could not be found |
bool inviwo::ResourceManager::hasResource | ( | const std::string & | key | ) | const |
Checks if a resource of type T with given key exists.
key | the key to look for |
size_t inviwo::ResourceManager::numberOfResources | ( | ) | const |
Returns the number of added resources
void inviwo::ResourceManager::removeResource | ( | const std::string & | key | ) |
Removes a resource from the manager.
Does not release the memory if the data is used somewhere else.
key | the key of the resource to remove |
void inviwo::ResourceManager::removeResource | ( | const std::string & | key, |
const std::type_index & | type | ||
) |
Removes a resource from the manager.
Does not release the memory if the data is used somewhere else.
This method is called from the ResourceManagerDockWidget when removing a resource.
key | the key of the resource to remove |
type | the type as a string of the resource to remove |
void inviwo::ResourceManager::setEnabled | ( | bool | enable = true | ) |
Enable or disable the resource manager Notifys observers by calling ResourceManagerObservable::notifyEnableChanged.