SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
smtk::graph::Resource< Traits > Class Template Reference

A resource for conceptual modeling of geometric components. More...

#include <Resource.h>

Collaboration diagram for smtk::graph::Resource< Traits >:
[legend]

Classes

struct  CreateNodeOfType
 A functor to create smtk::string::Tokens of accepted node types. More...
 
struct  NodeTypeNames
 A functor to create smtk::string::Tokens of accepted node types. More...
 

Public Types

using NodeContainer = typename detail::GraphTraits< Traits >::NodeContainer
 
using TypeTraits = Traits
 
template<typename NodeType >
using is_node = smtk::tuple_contains< NodeType, typename detail::GraphTraits< Traits >::NodeTypes >
 
template<typename ArcType >
using is_arc = smtk::tuple_contains< ArcType, typename detail::GraphTraits< Traits >::ArcTypes >
 

Public Member Functions

 smtkTypedefs (smtk::graph::Resource< Traits >)
 
std::string typeName () const override
 Return the resource's type, which is used by the resource manager and for persistent storage.
 
 smtkCreateMacro (smtk::graph::Resource< Traits >)
 
 smtkSuperclassMacro (smtk::resource::DerivedFrom< Resource< Traits >, ResourceBase >)
 
 smtkSharedFromThisMacro (smtk::resource::PersistentObject)
 
template<typename NodeType , typename... T>
std::enable_if< is_node< NodeType >::value, std::shared_ptr< NodeType > >::type create (T &&... parameters)
 Create a node of type NodeType with additional constructor arguments. More...
 
template<typename NodeType >
std::enable_if< is_node< NodeType >::value, bool >::type add (const std::shared_ptr< NodeType > &node)
 Add a node of type NodeType to the resource. More...
 
template<typename NodeType >
std::enable_if< is_node< NodeType >::value, bool >::type remove (const std::shared_ptr< NodeType > &node)
 Remove a node from the resource. Return true if the removal took place.
 
const ArcMaparcs () const override
 Access the arcs of the graph resource.
 
ArcMaparcs () override
 
std::function< bool(const smtk::resource::Component &)> queryOperation (const std::string &filterString) const override
 Return a functor that tests a node (component) against a string query.
 
 Resource (const Resource &) noexcept=delete
 Copy construction of resources is disallowed.
 
std::shared_ptr< smtk::resource::Componentfind (const smtk::common::UUID &uuid) const override
 Return a shared pointer to a node (component) given its UUID.
 
smtk::resource::Componentcomponent (const smtk::common::UUID &uuid) const override
 Return a raw pointer to a node (component) given its UUID.
 
void visit (std::function< void(const smtk::resource::ComponentPtr &)> &v) const override
 Visit all the components (nodes.
 
template<typename Functor , typename... Args>
void evaluateArcs (Args &&... args) const
 Invoke a Functor on each arc-type's implementation. More...
 
template<typename Functor , typename... Args>
void evaluateArcs (Args &&... args)
 
const std::set< smtk::string::Token > & nodeTypes () const override
 Return the set of node types accepted by this resource.
 
const std::set< smtk::string::Token > & arcTypes () const override
 Return the set of arc types accepted by this resource.
 
ComponentcreateNodeOfType (smtk::string::Token nodeTypeName) override
 Implement the generic (untyped) graph API for inserting nodes.
 
bool connect (Component *from, Component *to, smtk::string::Token arcType) override
 Implement the generic (untyped) graph API for inserting arcs. More...
 
bool disconnect (Component *node, bool explicitOnly) override
 Remove all arcs (or only explicit arcs) from the given node.
 
void dump (const std::string &filename, const std::string &mimeType="text/vnd.graphviz") const override
 Dump the resource nodes and arcs to a file. More...
 

Protected Member Functions

std::size_t eraseNodes (const smtk::graph::ComponentPtr &node) override
 
bool insertNode (const smtk::graph::ComponentPtr &node) override
 Insert a node without performing any type-safety checks.
 
bool isNodeTypeAcceptable (const smtk::graph::ComponentPtr &node) override
 Perform a run-time check to validate that a node is acceptable to this resource.
 
void initializeResource ()
 
 Resource (smtk::resource::ManagerPtr manager=nullptr)
 
 Resource (const smtk::common::UUID &uid, smtk::resource::ManagerPtr manager=nullptr)
 

Protected Attributes

ArcMap m_arcs
 
std::set< smtk::string::Tokenm_nodeTypes
 
std::set< smtk::string::Tokenm_arcTypes
 

Detailed Description

template<typename Traits>
class smtk::graph::Resource< Traits >

A resource for conceptual modeling of geometric components.

The smtk::graph::Resource is defined by a Traits type that defines the node types and arc types of a multipartite graph. The node types must all inherit from smtk::graph::Component and comprise the elements of the resource. The arc types can be any type, and can represent a 1-to-1 or 1-to-many relationship between node types.

Member Function Documentation

◆ add()

template<typename Traits >
template<typename NodeType >
std::enable_if<is_node<NodeType>::value, bool>::type smtk::graph::Resource< Traits >::add ( const std::shared_ptr< NodeType > &  node)
inline

Add a node of type NodeType to the resource.

Return true if the insertion took place.

◆ connect()

template<typename Traits >
bool smtk::graph::Resource< Traits >::connect ( Component from,
Component to,
smtk::string::Token  arcType 
)
inlineoverride

Implement the generic (untyped) graph API for inserting arcs.

The from and to nodes are checked to ensure they are owned by this resource and the proper type for this resource. This method returns true if the arc was inserted and false if it already existed or was inappropriate.

This method is considered "untyped" because the types of both the endpoint nodes and arc are unknown at compile-time. Type safety is ensured by run-time checks.

◆ create()

template<typename Traits >
template<typename NodeType , typename... T>
std::enable_if<is_node<NodeType>::value, std::shared_ptr<NodeType> >::type smtk::graph::Resource< Traits >::create ( T &&...  parameters)
inline

Create a node of type NodeType with additional constructor arguments.

Sometimes, it is necessary to have access to a shared pointer to the constructed node during initialization (especially if using the RAII (Resource Acquisition Is Initialization) idiom). Because shared pointers to objects cannot be used within that object's constructor, this method will invoke an initializer method on the node after the node is constructed (if one exists). The initializer must be a method of NodeType named initialize() whose arguments are a the parameters passed to this method.

◆ dump()

template<typename Traits >
void smtk::graph::Resource< Traits >::dump ( const std::string &  filename,
const std::string &  mimeType = "text/vnd.graphviz" 
) const
inlineoverride

Dump the resource nodes and arcs to a file.

This is a convenience method for debugging; its arguments are easy to pass to an interactive debugger. Internally, it calls evaluateArcs<evaluators::Dump>(...) to produce output. See evaluators::Dump for more information.

◆ evaluateArcs()

template<typename Traits >
template<typename Functor , typename... Args>
void smtk::graph::Resource< Traits >::evaluateArcs ( Args &&...  args) const
inline

Invoke a Functor on each arc-type's implementation.

The functor should have a templated parenthesis operator whose template parameter is the arc implementation object type, which determines the the functor's first argument type. This type varies for each ArcTraits type in TypeTraits::ArcTypes and will be ArcImplementation<ArcTraits>*.

The following arguments the functor's parenthesis-operator takes are args forwarded from this method.

This method allows you to traverse all types of arcs present in the resource for inspection or modification.


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