NamedData.h
Go to the documentation of this file.
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 
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 
328 
329 
330 #endif // SURGSIM_DATASTRUCTURES_NAMEDDATA_H
SurgSim::DataStructures::NamedData::getIndex
int getIndex(const std::string &name) const
Given a name, return the corresponding index (or -1).
Definition: NamedData-inl.h:133
SurgSim::DataStructures::NamedData::size
size_t size() const
Check the number of existing entries.
Definition: NamedData-inl.h:318
SurgSim::DataStructures::NamedData::operator=
NamedData & operator=(const NamedData &namedData)
Copy the data from another object.
Definition: NamedData-inl.h:62
Assert.h
SurgSim::DataStructures::NamedData::resetAll
void resetAll()
Invalidate all entries— mark everything as not containing any valid data.
Definition: NamedData-inl.h:312
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
NamedData-inl.h
SurgSim::DataStructures::NamedData::getDirectory
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
SurgSim::DataStructures::NamedData
A templated dictionary in which data can be accessed by name or index, with immutable names & indices...
Definition: NamedData.h:102
SurgSim::DataStructures::NamedData::NamedData
NamedData()
Create an empty object, with no associated names and indices yet.
Definition: NamedData-inl.h:30
SurgSim::DataStructures::NamedData::copy
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:331
SurgSim::DataStructures::NamedData::hasData
bool hasData(int index) const
Check whether the entry with the specified index contains valid data.
Definition: NamedData-inl.h:169
SurgSim::DataStructures::NamedData::m_isDataValid
std::vector< bool > m_isDataValid
The array storing whether the data is currently valid.
Definition: NamedData.h:320
SurgSim::DataStructures::NamedDataCopyMap
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
SurgSim::DataStructures::NamedData::m_directory
std::shared_ptr< const IndexDirectory > m_directory
The mapping between names and indices.
Definition: NamedData.h:314
SurgSim::DataStructures::NamedData::set
bool set(int index, const T &value)
Record the data for an entry specified by an index.
Definition: NamedData-inl.h:220
SurgSim::DataStructures::NamedData::hasEntry
bool hasEntry(int index) const
Check whether the object contains an entry with the specified index.
Definition: NamedData-inl.h:153
SurgSim::DataStructures::NamedData::m_data
std::vector< T > m_data
The array of values.
Definition: NamedData.h:317
SurgSim::DataStructures::NamedData::get
bool get(int index, T *value) const
Given an index, get the corresponding value.
Definition: NamedData-inl.h:190
SurgSim::DataStructures::NamedData::getNumEntries
int getNumEntries() const
Check the number of existing entries.
Definition: NamedData-inl.h:324
SurgSim::DataStructures::NamedData::getName
std::string getName(int index) const
Given an index, return the corresponding name (or "").
Definition: NamedData-inl.h:143
SurgSim::DataStructures::NamedData::isValid
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
SurgSim::DataStructures::NamedData::cacheIndex
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
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38
IndexDirectory.h
SurgSim::DataStructures::NamedData::reset
bool reset(int index)
Invalidate an entry— mark it as not containing any valid data.
Definition: NamedData-inl.h:282