Base class for both input and output ports.
More...
#include <dfx-core/ports/Port.hpp>
|
| 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).
|
|
| | 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.
|
| 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.
|
| 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.
|
| 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.
|
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)
◆ Id
Identifier type of a port (unique within a node by not unique accross a graph).
◆ Mode
Port direction.
| Enumerator |
|---|
| Input | Incoming endpoint.
|
| Output | Outgoing endpoint.
|
◆ ~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
-
| id | Port id (unique within a node). |
| node | Owning node (weak reference). |
| mode | Direction (input/output). |
| kind | Connectivity domain (data/control "network"). |
| name | Port name (validated by validatePortName). |
| allowsMimeTypePropagation | Optional propagation override. |
◆ 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
-
- Exceptions
-
| dfx::Utils::Exception | If 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 |
◆ as() [1/2]
template<DerivedFromPort T>
| T const & dfx::Core::Port::as |
( |
| ) |
const |
|
inlinenoexcept |
Unchecked cast to a derived port type.
- Template Parameters
-
| T | A 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
-
| T | A 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
-
| index | The 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 |
◆ 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 |
◆ mode()
| Mode dfx::Core::Port::mode |
( |
| ) |
const |
|
inlinenoexcept |
◆ name()
| std::string const & dfx::Core::Port::name |
( |
| ) |
const |
|
inlinenoexcept |
◆ 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
-
| hook | Hook 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
-
| name | Port name to validate. |
- Exceptions
-
◆ hooks
The documentation for this class was generated from the following file: