Drake
ModelValues Class Reference

Represents models for a sequence of AbstractValues (usually a sequence of either input or output ports). More...

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

Public Member Functions

 ModelValues ()=default
 
int size () const
 Returns one greater than the largest index passed to AddModel or AddVectorModel. More...
 
void AddModel (int index, std::unique_ptr< AbstractValue > model_value)
 Sets model_value to be the model value for index. More...
 
template<typename T >
void AddVectorModel (int index, std::unique_ptr< BasicVector< T >> model_vector)
 Wraps model_vector in a Value and sets that to be the model value for index. More...
 
std::unique_ptr< AbstractValueCloneModel (int index) const
 Returns a clone of the model value at index, which may be nullptr. More...
 
std::vector< std::unique_ptr< AbstractValue > > CloneAllModels () const
 Returns a vector of all the cloned model values. Some may be nullptr. More...
 
template<typename T >
std::unique_ptr< BasicVector< T > > CloneVectorModel (int index) const
 Returns a clone of the vector within the model value at index, which may be nullptr. More...
 
Does not allow copy, move, or assignment
 ModelValues (const ModelValues &)=delete
 
ModelValuesoperator= (const ModelValues &)=delete
 
 ModelValues (ModelValues &&)=delete
 
ModelValuesoperator= (ModelValues &&)=delete
 

Detailed Description

Represents models for a sequence of AbstractValues (usually a sequence of either input or output ports).

The models are the "prototype" design pattern (https://en.wikipedia.org/wiki/Prototype_pattern). When creating elements in new Context, these models' values are cloned to establish the subtype and default values of the, e.g. input port.

Conceptually, the ModelValues form an infinite sequence. The value at a given index is allowed to be absent, in which case the CloneModel method will return nullptr. Adding new values must be monotonic; new values must use strictly larger indices; the model value for a given index cannot be reset.

Constructor & Destructor Documentation

◆ ModelValues() [1/3]

ModelValues ( const ModelValues )
delete

◆ ModelValues() [2/3]

ModelValues ( ModelValues &&  )
delete

◆ ModelValues() [3/3]

ModelValues ( )
default

Member Function Documentation

◆ AddModel()

void AddModel ( int  index,
std::unique_ptr< AbstractValue model_value 
)

Sets model_value to be the model value for index.

Precondition
index >= size()

◆ AddVectorModel()

void AddVectorModel ( int  index,
std::unique_ptr< BasicVector< T >>  model_vector 
)

Wraps model_vector in a Value and sets that to be the model value for index.

Precondition
index >= size()

◆ CloneAllModels()

std::vector<std::unique_ptr<AbstractValue> > CloneAllModels ( ) const
inline

Returns a vector of all the cloned model values. Some may be nullptr.

◆ CloneModel()

std::unique_ptr< AbstractValue > CloneModel ( int  index) const

Returns a clone of the model value at index, which may be nullptr.

◆ CloneVectorModel()

std::unique_ptr< BasicVector< T > > CloneVectorModel ( int  index) const

Returns a clone of the vector within the model value at index, which may be nullptr.

Exceptions
std::exceptionif the index has a model but the model's type does not match the given T

◆ operator=() [1/2]

ModelValues& operator= ( ModelValues &&  )
delete

◆ operator=() [2/2]

ModelValues& operator= ( const ModelValues )
delete

◆ size()

int size ( ) const

Returns one greater than the largest index passed to AddModel or AddVectorModel.


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