Go to the documentation of this file.
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)
39 m_data.resize(m_directory->getNumEntries());
40 m_isDataValid.resize(m_directory->getNumEntries(),
false);
48 m_data.resize(m_directory->getNumEntries());
49 m_isDataValid.resize(m_directory->getNumEntries(),
false);
54 m_directory(namedData.m_directory),
55 m_data(namedData.m_data),
56 m_isDataValid(namedData.m_isDataValid)
65 "Cannot use an invalid (empty) NamedData on the right-hand side of an assignment!";
80 SURGSIM_ASSERT(m_data.size() == m_directory->size() && m_isDataValid.size() == m_directory->size()) <<
81 "NamedData is not correctly sized after assignment!";
88 m_directory(std::move(namedData.m_directory)),
89 m_data(std::move(namedData.m_data)),
90 m_isDataValid(std::move(namedData.m_isDataValid))
99 "Cannot use an invalid (empty) NamedData on the right-hand side of an assignment!";
103 m_directory = std::move(namedData.m_directory);
107 SURGSIM_ASSERT(m_directory == namedData.m_directory) <<
"Incompatible NamedData contents in assignment!";
110 m_data = std::move(namedData.m_data);
111 m_isDataValid = std::move(namedData.m_isDataValid);
114 SURGSIM_ASSERT(m_data.size() == m_directory->size() && m_isDataValid.size() == m_directory->size()) <<
115 "NamedData is not correctly sized after assignment!";
120 template <
typename T>
123 return static_cast<bool>(m_directory);
126 template <
typename T>
132 template <
typename T>
142 template <
typename T>
149 return m_directory->
getName(index);
152 template <
typename T>
155 return ((index >= 0) && (index <
static_cast<int>(m_data.size())));
158 template <
typename T>
168 template <
typename T>
171 return hasEntry(index) && m_isDataValid[index];
174 template <
typename T>
177 int index = getIndex(name);
185 return m_isDataValid[index];
189 template <
typename T>
192 if (! hasData(index))
198 *value = m_data[index];
203 template <
typename T>
206 int index = getIndex(name);
207 if ((index < 0) || ! m_isDataValid[index])
214 *value = m_data[index];
219 template <
typename T>
222 if (! hasEntry(index))
228 m_data[index] = value;
229 m_isDataValid[index] =
true;
234 template <
typename T>
237 if (! hasEntry(index))
243 m_data[index] = std::move(value);
244 m_isDataValid[index] =
true;
249 template <
typename T>
252 int index = getIndex(name);
260 <<
"The directory returned an index larger than the number of entries in the stored data.";
265 template <
typename T>
268 int index = getIndex(name);
276 <<
"The directory returned an index larger than the number of entries in the stored data.";
281 template <
typename T>
284 if (! hasEntry(index))
290 m_isDataValid[index] =
false;
295 template <
typename T>
298 int index = getIndex(name);
306 <<
"The directory returned an index larger than the number of entries in the stored data.";
311 template <
typename T>
314 m_isDataValid.assign(m_data.size(),
false);
317 template <
typename T>
320 return m_data.
size();
323 template <
typename T>
326 return static_cast<int>(m_data.size());
329 template <
typename T>
330 template <
typename N>
333 static_assert(std::is_same<T, N>::value,
"NamedData<T>::copy can only copy from another NamedData<T>.");
334 for (
auto it = map.cbegin(); it != map.cend(); ++it)
337 if (source.
get(it->first, &value))
339 set(it->second, value);
348 template <
typename T>
353 *index = getIndex(name);
360 #endif // SURGSIM_DATASTRUCTURES_NAMEDDATA_INL_H
#define SURGSIM_ASSERT(condition)
Assert that condition is true.
Definition: Assert.h:77
int getIndex(const std::string &name) const
Given a name, return the corresponding index (or -1).
Definition: NamedData-inl.h:133
A simple bidirectional mapping between names (strings) and distinct consecutive non-negative indices.
Definition: IndexDirectory.h:32
size_t size() const
Check the number of existing entries.
Definition: NamedData-inl.h:318
Definition: CompoundShapeToGraphics.cpp:29
bool isValid(float value)
Check if a float value is valid.
Definition: Valid-inl.h:98
A templated dictionary in which data can be accessed by name or index, with immutable names & indices...
Definition: NamedData.h:102
NamedData()
Create an empty object, with no associated names and indices yet.
Definition: NamedData-inl.h:30
set(SURGSIM_COLLISION_SOURCES BoxCapsuleContact.cpp BoxDoubleSidedPlaneContact.cpp BoxPlaneContact.cpp BoxSphereContact.cpp CapsuleSphereContact.cpp CollisionPair.cpp CompoundShapeContact.cpp ContactCalculation.cpp ContactFilter.cpp DefaultContactCalculation.cpp ElementContactFilter.cpp OctreeCapsuleContact.cpp OctreeContact.cpp OctreeDoubleSidedPlaneContact.cpp OctreePlaneContact.cpp OctreeSphereContact.cpp Representation.cpp SegmentMeshTriangleMeshContact.cpp SegmentSegmentCcdIntervalCheck.cpp SegmentSegmentCcdMovingContact.cpp SegmentSegmentCcdStaticContact.cpp SegmentSelfContact.cpp ShapeCollisionRepresentation.cpp SphereDoubleSidedPlaneContact.cpp SpherePlaneContact.cpp SphereSphereContact.cpp TriangleMeshParticlesContact.cpp TriangleMeshPlaneContact.cpp TriangleMeshSurfaceMeshContact.cpp TriangleMeshTriangleMeshContact.cpp) set(SURGSIM_COLLISION_HEADERS BoxCapsuleContact.h BoxDoubleSidedPlaneContact.h BoxPlaneContact.h BoxSphereContact.h CapsuleSphereContact.h CcdDcdCollision.h CollisionPair.h CompoundShapeContact.h ContactCalculation.h ContactFilter.h DefaultContactCalculation.h ElementContactFilter.h OctreeCapsuleContact.h OctreeContact.h OctreeDoubleSidedPlaneContact.h OctreePlaneContact.h OctreeSphereContact.h Representation.h SegmentMeshTriangleMeshContact.h SegmentSegmentCcdIntervalCheck.h SegmentSegmentCcdMovingContact.h SegmentSegmentCcdStaticContact.h SegmentSelfContact.h ShapeCollisionRepresentation.h ShapeShapeContactCalculation.h SphereDoubleSidedPlaneContact.h SpherePlaneContact.h SphereSphereContact.h TriangleMeshParticlesContact.h TriangleMeshPlaneContact.h TriangleMeshSurfaceMeshContact.h TriangleMeshTriangleMeshContact.h) surgsim_create_library_header(Collision.h "$
Definition: CMakeLists.txt:16
std::vector< bool > m_isDataValid
The array storing whether the data is currently valid.
Definition: NamedData.h:320
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
std::shared_ptr< const IndexDirectory > m_directory
The mapping between names and indices.
Definition: NamedData.h:314
bool hasEntry(int index) const
Check whether the object contains an entry with the specified index.
Definition: NamedData-inl.h:153
std::vector< T > m_data
The array of values.
Definition: NamedData.h:317
bool get(int index, T *value) const
Given an index, get the corresponding value.
Definition: NamedData-inl.h:190
std::string getName(int index) const
Given an index, return the corresponding name (or "").
Definition: NamedData-inl.h:143
bool isValid() const
Check if the object has been initialized, which means it has a set of entries (i.e....
Definition: NamedData-inl.h:121
void cacheIndex(const std::string &name, int *index) const
Caches an entry's index if it is not already cached.
Definition: NamedData-inl.h:349
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38