opensurgsim
NamedData.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2012-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_DATASTRUCTURES_NAMEDDATA_H
17 #define SURGSIM_DATASTRUCTURES_NAMEDDATA_H
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
24 #include "SurgSim/DataStructures/IndexDirectory.h"
25 
26 namespace SurgSim
27 {
28 namespace DataStructures
29 {
32 typedef std::unordered_map<int, int> NamedDataCopyMap;
33 
35 
36 namespace Names
37 {
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";
43 static const char* const TOOLDOF = "toolDof";
44 
45 static const char* const POSE = "pose";
46 static const char* const INPUT_POSE = "inputPose";
47 
48 static const char* const ANGULAR_VELOCITY = "angularVelocity";
49 static const char* const LINEAR_VELOCITY = "linearVelocity";
50 static const char* const INPUT_ANGULAR_VELOCITY = "inputAngularVelocity";
51 static const char* const INPUT_LINEAR_VELOCITY = "inputLinearVelocity";
52 
53 static const char* const FORCE = "force";
54 static const char* const TORQUE = "torque";
55 
56 static const char* const DAMPER_JACOBIAN = "damperJacobian";
57 static const char* const SPRING_JACOBIAN = "springJacobian";
58 
59 static const char* const IS_HOMED = "isHomed";
60 static const char* const IS_ORIENTATION_HOMED = "isOrientationHomed";
61 static const char* const IS_POSITION_HOMED = "isPositionHomed";
62 
63 static const char* const DIGITAL_INPUT_PREFIX = "digitalInput";
64 static const char* const DIGITAL_OUTPUT_PREFIX = "digitalOutput";
65 static const char* const TIMER_INPUT_PREFIX = "timerInput";
66 static const char* const TIMER_OUTPUT_PREFIX = "timerOutput";
67 static const char* const ANALOG_INPUT_PREFIX = "analogInput";
68 static const char* const ANALOG_OUTPUT_PREFIX = "analogOutput";
69 
70 static const char* const PROJECTION_MATRIX = "projectionMatix";
71 static const char* const LEFT_PROJECTION_MATRIX = "leftProjectionMatix";
72 static const char* const RIGHT_PROJECTION_MATRIX = "rightProjectionMatix";
73 
74 static const char* const KEY = "key";
75 };
76 
101 template <typename T>
103 {
104 public:
106  inline NamedData();
107 
112  inline explicit NamedData(std::shared_ptr<const IndexDirectory> directory);
113 
118  inline explicit NamedData(const std::vector<std::string>& names);
119 
123  inline NamedData(const NamedData& namedData);
124 
151  inline NamedData& operator=(const NamedData& namedData);
152 
156  inline NamedData(NamedData&& namedData);
157 
165  inline NamedData& operator=(NamedData&& namedData);
166 
172  inline bool isValid() const;
173 
177  inline std::shared_ptr<const IndexDirectory> getDirectory() const;
178 
182  inline int getIndex(const std::string& name) const;
183 
187  inline std::string getName(int index) const;
188 
194  inline bool hasEntry(int index) const;
195 
201  inline bool hasEntry(const std::string& name) const;
202 
210  inline bool hasData(int index) const;
211 
219  inline bool hasData(const std::string& name) const;
220 
229  inline bool get(int index, T* value) const;
230 
239  inline bool get(const std::string& name, T* value) const;
240 
247  inline bool set(int index, const T& value);
248 
256  inline bool set(int index, T&& value);
257 
264  inline bool set(const std::string& name, const T& value);
265 
273  inline bool set(const std::string& name, T&& value);
274 
279  inline bool reset(int index);
280 
285  inline bool reset(const std::string& name);
286 
288  inline void resetAll();
289 
293  inline size_t size() const;
294 
298  inline int getNumEntries() const;
299 
304  template <typename N>
305  void copy(const NamedData<N>& source, const NamedDataCopyMap& map);
306 
310  void cacheIndex(const std::string& name, int* index) const;
311 
312 private:
314  std::shared_ptr<const IndexDirectory> m_directory;
315 
317  std::vector<T> m_data;
318 
320  std::vector<bool> m_isDataValid;
321 };
322 
323 }; // namespace DataStructures
324 }; // namespace SurgSim
325 
326 
327 #include "SurgSim/DataStructures/NamedData-inl.h"
328 
329 
330 #endif // SURGSIM_DATASTRUCTURES_NAMEDDATA_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
A templated dictionary in which data can be accessed by name or index, with immutable names & indices...
Definition: NamedData.h:102
The header that provides the assertion API.