Drake
LeafContext< T > Class Template Reference

LeafContext is a container for all of the data necessary to uniquely determine the computations performed by a leaf System. More...

#include <systems/framework/leaf_context.h>

Inheritance diagram for LeafContext< T >:
[legend]
Collaboration diagram for LeafContext< T >:
[legend]

## Public Member Functions

LeafContext ()

~LeafContext () override

void ClearInputPorts ()
Removes all the input ports, and deregisters them from the output ports on which they depend. More...

void SetNumInputPorts (int n)
Clears the input ports and allocates n new input ports, not connected to anything. More...

int get_num_input_ports () const override
Returns the number of input ports. More...

const State< T > & get_state () const final

State< T > & get_mutable_state () final

CacheTicket CreateCacheEntry (const std::set< CacheTicket > &prerequisites) const
Reserves a cache entry with the given prerequisites on which it depends. More...

AbstractValueInitCachedValue (CacheTicket ticket, std::unique_ptr< AbstractValue > value) const
Stores the given value in the cache entry for the given ticket, and returns a bare pointer to value. More...

template<typename V >
void SetCachedValue (CacheTicket ticket, const V &value) const
Copies the given value into the cache entry for the given ticket. More...

const AbstractValueGetCachedValue (CacheTicket ticket) const

void set_parameters (std::unique_ptr< Parameters< T >> params)
Sets the parameters to params, deleting whatever was there before. More...

const Parameters< T > & get_parameters () const final
Returns the entire Parameters object. More...

Parameters< T > & get_mutable_parameters () final
Returns the entire Parameters object. More...

Does not allow copy, move, or assignment
LeafContext (const LeafContext &)=delete

LeafContextoperator= (const LeafContext &)=delete

LeafContext (LeafContext &&)=delete

LeafContextoperator= (LeafContext &&)=delete

Public Member Functions inherited from Context< T >
Context ()=default

virtual ~Context ()=default

const Tget_time () const
Returns the current time in seconds. More...

virtual void set_time (const T &time_sec)
Set the current time in seconds. More...

bool is_stateless () const
Returns true if the Context has no state. More...

bool has_only_continuous_state () const
Returns true if the Context has continuous state, but no discrete or abstract state. More...

bool has_only_discrete_state () const
Returns true if the Context has discrete state, but no continuous or abstract state. More...

int get_num_total_states () const
Returns the total dimension of all of the basic vector states (as if they were muxed). More...

void set_continuous_state (std::unique_ptr< ContinuousState< T >> xc)
Sets the continuous state to xc, deleting whatever was there before. More...

ContinuousState< T > & get_mutable_continuous_state ()
Returns a mutable reference to the continuous component of the state, which may be of size zero. More...

VectorBase< T > & get_mutable_continuous_state_vector ()
Returns a mutable reference to the continuous state vector, devoid of second-order structure. More...

const ContinuousState< T > & get_continuous_state () const
Returns a const reference to the continuous component of the state, which may be of size zero. More...

const VectorBase< T > & get_continuous_state_vector () const
Returns a reference to the continuous state vector, devoid of second-order structure. More...

int get_num_discrete_state_groups () const
Returns the number of elements in the discrete state. More...

const DiscreteValues< T > & get_discrete_state () const

const BasicVector< T > & get_discrete_state_vector () const
Returns a reference to the discrete state vector. More...

DiscreteValues< T > & get_mutable_discrete_state ()
Returns a mutable pointer to the discrete component of the state, which may be of size zero. More...

BasicVector< T > & get_mutable_discrete_state (int index)
Returns a mutable pointer to element index of the discrete state. More...

void set_discrete_state (std::unique_ptr< DiscreteValues< T >> xd)
Sets the discrete state to xd, deleting whatever was there before. More...

const BasicVector< T > & get_discrete_state (int index) const
Returns a const pointer to the discrete component of the state at index. More...

int get_num_abstract_state_groups () const
Returns the number of elements in the abstract state. More...

const AbstractValuesget_abstract_state () const
Returns a const reference to the abstract component of the state, which may be of size zero. More...

AbstractValuesget_mutable_abstract_state ()
Returns a mutable reference to the abstract component of the state, which may be of size zero. More...

template<typename U >
U & get_mutable_abstract_state (int index)
Returns a mutable pointer to element index of the abstract state. More...

void set_abstract_state (std::unique_ptr< AbstractValues > xa)
Sets the abstract state to xa, deleting whatever was there before. More...

template<typename U >
const U & get_abstract_state (int index) const
Returns a const reference to the abstract component of the state at index. More...

FreestandingInputPortValueFixInputPort (int index, std::unique_ptr< AbstractValue > value)
Connects the input port at index to a FreestandingInputPortValue with the given abstract value. More...

FreestandingInputPortValueFixInputPort (int index, std::unique_ptr< BasicVector< T >> vec)
Connects the input port at index to a FreestandingInputPortValue with the given vector vec. More...

FreestandingInputPortValueFixInputPort (int index, const Eigen::Ref< const VectorX< T >> &data)
Same as above method but starts with an Eigen vector whose contents are used to initialize a BasicVector in the FreestandingInputPortValue. More...

const InputPortValueEvalInputPort (const detail::InputPortEvaluatorInterface< T > *evaluator, const InputPortDescriptor< T > &descriptor) const
Evaluates and returns the value of the input port identified by descriptor, using the given evaluator, which should be the Diagram containing the System that allocated this Context. More...

const BasicVector< T > * EvalVectorInput (const detail::InputPortEvaluatorInterface< T > *evaluator, const InputPortDescriptor< T > &descriptor) const
Evaluates and returns the vector value of the input port with the given descriptor. More...

const AbstractValueEvalAbstractInput (const detail::InputPortEvaluatorInterface< T > *evaluator, const InputPortDescriptor< T > &descriptor) const
Evaluates and returns the abstract value of the input port with the given descriptor. More...

template<typename V >
const V * EvalInputValue (const detail::InputPortEvaluatorInterface< T > *evaluator, const InputPortDescriptor< T > &descriptor) const
Evaluates and returns the data of the input port at index. More...

int num_numeric_parameters () const
Returns the number of vector-valued parameters. More...

const BasicVector< T > & get_numeric_parameter (int index) const
Returns a const pointer to the vector-valued parameter at index. More...

BasicVector< T > & get_mutable_numeric_parameter (int index)
Returns a mutable pointer to element index of the vector-valued parameters. More...

int num_abstract_parameters () const
Returns the number of abstract-valued parameters. More...

const AbstractValueget_abstract_parameter (int index) const
Returns a const reference to the abstract-valued parameter at index. More...

AbstractValueget_mutable_abstract_parameter (int index)
Returns a mutable reference to element index of the abstract-valued parameters. More...

void set_accuracy (const optional< double > &accuracy)
Records the user's requested accuracy. More...

const optional< double > & get_accuracy () const
Returns the accuracy setting (if any). More...

std::unique_ptr< Context< T > > Clone () const
Returns a deep copy of this Context. More...

std::unique_ptr< State< T > > CloneState () const
Returns a deep copy of this Context's State. More...

void SetTimeStateAndParametersFrom (const Context< double > &source)
Initializes this context's time, state, and parameters from the real values in source, regardless of this context's scalar type. More...

void set_parent (const Context< T > *parent)
Declares that parent is the context of the enclosing Diagram. More...

template<typename T1 = T>
void VerifyInputPort (const InputPortDescriptor< T1 > &descriptor) const
Throws an exception unless the given descriptor matches the inputs actually connected to this context in shape. More...

Context (const Context &)=delete

Contextoperator= (const Context &)=delete

Context (Context &&)=delete

Contextoperator= (Context &&)=delete

## Protected Member Functions

Context< T > * DoClone () const override
The caller owns the returned memory. More...

State< T > * DoCloneState () const override
The caller owns the returned memory. More...

const InputPortValueGetInputPortValue (int index) const override
Returns the InputPortValue at the given index, which may be nullptr if it has never been set with SetInputPortValue(). More...

Protected Member Functions inherited from Context< T >
const StepInfo< T > & get_step_info () const
Returns a const reference to current time and step information. More...

StepInfo< T > * get_mutable_step_info ()
Provides writable access to time and step information, with the side effect of invaliding any computation that is dependent on them. More...

## Additional Inherited Members

Static Protected Member Functions inherited from Context< T >
static const InputPortValueGetInputPortValue (const Context< T > &context, int index)
Allows derived classes to invoke the protected method on subcontexts. More...

static void SetInputPortValue (Context< T > *context, int index, std::unique_ptr< InputPortValue > port_value)
Allows derived classes to invoke the protected method on subcontexts. More...

## Detailed Description

### template<typename T> class drake::systems::LeafContext< T >

LeafContext is a container for all of the data necessary to uniquely determine the computations performed by a leaf System.

Specifically, a LeafContext contains and owns the State, and also contains (but does not own) pointers to the value sources for Inputs, as well as the simulation time and the cache.

Template Parameters
 T The mathematical type of the context, which must be a valid Eigen scalar.

## Constructor & Destructor Documentation

 LeafContext ( const LeafContext< T > & )
delete
 LeafContext ( LeafContext< T > && )
delete
 LeafContext ( )
inline
 ~LeafContext ( )
inlineoverride

## Member Function Documentation

 void ClearInputPorts ( )
inline

Removes all the input ports, and deregisters them from the output ports on which they depend.

Here is the caller graph for this function:

 CacheTicket CreateCacheEntry ( const std::set< CacheTicket > & prerequisites ) const
inline

Reserves a cache entry with the given prerequisites on which it depends.

Returns a ticket to identify the entry.

Here is the caller graph for this function:

 Context* DoClone ( ) const
inlineoverrideprotectedvirtual

The caller owns the returned memory.

Implements Context< T >.

 State* DoCloneState ( ) const
inlineoverrideprotectedvirtual

The caller owns the returned memory.

Implements Context< T >.

 Parameters& get_mutable_parameters ( )
inlinefinalvirtual

Returns the entire Parameters object.

Implements Context< T >.

Here is the caller graph for this function:

 State& get_mutable_state ( )
inlinefinalvirtual

Implements Context< T >.

Here is the caller graph for this function:

 int get_num_input_ports ( ) const
inlineoverridevirtual

Returns the number of input ports.

Implements Context< T >.

Here is the caller graph for this function:

 const Parameters& get_parameters ( ) const
inlinefinalvirtual

Returns the entire Parameters object.

Implements Context< T >.

 const State& get_state ( ) const
inlinefinalvirtual

Implements Context< T >.

Here is the caller graph for this function:

 const AbstractValue* GetCachedValue ( CacheTicket ticket ) const
inline

Here is the caller graph for this function:

 const InputPortValue* GetInputPortValue ( int index ) const
inlineoverrideprotectedvirtual

Returns the InputPortValue at the given index, which may be nullptr if it has never been set with SetInputPortValue().

Asserts if index is out of range.

Implements Context< T >.

 AbstractValue* InitCachedValue ( CacheTicket ticket, std::unique_ptr< AbstractValue > value ) const
inline

Stores the given value in the cache entry for the given ticket, and returns a bare pointer to value.

That pointer will be invalidated whenever any of the ticket's declared prerequisites change, and possibly also at other times which are not defined.

Systems MUST NOT depend on a particular value being present or valid in the Cache, and MUST check the validity of cached values using the GetCachedValue interface. The Cache is useful to avoid recomputing expensive intermediate data. It is not a scratch space for arbitrary state. If you cannot derive a value from other fields in the Context, do not put that value in the Cache. If you violate this rule, you may be devoured by a horror from another universe, and forced to fill out paperwork in triplicate for all eternity. You have been warned.

Here is the caller graph for this function:

 LeafContext& operator= ( LeafContext< T > && )
delete
 LeafContext& operator= ( const LeafContext< T > & )
delete
 void set_parameters ( std::unique_ptr< Parameters< T >> params )
inline

Sets the parameters to params, deleting whatever was there before.

Here is the caller graph for this function:

 void SetCachedValue ( CacheTicket ticket, const V & value ) const
inline

Copies the given value into the cache entry for the given ticket.

May throw std::bad_cast if the type of the existing value is not V.

Template Parameters
 V The type of the value to store.

Here is the caller graph for this function:

 void SetNumInputPorts ( int n )
inline

Clears the input ports and allocates n new input ports, not connected to anything.

Here is the caller graph for this function:

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