smgl 0.11.0
Structured Metadata Engine and Graph Objects Library
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
smgl::OutputPort< T, Args > Class Template Reference

Typed OutputPort class. More...

#include <smgl/Ports.hpp>

Inheritance diagram for smgl::OutputPort< T, Args >:
[legend]
Collaboration diagram for smgl::OutputPort< T, Args >:
[legend]

Classes

struct  TypedConnection
 Describes typed connections from an output port. More...
 

Public Types

using Arguments = std::tuple< Args... >
 
- Public Types inherited from smgl::Port
enum class  State { Idle , Waiting , Queued , Error }
 

Public Member Functions

 ~OutputPort () override
 
 OutputPort (T source)
 Construct with a copy of source. Source is effectively constant.
 
 OutputPort (T *source)
 Construct with a pointer to a source.
 
 OutputPort (std::function< T(Args...)> source, Args &&... args)
 Construct with a function source.
 
template<class Obj , class ObjMemberFn >
 OutputPort (Obj *obj, ObjMemberFn &&fn, Args &&... args)
 Construct with a member function source.
 
 OutputPort (const OutputPort &)=delete
 
OutputPortoperator= (const OutputPort &)=delete
 
 OutputPort (const OutputPort &&)=delete
 
OutputPortoperator= (const OutputPort &&)=delete
 
std::vector< ConnectiongetConnections () const override
 Get a list of active connections.
 
std::size_t numConnections () const override
 Get the number of active connections.
 
void setArgs (Args &&... args)
 Set the arguments passed to a function source.
 
val ()
 Get the current value of source.
 
operator() ()
 Get the current value of source.
 
bool update () override
 Update all active connections with the value of the source.
 
void notify (State s) override
 Notify all active connections of this port's state.
 
Metadata serialize () override
 Get port metadata.
 
void deserialize (const Metadata &m) override
 Load port metadata.
 
template<std::size_t... Is>
auto run_ (std::tuple< Args... > &tup, std::index_sequence< Is... >) -> T
 
- Public Member Functions inherited from smgl::Port
State state () const
 
void setState (State s)
 
void setParent (Node *p)
 
- Public Member Functions inherited from smgl::UniquelyIdentifiable
auto uuid () const -> Uuid
 
void setUuid (const Uuid &uuid)
 

Private Member Functions

template<std::size_t... Is>
run_ (std::tuple< Args... > &tup, std::index_sequence< Is... >)
 
run_ (std::tuple< Args... > &tup)
 
void connect (Input *ip) final
 
void disconnect (Input *ip) final
 

Private Attributes

std::function< T(Args...)> source_
 
Arguments args_
 
std::unordered_map< Uuid, TypedConnectionconnections_
 

Additional Inherited Members

- Protected Member Functions inherited from smgl::Output
 Output ()
 
 ~Output () override=default
 
- Protected Member Functions inherited from smgl::Port
 Port ()=default
 
 Port (State s)
 
virtual ~Port ()=default
 
- Protected Member Functions inherited from smgl::UniquelyIdentifiable
 UniquelyIdentifiable ()=default
 
- Protected Attributes inherited from smgl::Port
State state_ {State::Idle}
 
Nodeparent_ {nullptr}
 
- Protected Attributes inherited from smgl::UniquelyIdentifiable
Uuid uuid_ {Uuid::Uuid4()}
 

Detailed Description

template<typename T, typename... Args>
class smgl::OutputPort< T, Args >

Typed OutputPort class.

An OutputPort provides access to the value of its source. It is similar to a getter function. On update(), it posts the current value of source to all connected InputPorts. T should be default constructible.

Template Parameters
TType of object received by this port

Definition at line 294 of file Ports.hpp.

Member Typedef Documentation

◆ Arguments

template<typename T , typename... Args>
using smgl::OutputPort< T, Args >::Arguments = std::tuple<Args...>

If source_ is a function, a tuple storing a list of arguments that can be passed to source_

Definition at line 301 of file Ports.hpp.

Constructor & Destructor Documentation

◆ ~OutputPort()

template<typename T , typename... Args>
smgl::OutputPort< T, Args >::~OutputPort ( )
override

Destructor performs auto-disconnect

Definition at line 112 of file PortsImpl.hpp.

◆ OutputPort() [1/6]

template<typename T , typename... Args>
smgl::OutputPort< T, Args >::OutputPort ( source)
explicit

Construct with a copy of source. Source is effectively constant.

Definition at line 121 of file PortsImpl.hpp.

◆ OutputPort() [2/6]

template<typename T , typename... Args>
smgl::OutputPort< T, Args >::OutputPort ( T *  source)
explicit

Construct with a pointer to a source.

Definition at line 127 of file PortsImpl.hpp.

◆ OutputPort() [3/6]

template<typename T , typename... Args>
smgl::OutputPort< T, Args >::OutputPort ( std::function< T(Args...)>  source,
Args &&...  args 
)
explicit

Construct with a function source.

If calling source requires arguments, the initial value for these arguments must be passed as the last parameter. Argument values can be changed with setArgs().

Definition at line 134 of file PortsImpl.hpp.

◆ OutputPort() [4/6]

template<typename T , typename... Args>
template<class Obj , class ObjMemberFn >
smgl::OutputPort< T, Args >::OutputPort ( Obj *  obj,
ObjMemberFn &&  fn,
Args &&...  args 
)
explicit

Construct with a member function source.

If calling source requires arguments, the initial value for these arguments must be passed as the last parameter. Argument values can be changed with setArgs().

Definition at line 142 of file PortsImpl.hpp.

◆ OutputPort() [5/6]

template<typename T , typename... Args>
smgl::OutputPort< T, Args >::OutputPort ( const OutputPort< T, Args > &  )
delete

Disable copy

◆ OutputPort() [6/6]

template<typename T , typename... Args>
smgl::OutputPort< T, Args >::OutputPort ( const OutputPort< T, Args > &&  )
delete

Disable move

Member Function Documentation

◆ connect()

template<typename T , typename... Args>
void smgl::OutputPort< T, Args >::connect ( Input ip)
finalprivatevirtual

Connect to an input port. Uses RTTI to determine if ip is actually of type InputPort<T>.

Exceptions
smgl::bad_connectionif ip is not of type InputPort<T>

Implements smgl::Output.

Definition at line 234 of file PortsImpl.hpp.

◆ deserialize()

template<typename T , typename... Args>
void smgl::OutputPort< T, Args >::deserialize ( const Metadata m)
overridevirtual

Load port metadata.

Implements smgl::Port.

Definition at line 213 of file PortsImpl.hpp.

◆ disconnect()

template<typename T , typename... Args>
void smgl::OutputPort< T, Args >::disconnect ( Input ip)
finalprivatevirtual

Disconnect from an input port

Implements smgl::Output.

Definition at line 248 of file PortsImpl.hpp.

◆ getConnections()

template<typename T , typename... Args>
auto smgl::OutputPort< T, Args >::getConnections ( ) const
overridevirtual

Get a list of active connections.

Implements smgl::Output.

Definition at line 149 of file PortsImpl.hpp.

◆ notify()

template<typename T , typename... Args>
void smgl::OutputPort< T, Args >::notify ( State  s)
overridevirtual

Notify all active connections of this port's state.

Implements smgl::Port.

Definition at line 197 of file PortsImpl.hpp.

◆ numConnections()

template<typename T , typename... Args>
auto smgl::OutputPort< T, Args >::numConnections ( ) const
overridevirtual

Get the number of active connections.

Implements smgl::Output.

Definition at line 161 of file PortsImpl.hpp.

◆ operator()()

template<typename T , typename... Args>
auto smgl::OutputPort< T, Args >::operator() ( )

Get the current value of source.

Definition at line 179 of file PortsImpl.hpp.

◆ operator=() [1/2]

template<typename T , typename... Args>
OutputPort & smgl::OutputPort< T, Args >::operator= ( const OutputPort< T, Args > &&  )
delete

Disable move

◆ operator=() [2/2]

template<typename T , typename... Args>
OutputPort & smgl::OutputPort< T, Args >::operator= ( const OutputPort< T, Args > &  )
delete

Disable copy

◆ run_() [1/3]

template<typename T , typename... Args>
auto smgl::OutputPort< T, Args >::run_ ( std::tuple< Args... > &  tup)
private

Redirect function to get source value with arguments

Definition at line 228 of file PortsImpl.hpp.

◆ run_() [2/3]

template<typename T , typename... Args>
template<std::size_t... Is>
T smgl::OutputPort< T, Args >::run_ ( std::tuple< Args... > &  tup,
std::index_sequence< Is... >   
)
private

Get source value with arguments

◆ run_() [3/3]

template<typename T , typename... Args>
template<std::size_t... Is>
auto smgl::OutputPort< T, Args >::run_ ( std::tuple< Args... > &  tup,
std::index_sequence< Is... >   
) -> T

Definition at line 221 of file PortsImpl.hpp.

◆ serialize()

template<typename T , typename... Args>
auto smgl::OutputPort< T, Args >::serialize ( )
overridevirtual

Get port metadata.

Implements smgl::Port.

Definition at line 205 of file PortsImpl.hpp.

◆ setArgs()

template<typename T , typename... Args>
void smgl::OutputPort< T, Args >::setArgs ( Args &&...  args)

Set the arguments passed to a function source.

Definition at line 168 of file PortsImpl.hpp.

◆ update()

template<typename T , typename... Args>
auto smgl::OutputPort< T, Args >::update ( )
overridevirtual

Update all active connections with the value of the source.

Implements smgl::Port.

Definition at line 187 of file PortsImpl.hpp.

◆ val()

template<typename T , typename... Args>
auto smgl::OutputPort< T, Args >::val ( )

Get the current value of source.

Definition at line 174 of file PortsImpl.hpp.

Member Data Documentation

◆ args_

template<typename T , typename... Args>
Arguments smgl::OutputPort< T, Args >::args_
private

If source is a function, the arguments passed to source

Definition at line 373 of file Ports.hpp.

◆ connections_

template<typename T , typename... Args>
std::unordered_map<Uuid, TypedConnection> smgl::OutputPort< T, Args >::connections_
private

Stores all outgoing connections

Definition at line 402 of file Ports.hpp.

◆ source_

template<typename T , typename... Args>
std::function<T(Args...)> smgl::OutputPort< T, Args >::source_
private

Value source

Definition at line 370 of file Ports.hpp.


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