16 #ifndef SURGSIM_DATASTRUCTURES_NAMEDDATA_H
17 #define SURGSIM_DATASTRUCTURES_NAMEDDATA_H
28 namespace DataStructures
38 static const char*
const BUTTON_0 =
"button0";
39 static const char*
const BUTTON_1 =
"button1";
40 static const char*
const BUTTON_2 =
"button2";
41 static const char*
const BUTTON_3 =
"button3";
42 static const char*
const BUTTON_4 =
"button4";
44 static const char*
const POSE =
"pose";
45 static const char*
const INPUT_POSE =
"inputPose";
47 static const char*
const ANGULAR_VELOCITY =
"angularVelocity";
48 static const char*
const LINEAR_VELOCITY =
"linearVelocity";
49 static const char*
const INPUT_ANGULAR_VELOCITY =
"inputAngularVelocity";
50 static const char*
const INPUT_LINEAR_VELOCITY =
"inputLinearVelocity";
52 static const char*
const FORCE =
"force";
53 static const char*
const TORQUE =
"torque";
55 static const char*
const DAMPER_JACOBIAN =
"damperJacobian";
56 static const char*
const SPRING_JACOBIAN =
"springJacobian";
58 static const char*
const IS_HOMED =
"isHomed";
59 static const char*
const IS_ORIENTATION_HOMED =
"isOrientationHomed";
60 static const char*
const IS_POSITION_HOMED =
"isPositionHomed";
62 static const char*
const DIGITAL_INPUT_PREFIX =
"digitalInput";
63 static const char*
const DIGITAL_OUTPUT_PREFIX =
"digitalOutput";
64 static const char*
const TIMER_INPUT_PREFIX =
"timerInput";
65 static const char*
const TIMER_OUTPUT_PREFIX =
"timerOutput";
66 static const char*
const ANALOG_INPUT_PREFIX =
"analogInput";
67 static const char*
const ANALOG_OUTPUT_PREFIX =
"analogOutput";
105 inline explicit NamedData(std::shared_ptr<const IndexDirectory> directory);
111 inline explicit NamedData(
const std::vector<std::string>& names);
170 inline std::shared_ptr<const IndexDirectory>
getDirectory()
const;
175 inline int getIndex(
const std::string& name)
const;
180 inline std::string
getName(
int index)
const;
187 inline bool hasEntry(
int index)
const;
194 inline bool hasEntry(
const std::string& name)
const;
203 inline bool hasData(
int index)
const;
212 inline bool hasData(
const std::string& name)
const;
222 inline bool get(
int index, T* value)
const;
232 inline bool get(
const std::string& name, T* value)
const;
240 inline bool set(
int index,
const T& value);
248 inline bool set(
const std::string& name,
const T& value);
254 inline bool reset(
int index);
260 inline bool reset(
const std::string& name);
268 inline size_t size()
const;
279 template <
typename N>
285 void cacheIndex(
const std::string& name,
int* index)
const;
305 #endif // SURGSIM_DATASTRUCTURES_NAMEDDATA_H
Definition: DriveElementFromInputBehavior.cpp:27
A templated dictionary in which data can be accessed by name or index, with immutable names & indices...
Definition: NamedData.h:95
std::vector< T > m_data
The array of values.
Definition: NamedData.h:292
bool hasData(int index) const
Check whether the entry with the specified index contains valid data.
Definition: NamedData-inl.h:169
bool hasEntry(int index) const
Check whether the object contains an entry with the specified index.
Definition: NamedData-inl.h:153
std::shared_ptr< const IndexDirectory > getDirectory() const
Return the object's layout directory, which is its collection of names and indices.
Definition: NamedData-inl.h:127
std::string getName(int index) const
Given an index, return the corresponding name (or "").
Definition: NamedData-inl.h:143
bool set(int index, const T &value)
Record the data for an entry specified by an index.
Definition: NamedData-inl.h:228
int getNumEntries() const
Check the number of existing entries.
Definition: NamedData-inl.h:310
std::unordered_map< int, int > NamedDataCopyMap
The type used for copying values between two NamedData objects that cannot assign to each other...
Definition: NamedData.h:32
bool isValid() const
Check if the object has been initialized, which means it has a set of entries (i.e., names, indices, and the map between them).
Definition: NamedData-inl.h:121
int getIndex(const std::string &name) const
Given a name, return the corresponding index (or -1).
Definition: NamedData-inl.h:133
NamedData & operator=(const NamedData &namedData)
Copy the data from another object.
Definition: NamedData-inl.h:62
std::vector< bool > m_isDataValid
The array storing whether the data is currently valid.
Definition: NamedData.h:295
void resetAll()
Invalidate all entries— mark everything as not containing any valid data.
Definition: NamedData-inl.h:298
void copy(const NamedData< N > &source, const NamedDataCopyMap &map)
Copy the data from another NamedData, based on a map of indices.
Definition: NamedData-inl.h:317
bool reset(int index)
Invalidate an entry— mark it as not containing any valid data.
Definition: NamedData-inl.h:264
The header that provides the assertion API.
void cacheIndex(const std::string &name, int *index) const
Caches an entry's index if it is not already cached.
Definition: NamedData-inl.h:335
std::shared_ptr< const IndexDirectory > m_directory
The mapping between names and indices.
Definition: NamedData.h:289
NamedData()
Create an empty object, with no associated names and indices yet.
Definition: NamedData-inl.h:30
size_t size() const
Check the number of existing entries.
Definition: NamedData-inl.h:304