dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
dfx::Core::Port Class Reference

Base class for both input and output ports. More...

#include <dfx-core/ports/Port.hpp>

Inheritance diagram for dfx::Core::Port:
[legend]
Collaboration diagram for dfx::Core::Port:
[legend]

Public Types

enum class  Mode { Input , Output }
 Port direction. More...
using Id = uint32_t
 Identifier type of a port (unique within a node by not unique accross a graph).

Public Member Functions

 ENABLE_DEFAULT_MOVE_DISABLE_COPY (Port)
 Move is allowed, copy is disabled.
virtual ~Port ()
 Virtual destructor for inheritance.
NodePtr node () const noexcept
 Get the owning node.
template<DerivedFromPort T>
T & as () noexcept
 Unchecked cast to a derived port type.
template<DerivedFromPort T>
T const & as () const noexcept
 Unchecked cast to a derived port type.
Introspection
Id id () const noexcept
 Get the port id.
std::string const & name () const noexcept
 Get the port name.
Mode mode () const noexcept
 Get the port mode.
Kind kind () const noexcept
 Get the port kind.
bool isInput () const noexcept
 Check is this is an input port.
bool isOutput () const noexcept
 Check is this is an output port.
std::optional< bool > allowsMimeTypePropagation () const noexcept
 Check if this node allow mime-type propagation.
Channel management
void addChannel (ChannelPtr channel)
 Attach a channel to this port.
void removeChannel (ChannelPtr channel)
 Detach a channel from this port. If the channel is not present, this is a no-op.
bool hasChannel (ChannelPtr channel) const noexcept
 Check whether a channel is attached to this port.
std::size_t channelCount () const noexcept
 Number of attached channels.
ChannelPtr channel (std::size_t index) const
 Get the attached channel at the given index.
Hook management
void registerHook (Hooks::Port *hook)
 Register a hook on this port.
void deregisterHook (Hooks::Port *hook)
 Deregister a hook from this port. If the hook is not registered, this is a no-op.

Static Public Member Functions

static void validatePortName (std::string_view name)
 Validate a port name according to dfx rules.

Protected Member Functions

 Port (Id id, NodeWPtr node, Mode mode, Kind kind, std::string name, std::optional< bool > allowsMimeTypePropagation)
 Construct a port.

Protected Attributes

std::vector< Hooks::Port * > hooks
 Registered port hooks. Stored as raw pointers. Managed via registerHook and deregisterHook.

Detailed Description

Base class for both input and output ports.

This class provides:

Channels
A port maintains the list of channels it participates in. The port does not validate graph-wide consistency (that is the responsibility of the graph layer), but it enforces a local invariant when adding a channel:
  • If this port is an input port, then channel->inputPort() must be this port.
  • If this port is an output port, then channel->outputPort() must be this port.

Duplicate channels are ignored (adding the same channel twice is a no-op).

Hooks
Hooks are stored as raw pointers in a simple vector:
  • Registering a null hook asserts.
  • Registering the same hook twice is a no-op.
  • Deregistering a hook that is not present is a no-op.
Port naming rules
validatePortName enforces:
  • non-empty name
  • only ASCII letters/digits plus -, _, and space
  • . is not allowed (used as separator between node.port)

Member Typedef Documentation

◆ Id

using dfx::Core::Port::Id = uint32_t

Identifier type of a port (unique within a node by not unique accross a graph).

Member Enumeration Documentation

◆ Mode

enum class dfx::Core::Port::Mode
strong

Port direction.

Enumerator
Input 

Incoming endpoint.

Output 

Outgoing endpoint.

Constructor & Destructor Documentation

◆ ~Port()

virtual dfx::Core::Port::~Port ( )
virtual

Virtual destructor for inheritance.

◆ Port()

dfx::Core::Port::Port ( Id id,
NodeWPtr node,
Mode mode,
Kind kind,
std::string name,
std::optional< bool > allowsMimeTypePropagation )
protected

Construct a port.

Parameters
idPort id (unique within a node).
nodeOwning node (weak reference).
modeDirection (input/output).
kindConnectivity domain (data/control "network").
namePort name (validated by validatePortName).
allowsMimeTypePropagationOptional propagation override.

Member Function Documentation

◆ addChannel()

void dfx::Core::Port::addChannel ( ChannelPtr channel)

Attach a channel to this port.

If the channel is already present, this is a no-op.

Parameters
channelChannel to attach.
Exceptions
dfx::Utils::ExceptionIf the channel direction does not match this port (i.e. the channel does not reference this port as its input/output endpoint).

◆ allowsMimeTypePropagation()

std::optional< bool > dfx::Core::Port::allowsMimeTypePropagation ( ) const
inlinenoexcept

Check if this node allow mime-type propagation.

See also
"any" ports and propagation

◆ as() [1/2]

template<DerivedFromPort T>
T const & dfx::Core::Port::as ( ) const
inlinenoexcept

Unchecked cast to a derived port type.

Template Parameters
TA type derived from Port.
Warning
This uses static_cast. Use only when you know the dynamic type.

◆ as() [2/2]

template<DerivedFromPort T>
T & dfx::Core::Port::as ( )
inlinenoexcept

Unchecked cast to a derived port type.

Template Parameters
TA type derived from Port.
Warning
This uses static_cast. Use only when you know the dynamic type.

◆ channel()

ChannelPtr dfx::Core::Port::channel ( std::size_t index) const
inline

Get the attached channel at the given index.

Parameters
indexThe channel index. Must be a valid index i.e. >= 0 && < channelCount()
Exceptions
`std::out_of_range`if index is invalid.

◆ channelCount()

std::size_t dfx::Core::Port::channelCount ( ) const
inlinenoexcept

Number of attached channels.

◆ deregisterHook()

void dfx::Core::Port::deregisterHook ( Hooks::Port * hook)

Deregister a hook from this port. If the hook is not registered, this is a no-op.

◆ ENABLE_DEFAULT_MOVE_DISABLE_COPY()

dfx::Core::Port::ENABLE_DEFAULT_MOVE_DISABLE_COPY ( Port )

Move is allowed, copy is disabled.

◆ hasChannel()

bool dfx::Core::Port::hasChannel ( ChannelPtr channel) const
noexcept

Check whether a channel is attached to this port.

◆ id()

Id dfx::Core::Port::id ( ) const
inlinenoexcept

Get the port id.

◆ isInput()

bool dfx::Core::Port::isInput ( ) const
inlinenoexcept

Check is this is an input port.

◆ isOutput()

bool dfx::Core::Port::isOutput ( ) const
inlinenoexcept

Check is this is an output port.

◆ kind()

Kind dfx::Core::Port::kind ( ) const
inlinenoexcept

Get the port kind.

◆ mode()

Mode dfx::Core::Port::mode ( ) const
inlinenoexcept

Get the port mode.

◆ name()

std::string const & dfx::Core::Port::name ( ) const
inlinenoexcept

Get the port name.

◆ node()

NodePtr dfx::Core::Port::node ( ) const
inlinenoexcept

Get the owning node.

Returns
Shared pointer to the node, or nullptr if the node no longer exists.

◆ registerHook()

void dfx::Core::Port::registerHook ( Hooks::Port * hook)

Register a hook on this port.

Duplicate registration is ignored.

Parameters
hookHook pointer (must not be null).
Warning
This stores a raw pointer; the hook must outlive the port or be deregistered before destruction.

◆ removeChannel()

void dfx::Core::Port::removeChannel ( ChannelPtr channel)

Detach a channel from this port. If the channel is not present, this is a no-op.

◆ validatePortName()

void dfx::Core::Port::validatePortName ( std::string_view name)
static

Validate a port name according to dfx rules.

Rules:

  • must not be empty
  • allowed characters: [A-Za-z0-9-_ ]
Parameters
namePort name to validate.
Exceptions
dfx::Utils::Exceptionif the name is invalid

Member Data Documentation

◆ hooks

std::vector<Hooks::Port *> dfx::Core::Port::hooks
protected

Registered port hooks. Stored as raw pointers. Managed via registerHook and deregisterHook.


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