OSVR-Core
PathElementTypes.h
Go to the documentation of this file.
1 
20 // Copyright 2014 Sensics, Inc.
21 //
22 // Licensed under the Apache License, Version 2.0 (the "License");
23 // you may not use this file except in compliance with the License.
24 // You may obtain a copy of the License at
25 //
26 // http://www.apache.org/licenses/LICENSE-2.0
27 //
28 // Unless required by applicable law or agreed to in writing, software
29 // distributed under the License is distributed on an "AS IS" BASIS,
30 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 // See the License for the specific language governing permissions and
32 // limitations under the License.
33 
34 #ifndef INCLUDED_PathElementTypes_h_GUID_5CC817E5_C7CB_45AE_399D_0B0D39579374
35 #define INCLUDED_PathElementTypes_h_GUID_5CC817E5_C7CB_45AE_399D_0B0D39579374
36 
37 // Internal Includes
38 #include <osvr/Common/Export.h>
39 #include <osvr/Common/PathElementTypes_fwd.h> // IWYU pragma: export
40 #include <osvr/Util/PortFlags.h>
41 
42 // Library/third-party includes
43 #include <boost/mpl/contains.hpp>
44 #include <boost/operators.hpp>
45 #include <boost/variant/variant.hpp>
46 #include <json/value.h>
47 
48 // Standard includes
49 #include <string>
50 #include <type_traits>
51 
52 namespace osvr {
53 namespace common {
56 #ifndef OSVR_DOXYGEN_EXTERNAL
57 #endif
62  namespace elements {
65  template <typename Type> class ElementBase {
66  public:
67  typedef Type type;
69 
70  const char *getTypeName() const;
71 
72  protected:
77  ElementBase();
78  };
79 
83  template <typename Type>
84  class EmptyElementBase : public ElementBase<Type>,
85  boost::operators<Type> {
86  public:
88 
89  bool operator==(EmptyElementBase<Type> const &) const {
90  return true;
91  }
92 
93  protected:
96  };
97 
100  class NullElement : public EmptyElementBase<NullElement> {
101  public:
102  NullElement() = default;
103  };
104 
106  class PluginElement : public EmptyElementBase<PluginElement> {
107  public:
108  PluginElement() = default;
109  };
110 
113  class DeviceElement : public ElementBase<DeviceElement>,
114  boost::operators<DeviceElement> {
115  public:
116  DeviceElement() = default;
117  DeviceElement(std::string const &deviceName,
118  std::string const &server)
119  : m_devName(deviceName), m_server(server) {}
120 
121  OSVR_COMMON_EXPORT static DeviceElement
122  createVRPNDeviceElement(std::string const &deviceName,
123  std::string const &server);
124 
127  OSVR_COMMON_EXPORT static DeviceElement
128  createDeviceElement(std::string const &deviceName,
129  std::string const &server,
130  int port = util::UseDefaultPort);
131 
132  OSVR_COMMON_EXPORT std::string &getDeviceName();
133  OSVR_COMMON_EXPORT std::string const &getDeviceName() const;
134  OSVR_COMMON_EXPORT std::string &getServer();
135  OSVR_COMMON_EXPORT std::string const &getServer() const;
136  OSVR_COMMON_EXPORT std::string getFullDeviceName() const;
137 
138  OSVR_COMMON_EXPORT Json::Value &getDescriptor();
139  OSVR_COMMON_EXPORT Json::Value const &getDescriptor() const;
140 
142  bool operator==(DeviceElement const &other) const {
143  return m_devName == other.m_devName &&
144  m_server == other.m_server &&
145  m_descriptor == other.m_descriptor;
146  }
147 
148  private:
149  std::string m_devName;
150  std::string m_server;
151  Json::Value m_descriptor;
152  };
153 
156  class InterfaceElement : public EmptyElementBase<InterfaceElement> {
157  public:
158  InterfaceElement() = default;
159  };
160 
163  class SensorElement : public EmptyElementBase<SensorElement> {
164  public:
165  SensorElement() = default;
166  };
167 
173  class AliasElement : public ElementBase<AliasElement>,
174  boost::operators<DeviceElement> {
175  public:
177  OSVR_COMMON_EXPORT
178  AliasElement(std::string const &source, AliasPriority priority);
179 
181  OSVR_COMMON_EXPORT
182  AliasElement(std::string const &source);
183 
185  AliasElement() : AliasElement("", ALIASPRIORITY_MINIMUM) {}
186 
192  OSVR_COMMON_EXPORT void setSource(std::string const &source);
193 
195  OSVR_COMMON_EXPORT std::string &getSource();
197  OSVR_COMMON_EXPORT std::string const &getSource() const;
198 
201  OSVR_COMMON_EXPORT AliasPriority &priority();
203  OSVR_COMMON_EXPORT AliasPriority priority() const;
204 
206  bool operator==(AliasElement const &rhs) const {
207  return m_priority == rhs.m_priority && m_source == rhs.m_source;
208  }
209 
210  private:
211  std::string m_source;
212  AliasPriority m_priority;
213  };
214 
217  class StringElement : public ElementBase<StringElement> {
218  public:
220  OSVR_COMMON_EXPORT
221  StringElement();
222 
224  OSVR_COMMON_EXPORT
225  StringElement(std::string const &s);
226 
228  OSVR_COMMON_EXPORT std::string &getString();
229 
231  OSVR_COMMON_EXPORT std::string const &getString() const;
232 
234  bool operator==(StringElement const &other) const {
235  return m_val == other.m_val;
236  }
237 
238  private:
239  std::string m_val;
240  };
241 
243 
244  class ArticulationElement : public ElementBase<ArticulationElement>,
245  boost::operators<ArticulationElement> {
246  public:
247  ArticulationElement() = default;
248  ArticulationElement(std::string const &articulationType,
249  std::string const &boneName,
250  std::string const &trackerPath)
251  : m_articulationType(articulationType), m_boneName(boneName),
252  m_trackerPath(trackerPath) {}
253 
255  OSVR_COMMON_EXPORT void
256  setArticulationType(std::string const &articulationType);
257 
259  OSVR_COMMON_EXPORT void setBoneName(std::string const &boneName);
260 
262  OSVR_COMMON_EXPORT void
263  setTrackerPath(std::string const &trackerPath);
264 
265  OSVR_COMMON_EXPORT std::string &getArticulationType();
266  OSVR_COMMON_EXPORT std::string const &getArticulationType() const;
267  OSVR_COMMON_EXPORT std::string &getBoneName();
268  OSVR_COMMON_EXPORT std::string const &getBoneName() const;
269  OSVR_COMMON_EXPORT std::string &getTrackerPath();
270  OSVR_COMMON_EXPORT std::string const &getTrackerPath() const;
271 
273  bool operator==(ArticulationElement const &other) const {
274  return m_articulationType == other.m_articulationType &&
275  m_boneName == other.m_boneName &&
276  m_trackerPath == other.m_trackerPath;
277  }
278 
279  private:
280  std::string m_articulationType;
281  std::string m_boneName;
282  std::string m_trackerPath;
283  };
284 
289  template <typename Type> inline ElementBase<Type>::ElementBase() {
297  static_assert(std::is_base_of<base_type, type>::value,
298  "ElementBase<T> must be the base of an element "
299  "type T (the CRTP)!");
300 
303  static_assert(
304  boost::mpl::contains<PathElement::types, type>::type::value,
305  "Every element type must be a part of the PathElement variant "
306  "type's bounded type list!");
307  }
308 
309  } // namespace elements
310 
311 } // namespace common
312 } // namespace osvr
313 
314 #endif // INCLUDED_PathElementTypes_h_GUID_5CC817E5_C7CB_45AE_399D_0B0D39579374
The element type corresponding to a articulation element.
Definition: PathElementTypes.h:244
EmptyElementBase()
Protected constructor to force subclassing.
Definition: PathElementTypes.h:95
Handles spatial transformations.
Definition: SerializationTraitExample_Complicated.h:40
bool operator==(StringElement const &other) const
Equality comparison operator.
Definition: PathElementTypes.h:234
The element type corresponding to a path alias, with a priority level for sorting out whether automat...
Definition: PathElementTypes.h:173
Header defining some special values that may be passed to some functions that request a port number t...
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
The element type corresponding to a particular sensor of an interface.
Definition: PathElementTypes.h:163
The element type corresponding to a plugin.
Definition: PathElementTypes.h:106
bool operator==(ArticulationElement const &other) const
Equality comparison operator.
Definition: PathElementTypes.h:273
bool operator==(DeviceElement const &other) const
Equality comparison operator.
Definition: PathElementTypes.h:142
The element type corresponding to a device, which implements 0 or more interfaces.
Definition: PathElementTypes.h:113
bool operator==(AliasElement const &rhs) const
Equality comparison operator.
Definition: PathElementTypes.h:206
bool operator==(EmptyElementBase< Type > const &) const
Trivial equality comparison operator.
Definition: PathElementTypes.h:89
Namespace for the various element types that may constitute a node in the path tree.
Definition: PathElementTools.h:78
Base, using the CRTP, of "empty" path elements (those that don&#39;t store additional data but derive the...
Definition: PathElementTypes.h:84
The element type corresponding to a string value such as a JSON string.
Definition: PathElementTypes.h:217
AliasElement()
default constructor
Definition: PathElementTypes.h:185
The element type corresponding to an interface, which often may have one or more sensors.
Definition: PathElementTypes.h:156
ElementBase()
Protected constructor to force subclassing.
Definition: PathElementTypes.h:289
Header forward-declaring the types in PathElementTypes.h and including the PathElement typedef...
Base, using the CRTP, providing some basic functionality for path elements.
Definition: PathElementTypes.h:65
The element type created when requesting a path that isn&#39;t yet in the tree.
Definition: PathElementTypes.h:100