opensurgsim
MlcpMapping.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_PHYSICS_MLCPMAPPING_H
17 #define SURGSIM_PHYSICS_MLCPMAPPING_H
18 
19 #include <unordered_map>
20 
21 namespace SurgSim
22 {
23 namespace Physics
24 {
25 
26 template <class T>
28 {
29 public:
30  MlcpMapping(){}
31 
33  void clear()
34  {
35  m_indexMapping.clear();
36  }
37 
39  void setValue(const T* key, size_t value)
40  {
41  typename std::unordered_map<const T*, ptrdiff_t>::iterator found = m_indexMapping.find(key);
42  if (found == m_indexMapping.end())
43  {
44  m_indexMapping.insert(std::make_pair(key, value));
45  }
46  else
47  {
48  (*found).second = value;
49  }
50  }
51 
53  ptrdiff_t getValue(const T* key) const
54  {
55  typename std::unordered_map<const T*, ptrdiff_t>::const_iterator returnValue = m_indexMapping.find(key);
56  return (returnValue == m_indexMapping.end() ? -1 : (*returnValue).second);
57  }
58 
59 private:
60 
62  std::unordered_map<const T*, ptrdiff_t> m_indexMapping;
63 };
64 
65 }; // Physics
66 }; // SurgSim
67 
68 #endif // SURGSIM_PHYSICS_MLCPMAPPING_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
void clear()
Clear the mapping.
Definition: MlcpMapping.h:33
void setValue(const T *key, size_t value)
Sets the key/value (add an entry if the key is not found, change the value otherwise) ...
Definition: MlcpMapping.h:39
Definition: MlcpMapping.h:27
ptrdiff_t getValue(const T *key) const
Gets the value from a given key.
Definition: MlcpMapping.h:53