Drake
Drake C++ Documentation
InputPortBase Class Reference

Detailed Description

An InputPort is a System resource that describes the kind of input a System accepts, on a given port.

It does not directly contain any runtime input port data; that is always contained in a Context. The actual value will be either the value of an OutputPort to which this is connected, or a fixed value set in a Context.

InputPortBase is the scalar type-independent part of an InputPort.

#include <drake/systems/framework/input_port_base.h>

Public Member Functions

 ~InputPortBase () override
 
InputPortIndex get_index () const
 Returns the index of this input port within the owning System. More...
 
bool is_random () const
 Returns true if this is a random port. More...
 
std::optional< RandomDistributionget_random_type () const
 Returns the RandomDistribution if this is a random port. More...
 
std::unique_ptr< AbstractValueAllocate () const
 Allocates a concrete object suitable for holding the value to be provided by this input port, and returns that as an AbstractValue. More...
 
const std::string & get_name () const
 Get port name. More...
 
std::string GetFullDescription () const
 Returns a verbose human-readable description of port. More...
 
PortDataType get_data_type () const
 Returns the port data type. More...
 
int size () const
 Returns the fixed size expected for a vector-valued port. More...
 
DependencyTicket ticket () const
 (Advanced.) Returns the DependencyTicket for this port within the owning System. More...
 
Does not allow copy, move, or assignment
 InputPortBase (const InputPortBase &)=delete
 
InputPortBaseoperator= (const InputPortBase &)=delete
 
 InputPortBase (InputPortBase &&)=delete
 
InputPortBaseoperator= (InputPortBase &&)=delete
 
- Public Member Functions inherited from PortBase
virtual ~PortBase ()
 
const std::string & get_name () const
 Get port name. More...
 
std::string GetFullDescription () const
 Returns a verbose human-readable description of port. More...
 
PortDataType get_data_type () const
 Returns the port data type. More...
 
int size () const
 Returns the fixed size expected for a vector-valued port. More...
 
const std::optional< std::string > & get_deprecation () const
 When this port is deprecated, returns non-null with a (possibly empty) deprecation message; when this port is not deprecated, returns null. More...
 
void set_deprecation (std::optional< std::string > deprecation)
 Sets whether this port is deprecated (and if so, the message). More...
 
DependencyTicket ticket () const
 (Advanced.) Returns the DependencyTicket for this port within the owning System. More...
 
 PortBase (const PortBase &)=delete
 
PortBaseoperator= (const PortBase &)=delete
 
 PortBase (PortBase &&)=delete
 
PortBaseoperator= (PortBase &&)=delete
 

Protected Types

using EvalAbstractCallback = std::function< const AbstractValue *(const ContextBase &)>
 Signature of a function suitable for returning the cached value of a particular input port. More...
 

Protected Member Functions

 InputPortBase (internal::SystemMessageInterface *owning_system, internal::SystemId owning_system_id, std::string name, InputPortIndex index, DependencyTicket ticket, PortDataType data_type, int size, const std::optional< RandomDistribution > &random_type, EvalAbstractCallback eval, ValueProducer::AllocateCallback alloc)
 (Internal use only) Provides derived classes the ability to set the base class members at construction. More...
 
const AbstractValueDoEvalRequired (const ContextBase &context) const
 Evaluate this port; throws an exception if the port is not connected. More...
 
const AbstractValueDoEvalOptional (const ContextBase &context) const
 Evaluate this port; returns nullptr if the port is not connected. More...
 
void ThrowRequiredMissing () const
 Throws an exception that this port is not connected, but was expected to be connected (i.e., an Eval caller expected that it was always connected). More...
 
- Protected Member Functions inherited from PortBase
 PortBase (const char *kind_string, internal::SystemMessageInterface *owning_system, internal::SystemId owning_system_id, std::string name, int index, DependencyTicket ticket, PortDataType data_type, int size)
 Provides derived classes the ability to set the base class members at construction. More...
 
int get_int_index () const
 Returns the index of this port within the owning System (i.e., an InputPortIndex or OutputPortIndex, but as a bare integer). More...
 
const internal::SystemMessageInterface & get_system_interface () const
 Returns a reference to the system that owns this port. More...
 
internal::SystemMessageInterface & get_mutable_system_interface ()
 Returns get_system_interface(), but without the const. More...
 
void ValidateSystemId (internal::SystemId id) const
 (Internal use only) Checks whether the given id (nominally obtained from a Context passed to this port) was created for the system that owns this port. More...
 
void ThrowValidateContextMismatch () const
 (Internal use only) Throws std::exception with a message that the sanity check(s) related to ValidateContext have failed. More...
 
template<typename ValueType >
const ValueType & PortEvalCast (const AbstractValue &abstract) const
 Pull a value of a given type from an abstract value or issue a nice message if the type is not correct. More...
 
template<typename ValueType , typename T >
const ValueType & PortEvalCast (const BasicVector< T > &basic) const
 Downcast a basic vector to a more specific subclass (e.g., as generated by //tools/vector_gen) or issue a nice message if the type is not correct. More...
 
template<typename ValueType >
const ValueType & ThrowBadCast (const AbstractValue &abstract) const
 Reports that the user provided a bad ValueType argument to Eval. More...
 
template<typename ValueType , typename T >
const ValueType & ThrowBadCast (const BasicVector< T > &basic) const
 Reports that the user provided a bad ValueType argument to Eval. More...
 
void ThrowBadCast (const std::string &value_typename, const std::string &eval_typename) const
 Reports that the user provided a bad ValueType argument to Eval. More...
 

Member Typedef Documentation

◆ EvalAbstractCallback

using EvalAbstractCallback = std::function<const AbstractValue*(const ContextBase&)>
protected

Signature of a function suitable for returning the cached value of a particular input port.

Will return nullptr if the port is not connected.

Constructor & Destructor Documentation

◆ InputPortBase() [1/3]

InputPortBase ( const InputPortBase )
delete

◆ InputPortBase() [2/3]

InputPortBase ( InputPortBase &&  )
delete

◆ ~InputPortBase()

~InputPortBase ( )
override

◆ InputPortBase() [3/3]

InputPortBase ( internal::SystemMessageInterface *  owning_system,
internal::SystemId  owning_system_id,
std::string  name,
InputPortIndex  index,
DependencyTicket  ticket,
PortDataType  data_type,
int  size,
const std::optional< RandomDistribution > &  random_type,
EvalAbstractCallback  eval,
ValueProducer::AllocateCallback  alloc 
)
protected

(Internal use only) Provides derived classes the ability to set the base class members at construction.

Parameters
owning_systemThe System that owns this input port.
owning_system_idThe ID of owning_system.
nameA name for the port. Input port names should be non-empty and unique within a single System.
indexThe index to be assigned to this InputPort.
ticketThe DependencyTicket to be assigned to this InputPort.
data_typeWhether the port described is vector- or abstract-valued.
sizeIf the port described is vector-valued, the number of elements. Ignored for abstract-valued ports.
random_typeInput ports may optionally be labeled as random, if the port is intended to model a random-source "noise" or "disturbance" input.

Member Function Documentation

◆ Allocate()

std::unique_ptr<AbstractValue> Allocate ( ) const

Allocates a concrete object suitable for holding the value to be provided by this input port, and returns that as an AbstractValue.

The returned object will never be null.

◆ DoEvalOptional()

const AbstractValue* DoEvalOptional ( const ContextBase context) const
protected

Evaluate this port; returns nullptr if the port is not connected.

◆ DoEvalRequired()

const AbstractValue& DoEvalRequired ( const ContextBase context) const
protected

Evaluate this port; throws an exception if the port is not connected.

◆ get_data_type()

PortDataType get_data_type

Returns the port data type.

◆ get_index()

InputPortIndex get_index ( ) const

Returns the index of this input port within the owning System.

For a Diagram, this will be the index within the Diagram, not the index within a LeafSystem whose input port was exported.

◆ get_name()

const std::string& get_name

Get port name.

◆ get_random_type()

std::optional<RandomDistribution> get_random_type ( ) const

Returns the RandomDistribution if this is a random port.

◆ GetFullDescription()

std::string GetFullDescription

Returns a verbose human-readable description of port.

This is useful for error messages or debugging.

◆ is_random()

bool is_random ( ) const

Returns true if this is a random port.

◆ operator=() [1/2]

InputPortBase& operator= ( InputPortBase &&  )
delete

◆ operator=() [2/2]

InputPortBase& operator= ( const InputPortBase )
delete

◆ size()

int size

Returns the fixed size expected for a vector-valued port.

Not meaningful for abstract-valued ports.

◆ ThrowRequiredMissing()

void ThrowRequiredMissing ( ) const
protected

Throws an exception that this port is not connected, but was expected to be connected (i.e., an Eval caller expected that it was always connected).

◆ ticket()

(Advanced.) Returns the DependencyTicket for this port within the owning System.


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