16 #ifndef SURGSIM_DATASTRUCTURES_NAMEDDATA_INL_H 17 #define SURGSIM_DATASTRUCTURES_NAMEDDATA_INL_H 19 #include <type_traits> 26 namespace DataStructures
36 m_directory(directory)
65 "Cannot use an invalid (empty) NamedData on the right-hand side of an assignment!";
81 "NamedData is not correctly sized after assignment!";
99 "Cannot use an invalid (empty) NamedData on the right-hand side of an assignment!";
110 m_data = std::move(namedData.m_data);
115 "NamedData is not correctly sized after assignment!";
120 template <
typename T>
126 template <
typename T>
132 template <
typename T>
142 template <
typename T>
152 template <
typename T>
155 return ((index >= 0) && (index < static_cast<int>(
m_data.size())));
158 template <
typename T>
168 template <
typename T>
174 template <
typename T>
193 template <
typename T>
207 template <
typename T>
227 template <
typename T>
242 template <
typename T>
263 template <
typename T>
277 template <
typename T>
297 template <
typename T>
303 template <
typename T>
309 template <
typename T>
312 return static_cast<int>(
m_data.size());
315 template <
typename T>
316 template <
typename N>
319 static_assert(std::is_same<T, N>::value,
"NamedData<T>::copy can only copy from another NamedData<T>.");
320 for (
auto it = map.cbegin(); it != map.cend(); ++it)
323 if (source.
get(it->first, &value))
325 set(it->second, value);
334 template <
typename T>
346 #endif // SURGSIM_DATASTRUCTURES_NAMEDDATA_INL_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
#define SURGSIM_ASSERT(condition)
Assert that condition is true.
Definition: Assert.h:77
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
string(TOUPPER ${DEVICE}DEVICE_UPPER_CASE) option(BUILD_DEVICE_ $
Definition: CMakeLists.txt:35
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
A simple bidirectional mapping between names (strings) and distinct consecutive non-negative indices...
Definition: IndexDirectory.h:32
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
bool get(int index, T *value) const
Given an index, get the corresponding value.
Definition: NamedData-inl.h:194
size_t size() const
Check the number of existing entries.
Definition: NamedData-inl.h:304