Simbody  3.6
Type-Safe Integer Indices

It is common to store objects or information about them in randomly-indexable arrays, and then to support maximum-performance selection by allowing the index to be used. More...

Classes

class  SimTK::MobilizedBodyIndex
 This is for arrays indexed by mobilized body number within a subsystem (typically the SimbodyMatterSubsystem). It is assigned when a MobilizedBody is added to a subsystem. You can abbreviate this as MobodIndex if you prefer. More...
 
class  SimTK::ConstraintIndex
 This is for arrays indexed by constraint number within a subsystem (typically the SimbodyMatterSubsystem). It is assigned when a Constraint is added to the subsystem. More...
 
class  SimTK::MobilizerQIndex
 The Mobilizer associated with each MobilizedBody, once modeled, has a specific number of generalized coordinates q (0-7) and generalized speeds (mobilities) u (0-6). This is the index type for the small array of Mobilizer-local q's. More...
 
class  SimTK::MobilizerUIndex
 The Mobilizer associated with each MobilizedBody, once modeled, has a specific number of generalized coordinates q (0-7) and generalized speeds (mobilities) u (0-6). This is the index type for the small array of Mobilizer-local u's. More...
 
class  SimTK::ForceIndex
 This type represents the index of a Force element within its subsystem. More...
 

Typedefs

typedef MobilizedBodyIndex SimTK::MobodIndex
 This is the approved abbeviation for MobilizedBodyIndex. Feel free to use it if you get tired of typing or seeing the full name. More...
 

Functions

static const MobilizedBodyIndex SimTK::GroundIndex (0)
 This is the MobilizedBodyIndex corresponding to the unique Ground body; its index is always zero. More...
 

Detailed Description

It is common to store objects or information about them in randomly-indexable arrays, and then to support maximum-performance selection by allowing the index to be used.

We want these arrays indexable by simple ints for speed, but this quickly leads to APIs in which there are multiple int arguments in a function call, each intended to select a different kind of object. A common error when there is a series of identical argument types is to put them in the wrong order. To avoid that, we define unique index types here for accessing each category to help stay out of trouble.

A unique index type is just a type-safe non-negative int, augmented with a "NaN" value called InvalidBLAH where BLAH is the type name. For most uses it will behave like an int, and it has an implicit conversion to int. Importantly though, it has no implicit conversion from int so you can't pass a plain int or any other Index type to an argument expecting a certain Index type.

Typedef Documentation

◆ MobodIndex

This is the approved abbeviation for MobilizedBodyIndex. Feel free to use it if you get tired of typing or seeing the full name.

Function Documentation

◆ GroundIndex()

static const MobilizedBodyIndex SimTK::GroundIndex ( )
static

This is the MobilizedBodyIndex corresponding to the unique Ground body; its index is always zero.