SMTK
@SMTK_VERSION@
Simulation Modeling Tool Kit
|
11 #ifndef smtk_resource_Resource_h
12 #define smtk_resource_Resource_h
14 #include "smtk/CoreExports.h"
16 #include "smtk/common/UUID.h"
18 #include "smtk/resource/Component.h"
19 #include "smtk/resource/Lock.h"
20 #include "smtk/resource/PersistentObject.h"
21 #include "smtk/resource/ResourceLinks.h"
23 #include "smtk/resource/query/BadTypeError.h"
24 #include "smtk/resource/query/Queries.h"
33 #include <unordered_map>
57 template<
typename Self,
typename Parent>
67 typedef std::size_t Index;
75 template<
typename Child,
typename Parent>
78 static const Resource::Index type_index;
86 static constexpr smtk::resource::Links::RoleType VisuallyLinkedRole = -4;
95 virtual Index
index()
const {
return std::type_index(
typeid(*
this)).hash_code(); }
99 template<
class ResourceType>
102 return this->isOfType(std::type_index(
typeid(ResourceType)).hash_code());
107 virtual bool isOfType(
const Index& index)
const;
111 virtual bool isOfType(
const std::string&
typeName)
const;
116 virtual int numberOfGenerationsFromBase(
const std::string&
typeName)
const;
121 const std::string& location()
const {
return m_location; }
124 virtual bool setLocation(
const std::string& location);
131 std::string name()
const override;
132 virtual bool setName(
const std::string& name);
133 bool isNameSet() {
return !m_name.empty(); }
144 virtual bool clean()
const {
return m_clean; }
145 void setClean(
bool state =
true);
168 template<
typename ComponentType>
171 return dynamic_cast<ComponentType*
>(this->component(uuid));
177 virtual std::function<bool(
const Component&)> queryOperation(
const std::string&)
const;
180 virtual void visit(std::function<
void(
const ComponentPtr&)>& v)
const = 0;
182 ComponentSet filter(
const std::string& queryString)
const;
187 template<
typename Collection>
188 Collection filterAs(
const std::string& queryString)
const;
190 Links& links()
override {
return m_links; }
191 const Links& links()
const override {
return m_links; }
193 Properties& properties()
override {
return m_properties; }
194 const Properties& properties()
const override {
return m_properties; }
196 const Queries& queries()
const {
return m_queries; }
197 Queries& queries() {
return m_queries; }
204 LockType
locked()
const {
return m_lock.state(); }
210 virtual
bool setUnitsSystem(const shared_ptr<units::System>& unitsSystem);
211 const shared_ptr<units::System>& unitsSystem()
const {
return m_unitsSystem; }
222 std::shared_ptr<units::System> m_unitsSystem;
236 void operator()(
ResourcePtr& resource)
const { resource->m_id = m_id; }
249 SetLocation(
const std::string& url)
254 void operator()(
ResourcePtr& resource)
const { resource->m_location = m_url; }
256 std::string location()
const {
return m_url; }
258 const std::string& m_url;
262 std::string m_location;
268 Properties m_properties;
270 bool m_markedForRemoval =
false;
274 template<
typename Collection>
288 std::dynamic_pointer_cast<typename Collection::value_type::element_type>(
component);
291 col.insert(col.end(), entry);
296 this->
visit(visitor);
307 template<
typename QueryType>
310 const auto* resource =
dynamic_cast<const Resource*
>(&object);
313 const auto*
const component =
dynamic_cast<const Component*
>(&object);
316 resource = component->
resource().get();
321 return resource->queries().get<QueryType>();
328 #endif // smtk_resource_Resource_h
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
smtk::weak_ptr< smtk::resource::Manager > WeakManagerPtr
Definition: PublicPointerDefs.h:283
void setMarkedForRemoval(bool val)
Mark the resource to indicate it is about to removed (meaning it is being removed from memory not nec...
Definition: Resource.h:149
Links is a virtual class describing the API for connecting one resource/component to another resource...
Definition: Links.h:29
Derived resources are subclassed from smtk::resource::Resource.
Definition: DerivedFrom.h:32
virtual bool isMarkedForRemoval() const
Return whether the object is marked for removal.
Definition: Resource.h:152
const smtk::common::UUID & id() const override
id and location are run-time intrinsics of the derived resource; we need to allow the user to reset t...
Definition: Resource.h:120
ComponentType * componentAs(const smtk::common::UUID &uuid) const
A templated version of component() that casts its result to a type.
Definition: Resource.h:169
Collection filterAs(const std::string &queryString) const
given a a std::string describing a query and a type of container, return a set of components that sat...
Definition: Resource.h:275
virtual Index index() const
index is a compile-time intrinsic of the derived resource; as such, it cannot be set.
Definition: Resource.h:95
An exception to throw when a type is requested that does not exist in a container.
Definition: BadTypeError.h:34
This specialization of smtk::resource::Properties completes aforementioned class's implementation by ...
Definition: Properties.h:518
virtual Component * component(const smtk::common::UUID &compId) const
Given a component's UUID, return a raw pointer to the component.
Definition: Resource.cxx:93
The ResourceLinks class is a resource-specific API for manipulating unidirectional links from a Resou...
Definition: ResourceLinks.h:71
std::set< smtk::resource::ComponentPtr > ComponentSet
Definition: PublicPointerDefs.h:319
virtual void visit(std::function< void(const ComponentPtr &)> &v) const =0
visit all components in a resource.
A class for registering and accessing Query types.
Definition: Queries.h:30
ManagerPtr manager() const
Resources that are managed have a non-null pointer to their manager.
Definition: Resource.h:154
A utility for holding multiple lock-guards at once.
Definition: Lock.h:107
virtual bool clean() const
Indicate whether the resource is in sync with its location.
Definition: Resource.h:144
#define smtkSharedFromThisMacro(...)
A macro to help with derived classes whose bases enable shared_from_this().
Definition: SharedFromThis.h:250
Operations need the ability to lock and unlock resources, but no additional access privilege is requi...
Definition: Resource.h:50
Operation is a base class for all SMTK operations.
Definition: Operation.h:61
#define smtkTypeMacro(...)
Add typedefs to a class for identifcation.
Definition: SharedFromThis.h:128
virtual const ResourcePtr resource() const =0
Components are required to return their owning resource (if any).
bool isOfType() const
given a resource type, return whether or not this resource is or is derived from the resource describ...
Definition: Resource.h:100
#define smtkSuperclassMacro(...)
Add a typedef to the superclass of this class.
Definition: SharedFromThis.h:147
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 ...
Definition: Resource.cxx:98
std::string typeName()
Return the name of a class.
Definition: TypeName.h:289
An abstract base class for SMTK resources.
Definition: Resource.h:64
A read/write lock for resources.
Definition: Lock.h:42
Lock & lock(Key()) const
classes that are granted permission to the key may retrieve the resource's lock.
Definition: Resource.h:201
Component is the base class for records stored in an smtk::resource::Resource.
Definition: Component.h:43
LockType locked() const
Anyone can query whether or not the resource is locked.
Definition: Resource.h:204
A resource Manager is responsible for tracking currently allocated resources, creating new resources ...
Definition: Manager.h:47
An abstract base class for SMTK resources and their components.
Definition: PersistentObject.h:39
smtk::shared_ptr< smtk::resource::Manager > ManagerPtr
Definition: PublicPointerDefs.h:281
smtk::shared_ptr< smtk::resource::Component > ComponentPtr
Definition: PublicPointerDefs.h:297
SMTKCORE_NO_EXPORT QueryType & queryForObject(const PersistentObject &object)
Given an object, return a query for interrogating it.
Definition: Resource.h:308
smtk::shared_ptr< smtk::resource::Resource > ResourcePtr
Definition: PublicPointerDefs.h:295