SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
smtk::task::Port Class Reference

Ports are components that pass information between tasks of a workflow. More...

#include <Port.h>

Inheritance diagram for smtk::task::Port:
[legend]
Collaboration diagram for smtk::task::Port:
[legend]

Public Types

enum  Direction { In, Out }
 Whether the task fetches data from a port or provides data for a port. More...
 
enum  Access { Internal, External }
 Whether the task fetches data from a port or provides data for a port. More...
 
using Configuration = nlohmann::json
 Ports may be configured with arbitrary JSON objects.
 
- Public Types inherited from smtk::resource::Component
typedef std::function< void(const ComponentPtr &)> Visitor
 
typedef detail::ComponentLinks Links
 
typedef detail::ComponentProperties Properties
 

Public Member Functions

 smtkTypeMacro (smtk::task::Port)
 
 smtkSuperclassMacro (smtk::resource::Component)
 
 smtkCreateMacro (smtk::resource::PersistentObject)
 
 Port (const Configuration &config, Task *parentTask, const std::shared_ptr< smtk::common::Managers > &managers=nullptr)
 
 Port (const Configuration &config, Manager &taskManager, const std::shared_ptr< smtk::common::Managers > &managers=nullptr)
 
virtual void configure (const Configuration &config)
 A method called by all constructors passed Configuration information. More...
 
virtual void configureConnections (const Configuration &connConfig)
 Add port connections from configuration data. More...
 
const common::UUIDid () const override
 Set/get the task's unique identifier.
 
bool setId (const common::UUID &newId) override
 Assign an ID to this object (used by readers; not for arbitrary reuse). More...
 
std::string name () const override
 Return the task's name.
 
virtual bool setName (const std::string &name)
 
Direction direction () const
 Return the port's direction. More...
 
Access access () const
 Return the port's access. More...
 
std::unordered_set< smtk::string::Token > & dataTypes ()
 Return the types of data this port is allowed to pass.
 
const std::unordered_set< smtk::string::Token > & dataTypes () const
 
const std::unordered_set< PersistentObject * > & connections () const
 Return the set of port connections. More...
 
std::unordered_set< PersistentObject * > & connections ()
 
virtual std::shared_ptr< PortDataportData (smtk::resource::PersistentObject *object) const
 Return PortData for a given object in connections(). More...
 
const std::shared_ptr< resource::Resourceresource () const override
 Components are required to return their owning resource (if any). More...
 
smtk::string::Token unassignedRole () const
 Return a role to be assigned to connections that are not ports. More...
 
const std::unordered_set< smtk::string::Token > & style () const
 Set/get style classes for the port. More...
 
bool addStyle (const smtk::string::Token &styleClass)
 
bool removeStyle (const smtk::string::Token &styleClass)
 
bool clearStyle ()
 
virtual bool getViewData (smtk::common::TypeContainer &configuration) const
 Populate a type-container with view-related data for configuration. More...
 
Taskparent () const
 Return a parent task if one exists; null otherwise.
 
bool setParent (Task *parent)
 Set the parent task of a port. More...
 
std::string describe () const
 Return an XHTML description of the port and its data.
 
- Public Member Functions inherited from smtk::resource::Component
 smtkTypeMacro (smtk::resource::Component)
 
 smtkSuperclassMacro (smtk::resource::PersistentObject)
 
 smtkSharedFromThisMacro (smtk::resource::PersistentObject)
 
ResourceparentResource () const override
 Return a raw (not shared) pointer to the resource that owns this component. More...
 
template<typename ResourceType >
ResourceType * parentResourceAs () const
 This variant of parentResource casts the result to the given ResourceType.
 
Linkslinks () override
 Return the links that connect this component to external resources/components.
 
const Linkslinks () const override
 
Propertiesproperties () override
 Return properties defined on this component.
 
const Propertiesproperties () const override
 
- 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 Member Functions

static Direction DirectionFromLabel (const std::string &label)
 Convert Direction enumerants to/from labels.
 
static smtk::string::Token LabelFromDirection (Direction dir)
 
static Access AccessFromLabel (const std::string &label)
 Convert Access enumerants to/from labels.
 
static smtk::string::Token LabelFromAccess (Access ac)
 

Protected Attributes

smtk::common::UUID m_id
 The unique identifier for this task.
 
std::string m_name
 A task name to present to the user.
 
Taskm_parent = nullptr
 The task which owns this port.
 
std::weak_ptr< smtk::task::Managerm_manager
 If this task is being managed, this will refer to its manager.
 
Direction m_direction { Direction::In }
 The direction of this port.
 
Access m_access { Access::External }
 The access of this port with respect to its task.
 
std::unordered_set< PersistentObject * > m_connections
 The port's upstream/downstream connections.
 
std::unordered_set< smtk::string::Tokenm_dataTypes
 The subclasses of PortData this port is allowed to pass.
 
smtk::string::Token m_unassignedRole
 The role which "bare" objects in m_connections should be assigned. More...
 
std::unordered_set< smtk::string::Tokenm_style
 The set of style classes for this task.
 

Detailed Description

Ports are components that pass information between tasks of a workflow.

Tasks are objects in a workflow that require users to perform work, make a decision, or provide information. Ports provide a way to model the flow of user-provided information between tasks.

Each port provides types of information that will be passed to or from its parent task.

A task may own 0 or more ports. Workflow designers and/or users may connect ports owned by different tasks via an adaptor; as long as the ports model information of matching types, data can be fetched as needed by the downstream task. When requesting data from a task, its ports are used as keys.

Member Enumeration Documentation

◆ Access

Whether the task fetches data from a port or provides data for a port.

Enumerator
Internal 

This port is inward facing and is used by its task's children.

External 

This port is outward facing and is used by other tasks.

◆ Direction

Whether the task fetches data from a port or provides data for a port.

Enumerator
In 

The task fetches data from this port.

Out 

The task provides data for this port.

Member Function Documentation

◆ access()

Access smtk::task::Port::access ( ) const
inline

Return the port's access.

A port's access may not change; it should be set by configure(), which is called at construction.

◆ configure()

void smtk::task::Port::configure ( const Configuration config)
virtual

A method called by all constructors passed Configuration information.

In general, this method should set member variables directly instead of calling set/get methods since those may invoke observers with an uninitialized object.

◆ configureConnections()

void smtk::task::Port::configureConnections ( const Configuration connConfig)
virtual

Add port connections from configuration data.

This method is called by configure() but may also be called elsewhere. Specifically, the task::Manager's from_json() function calls it after all of a project's persistent objects have been constructed to ensure the connections are able to be assigned.

Note that connConfig is not the same as the config parameter passed to Port::configure(). Instead, it is a subitem of config that holds only connections.

◆ connections()

const std::unordered_set<PersistentObject*>& smtk::task::Port::connections ( ) const
inline

Return the set of port connections.

If the Port::Direction is In, these connections are objects upstream of the port. If the Port::Direction is Out, the connected objects are downstream of the port.

◆ direction()

Direction smtk::task::Port::direction ( ) const
inline

Return the port's direction.

A port's direction may not change; it should be set by configure(), which is called at construction.

◆ getViewData()

bool smtk::task::Port::getViewData ( smtk::common::TypeContainer configuration) const
virtual

Populate a type-container with view-related data for configuration.

Subclasses should override this method. Generally, views will want access to a resource and potentially components in the resource that are the subject of the view. Other view configuration will come from view style() (see above) or smtk::common::Managers.

This method will return true when the configuration was modified and false otherwise.

◆ portData()

std::shared_ptr< PortData > smtk::task::Port::portData ( smtk::resource::PersistentObject object) const
virtual

Return PortData for a given object in connections().

If object is not a port, the base Port class will either (a) construct an ObjectsInRoles instance holding the object in the unassignedRole(); or (b) return a null pointer, depending on whethern ObjectsInRoles is listed in the set returned by dataTypes().

If object is a port, the task will be asked to produce a PortData instance.

◆ resource()

const std::shared_ptr< resource::Resource > smtk::task::Port::resource ( ) const
overridevirtual

Components are required to return their owning resource (if any).

Components may not have an owning resource at some points in their lifecycle, so be sure to verify the returned value is non-null.

Implements smtk::resource::Component.

◆ setId()

bool smtk::task::Port::setId ( const 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.

◆ setParent()

bool smtk::task::Port::setParent ( Task parent)

Set the parent task of a port.

Tasks should call this when they take ownership of a port.

◆ style()

const std::unordered_set<smtk::string::Token>& smtk::task::Port::style ( ) const
inline

Set/get style classes for the port.

A style class specifies how applications should present the port (e.g., what type of view to provide the user, what rendering mode to use, what objects to list or exclude).

◆ unassignedRole()

smtk::string::Token smtk::task::Port::unassignedRole ( ) const
inline

Return a role to be assigned to connections that are not ports.

Since persistent objects that are not ports cannot produce smtk::task::PortData themselves (that includes roles for objects), this helps ports produce ObjectsInRoles data (where a role is required).

Member Data Documentation

◆ m_unassignedRole

smtk::string::Token smtk::task::Port::m_unassignedRole
protected

The role which "bare" objects in m_connections should be assigned.

This defaults to "unassigned".


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