Drake
Drake C++ Documentation
PortBase Class Reference

Detailed Description

A PortBase is base class for System ports; users will typically use the InputPort<T> or OutputPort<T> types, not this base class.

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

Public Member Functions

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...
 
Does not allow copy, move, or assignment
 PortBase (const PortBase &)=delete
 
PortBaseoperator= (const PortBase &)=delete
 
 PortBase (PortBase &&)=delete
 
PortBaseoperator= (PortBase &&)=delete
 

Protected Member Functions

 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...
 

Friends

class internal::PortBaseAttorney
 

Constructor & Destructor Documentation

◆ PortBase() [1/3]

PortBase ( const PortBase )
delete

◆ PortBase() [2/3]

PortBase ( PortBase &&  )
delete

◆ ~PortBase()

virtual ~PortBase ( )
virtual

◆ PortBase() [3/3]

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 
)
protected

Provides derived classes the ability to set the base class members at construction.

Parameters
kind_stringEither "Input" or "Output", depending on the kind of subclass.
owning_systemThe System that owns this port.
owning_system_idThe ID of owning_system.
nameA name for the port. Port names should be non-empty and unique within a single System.
indexThe index to be assigned to this port. Input ports and output ports each have their own pool of indices (InputPortIndex and OutputPortIndex); this is just that TypeSafeIndex passed as a bare int.
ticketThe DependencyTicket to be assigned to this port.
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.

Member Function Documentation

◆ get_data_type()

PortDataType get_data_type ( ) const

Returns the port data type.

◆ get_deprecation()

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.

◆ get_int_index()

int get_int_index ( ) const
protected

Returns the index of this port within the owning System (i.e., an InputPortIndex or OutputPortIndex, but as a bare integer).

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

◆ get_mutable_system_interface()

internal::SystemMessageInterface& get_mutable_system_interface ( )
protected

Returns get_system_interface(), but without the const.

◆ get_name()

const std::string& get_name ( ) const

Get port name.

◆ get_system_interface()

const internal::SystemMessageInterface& get_system_interface ( ) const
protected

Returns a reference to the system that owns this port.

Note that for a diagram port this will be the diagram, not the leaf system whose port was exported.

◆ GetFullDescription()

std::string GetFullDescription ( ) const

Returns a verbose human-readable description of port.

This is useful for error messages or debugging.

◆ operator=() [1/2]

PortBase& operator= ( PortBase &&  )
delete

◆ operator=() [2/2]

PortBase& operator= ( const PortBase )
delete

◆ PortEvalCast() [1/2]

const ValueType & PortEvalCast ( const AbstractValue abstract) const
protected

Pull a value of a given type from an abstract value or issue a nice message if the type is not correct.

◆ PortEvalCast() [2/2]

const ValueType & PortEvalCast ( const BasicVector< T > &  basic) const
protected

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.

◆ set_deprecation()

void set_deprecation ( std::optional< std::string >  deprecation)

Sets whether this port is deprecated (and if so, the message).

◆ size()

int size ( ) const

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

Not meaningful for abstract-valued ports.

◆ ThrowBadCast() [1/3]

const ValueType& ThrowBadCast ( const AbstractValue abstract) const
protected

Reports that the user provided a bad ValueType argument to Eval.

◆ ThrowBadCast() [2/3]

const ValueType& ThrowBadCast ( const BasicVector< T > &  basic) const
protected

Reports that the user provided a bad ValueType argument to Eval.

◆ ThrowBadCast() [3/3]

void ThrowBadCast ( const std::string &  value_typename,
const std::string &  eval_typename 
) const
protected

Reports that the user provided a bad ValueType argument to Eval.

The value_typename is the type of the port's current value; the eval_typename is the type the user asked for.

◆ ThrowValidateContextMismatch()

void ThrowValidateContextMismatch ( ) const
protected

(Internal use only) Throws std::exception with a message that the sanity check(s) related to ValidateContext have failed.

◆ ticket()

DependencyTicket ticket ( ) const

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

◆ ValidateSystemId()

void ValidateSystemId ( internal::SystemId  id) const
protected

(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.

This is similar in spirit to SystemBase::ValidateContext, but ports cannot use SystemBase.

Note
This method is sufficiently fast for performance sensitive code.

Friends And Related Function Documentation

◆ internal::PortBaseAttorney

friend class internal::PortBaseAttorney
friend

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