36 : vector_(
std::move(vector)) {}
38 int size()
const override {
39 return static_cast<int>(vector_->get_value().rows());
43 if (index >=
size()) {
45 " out of bounds for state vector of size " +
48 return vector_->get_value()[index];
52 if (index >=
size()) {
54 " out of bounds for state vector of size " +
57 vector_->get_mutable_value()[index] = value;
61 vector_->set_value(value);
68 if (vec.rows() !=
size()) {
69 throw std::out_of_range(
"Addends must be the same length.");
71 vec += scale * vector_->get_value();
98 std::unique_ptr<VectorInterface<T>> vector_;
VectorInterface is a pure abstract interface that real-valued signals between Systems must satisfy...
Definition: vector_interface.h:25
Definition: constants.h:3
StateVector is an abstract base class template for vector quantities within the state of a System...
Definition: state_vector.h:20
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > VectorX
A column vector of any size, templated on scalar type.
Definition: eigen_types.h:36
VectorX< T > CopyToVector() const override
Copies the entire state to a vector with no semantics.
Definition: basic_state_vector.h:64
void ScaleAndAddToVector(const T &scale, Eigen::Ref< VectorX< T >> vec) const override
Adds a scaled version of this state vector to Eigen vector vec, which must be the same size...
Definition: basic_state_vector.h:66
BasicStateVector(std::unique_ptr< VectorInterface< T >> vector)
Constructs a BasicStateVector that owns an arbitrary vector, which must not be nullptr.
Definition: basic_state_vector.h:35
std::string to_string(const Eigen::MatrixBase< Derived > &a)
Definition: testUtil.h:29
BasicStateVector is a concrete class template that implements StateVector in a convenient manner for ...
Definition: basic_state_vector.h:25
virtual void ScaleAndAddToVector(const T &scale, Eigen::Ref< VectorX< T >> vec) const
Adds a scaled version of this state vector to Eigen vector vec, which must be the same size...
Definition: state_vector.h:64
BasicVector is a semantics-free wrapper around an Eigen vector that satisfies VectorInterface.
Definition: basic_vector.h:23
BasicStateVector & PlusEqScaled(const T &scale, const StateVector< T > &rhs) override
Add in scaled state vector rhs to this state vector.
Definition: basic_state_vector.h:74
LeafStateVector is an abstract class template that implements StateVector for leaf Systems...
Definition: leaf_state_vector.h:17
void SetAtIndex(int index, const T &value) override
Replaces the state at the given index with the value.
Definition: basic_state_vector.h:51
void SetFromVector(const Eigen::Ref< const VectorX< T >> &value) override
Replaces the entire state with the contents of value.
Definition: basic_state_vector.h:60
const T GetAtIndex(int index) const override
Returns the element at the given index in the vector.
Definition: basic_state_vector.h:42
int size() const override
Returns the number of elements in the vector.
Definition: basic_state_vector.h:38
BasicStateVector(int size)
Constructs a BasicStateVector that owns a generic BasicVector of the specified size.
Definition: basic_state_vector.h:29
BasicStateVector(const BasicStateVector &other)
Definition: basic_state_vector.h:81