SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
smtk::resource::Resource Class Referenceabstract

An abstract base class for SMTK resources. More...

#include <Resource.h>

Inheritance diagram for smtk::resource::Resource:
[legend]
Collaboration diagram for smtk::resource::Resource:
[legend]

Public Types

typedef std::size_t Index
 
typedef smtk::resource::Metadata Metadata
 
typedef detail::ResourceLinks Links
 
typedef detail::ResourceProperties Properties
 
typedef query::Queries Queries
 

Public Member Functions

 smtkTypeMacro (smtk::resource::Resource)
 
 smtkSuperclassMacro (smtk::resource::PersistentObject)
 
 smtkSharedFromThisMacro (smtk::resource::PersistentObject)
 
virtual Index index () const
 index is a compile-time intrinsic of the derived resource; as such, it cannot be set.
 
template<class ResourceType >
bool isOfType () const
 given a resource type, return whether or not this resource is or is derived from the resource described by the index.
 
virtual bool isOfType (const Index &index) const
 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 std::string &typeName) const
 given a resource's unique name, return whether or not this resource is or is derived from the resource described by the name.
 
virtual int numberOfGenerationsFromBase (const std::string &typeName) const
 given a resource's unique name, return the number of generations derived from the resource described from the name (or a negative value if this resource is not derived from the input resource type).
 
const smtk::common::UUIDid () const override
 id and location are run-time intrinsics of the derived resource; we need to allow the user to reset these values.
 
const std::string & location () const
 
bool setId (const smtk::common::UUID &myID) override
 Assign an ID to this object (used by readers; not for arbitrary reuse). More...
 
bool setLocation (const std::string &location)
 
std::string name () const override
 Return the user-assigned name of the resource. More...
 
bool setName (const std::string &name)
 
bool isNameSet ()
 
virtual bool clean () const
 Indicate whether the resource is in sync with its location. More...
 
void setClean (bool state=true)
 
void setMarkedForRemoval (bool val)
 Mark the resource to indicate it is about to removed (meaning it is being removed from memory not necessarily for deletion)
 
virtual bool isMarkedForRemoval () const
 Return whether the object is marked for removal.
 
ManagerPtr manager () const
 Resources that are managed have a non-null pointer to their manager.
 
virtual ComponentPtr find (const smtk::common::UUID &compId) const =0
 Given a resource component's UUID, return the resource component.
 
virtual Componentcomponent (const smtk::common::UUID &compId) const
 Given a component's UUID, return a raw pointer to the component.
 
template<typename ComponentType >
ComponentType * componentAs (const smtk::common::UUID &uuid) const
 A templated version of component() that casts its result to a type. More...
 
virtual std::function< bool(const Component &)> queryOperation (const std::string &) const
 given a std::string describing a query, return a functor for performing the query (accepts component as input, returns true if the component satisfies the query parameters).
 
virtual void visit (std::function< void(const ComponentPtr &)> &v) const =0
 visit all components in a resource.
 
ComponentSet find (const std::string &queryString) const
 Given a a std::string describing a query, return a set of components that satisfy the query criteria.
 
ComponentSet filter (const std::string &queryString) const
 
template<typename Collection >
Collection findAs (const std::string &queryString) const
 given a a std::string describing a query and a type of container, return a set of components that satisfy both. More...
 
template<typename Collection >
Collection filterAs (const std::string &queryString) const
 
Linkslinks () override
 
const Linkslinks () const override
 
Propertiesproperties () override
 
const Propertiesproperties () const override
 
const Queriesqueries () const
 
Queriesqueries ()
 
Locklock (Key()) const
 classes that are granted permission to the key may retrieve the resource's lock.
 
LockType locked () const
 Anyone can query whether or not the resource is locked.
 
 Resource (Resource &&) noexcept
 
- Public Member Functions inherited from smtk::resource::PersistentObject
 smtkTypeMacroBase (smtk::resource::PersistentObject)
 
template<typename T >
T::Ptr as ()
 Attempt to cast this object to a subclass.
 
template<typename T >
T::ConstPtr as () const
 Attempt to cast this object to a subclass.
 

Static Public Attributes

static const Resource::Index type_index = std::type_index(typeid(Resource)).hash_code()
 

Protected Member Functions

 Resource (const smtk::common::UUID &, ManagerPtr manager=nullptr)
 
 Resource (ManagerPtr manager=nullptr)
 

Protected Attributes

WeakManagerPtr m_manager
 

Friends

class Manager
 The Manager is a singleton interface for registering available plugins to manager instances. More...
 
template<typename Child , typename Parent >
class DerivedFrom
 

Detailed Description

An abstract base class for SMTK resources.

Member Function Documentation

◆ clean()

virtual bool smtk::resource::Resource::clean ( ) const
inlinevirtual

Indicate whether the resource is in sync with its location.

Resources that have a non-empty location and are identical to the data stored at location are clean. All other resources are dirty.

Operations that are write-operators (i.e., not read-only) should mark resources as modified. Saving a resource using its metadata's write method will mark the resource as clean. Loading a resource using its metadata's read method should return a clean resource.

Reimplemented in smtk::project::Project.

◆ componentAs()

template<typename ComponentType >
ComponentType* smtk::resource::Resource::componentAs ( const smtk::common::UUID uuid) const
inline

A templated version of component() that casts its result to a type.

This method performs a dynamic cast, so it may return nullptr even if there is a component with a matching uuid (in the case that it is of a different type than ComponentType).

◆ findAs()

template<typename Collection >
Collection smtk::resource::Resource::findAs ( const std::string &  queryString) const
inline

given a a std::string describing a query and a type of container, return a set of components that satisfy both.

Note that since this uses a dynamic pointer cast this can be slower than other find methods.

◆ name()

std::string smtk::resource::Resource::name ( ) const
overridevirtual

Return the user-assigned name of the resource.

If no name has been assigned, return the stem of its filename. You may use isNameSet() to determine whether the returned name is generated or assigned.

Reimplemented from smtk::resource::PersistentObject.

◆ setId()

bool smtk::resource::Resource::setId ( const smtk::common::UUID myID)
overridevirtual

Assign an ID to this object (used by readers; not for arbitrary reuse).

TODO: care must be taken to modify the recorded ID in all links that connect to this object (see Resource::setId and its treatment of manager registration for reference).

Implements smtk::resource::PersistentObject.

Friends And Related Function Documentation

◆ Manager

friend class Manager
friend

The Manager is a singleton interface for registering available plugins to manager instances.

When a plugin is loaded, it creates a Client that adds itself to Manager's set of Client weak_ptrs. When a manager instance is passed into the Manager's "registerPluginsTo" method, each Client in the set that accepts a manager of this type constructs a Registry that tethers the scope of the manager's ability to use features from the plugin to the lifetime of the Registry object. Additionally, when a manager is passed into this class a register function is created that facilitates the registration of future plugins to the manager.


The documentation for this class was generated from the following files: