25 template <
class UnitVector>
33 typename std::decay<decltype(toEigen(UnitVector())(0))>::type;
37 typedef Eigen::Matrix<UnitScalar, RowsAtCompileTime, 1>
EigenType;
54 int count()
const {
return count_; }
58 void Append(
const UnitVector& unit) {
59 if (unit_size_ == 0) {
65 combined_vector_.conservativeResize(combined_vector_.rows() + unit_size_,
68 combined_vector_.bottomRows(unit_size_) =
toEigen(unit);
77 UnitVector
get(
int pos)
const {
79 if ((pos < 0) || (pos >= count_)) {
80 throw std::out_of_range(
"Position pos exceeds range [0, count()].");
83 const int row0 = pos * unit_size_;
84 return UnitVector(combined_vector_.block(row0, 0,
92 void set(
int pos,
const UnitVector& unit) {
94 if ((pos < 0) || (pos >= count_)) {
95 throw std::out_of_range(
"Position pos exceeds range [0, count()].");
98 const int row0 = pos * unit_size_;
99 combined_vector_.block(row0, 0, unit_size_, 1) =
toEigen(unit);
103 template <
typename Derived>
108 combined_vector_(initial) {
112 template <
typename Derived>
115 combined_vector_ = rhs;
120 int size()
const {
return combined_vector_.rows(); }
124 return vec.combined_vector_;
143 if ((rows % us) != 0) {
144 throw std::domain_error(
"Row count not a multiple of non-null unit.");
163 throw std::domain_error(
"Negative count for non-null unit.");
172 EigenType combined_vector_;
static int RowsFromUnitCount(int count)
Determines how many Eigen matrix rows will be needed to represent.
Definition: n_ary_state.h:157
void Append(const UnitVector &unit)
Appends the.
Definition: n_ary_state.h:58
friend EigenType toEigen(const NAryState< UnitVector > &vec)
Definition: n_ary_state.h:123
Definition: constants.h:3
NAryState is a Drake::Vector (concept implementation) which is a container of zero or more component ...
Definition: n_ary_state.h:26
static int unit_size()
Calculates the size (Eigen row count) of UnitVector, which is presumed to be fixed for all instances ...
Definition: n_ary_state.h:129
NAryState()
Definition: n_ary_state.h:39
NAryState(const Eigen::MatrixBase< Derived > &initial)
Definition: n_ary_state.h:105
int count() const
Definition: n_ary_state.h:54
NAryState & operator=(const Eigen::MatrixBase< Derived > &rhs)
Definition: n_ary_state.h:113
#define DRAKE_ASSERT(condition)
DRAKE_ASSERT(condition) is similar to the built-in assert(condition) from the C++ system header <cas...
Definition: drake_assert.h:35
static const int RowsAtCompileTime
Definition: n_ary_state.h:35
Provides Drake's assertion implementation.
NAryState(int count)
Definition: n_ary_state.h:41
Eigen::Matrix< UnitScalar, RowsAtCompileTime, 1 > EigenType
Definition: n_ary_state.h:37
typename std::decay< decltype(toEigen(UnitVector())(0))>::type UnitScalar
Definition: n_ary_state.h:33
int size() const
Definition: n_ary_state.h:120
static int UnitCountFromRows(int rows)
Determines how many.
Definition: n_ary_state.h:140
const Eigen::Matrix< ScalarType, Rows, 1 > & toEigen(const Eigen::Matrix< ScalarType, Rows, 1 > &vec)
Definition: Vector.h:61