28 first_element_(first_element),
29 num_elements_(num_elements) {
30 if (vector_ ==
nullptr) {
31 throw std::logic_error(
32 "Cannot create StateSubvector of a nullptr vector.");
34 if (first_element_ + num_elements_ > vector_->size()) {
35 throw std::out_of_range(
"StateSubvector out of bounds.");
45 int size()
const override {
return num_elements_; }
48 if (index >=
size()) {
50 " out of bounds for state subvector of size " +
53 return vector_->GetAtIndex(first_element_ + index);
57 if (index >=
size()) {
59 " out of bounds for state subvector of size " +
62 vector_->SetAtIndex(first_element_ + index, value);
66 for (
int i = 0; i < value.rows(); ++i) {
73 for (
int i = 0; i <
size(); ++i) {
87 int first_element_{0};
void SetAtIndex(int index, const T &value) override
Replaces the state at the given index with the value.
Definition: state_subvector.h:56
Definition: constants.h:3
int size() const override
Returns the number of elements in the vector.
Definition: state_subvector.h:45
StateVector is an abstract base class template for vector quantities within the state of a System...
Definition: state_vector.h:20
const T GetAtIndex(int index) const override
Returns the element at the given index in the vector.
Definition: state_subvector.h:47
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > VectorX
A column vector of any size, templated on scalar type.
Definition: eigen_types.h:36
StateSubvector(StateVector< T > *vector, int first_element, int num_elements)
Constructs a subvector of vector that consists of num_elements starting at first_element.
Definition: state_subvector.h:25
StateSubvector(StateVector< T > *vector)
Constructs an empty subvector.
Definition: state_subvector.h:42
StateSubvector is a concrete class template that implements StateVector by providing a sliced view of...
Definition: state_subvector.h:19
void SetFromVector(const Eigen::Ref< const VectorX< T >> &value) override
Replaces the entire state with the contents of value.
Definition: state_subvector.h:65
std::string to_string(const Eigen::MatrixBase< Derived > &a)
Definition: testUtil.h:29
VectorX< T > CopyToVector() const override
Copies the entire state to a vector with no semantics.
Definition: state_subvector.h:71