OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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/variant/variant.hpp>
44 #include <boost/mpl/contains.hpp>
45 #include <boost/operators.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 
246  template <typename Type> inline ElementBase<Type>::ElementBase() {
254  static_assert(std::is_base_of<base_type, type>::value,
255  "ElementBase<T> must be the base of an element "
256  "type T (the CRTP)!");
257 
260  static_assert(
261  boost::mpl::contains<PathElement::types, type>::type::value,
262  "Every element type must be a part of the PathElement variant "
263  "type's bounded type list!");
264  }
265 
266  } // namespace elements
267 
268 } // namespace common
269 } // namespace osvr
270 
271 #endif // INCLUDED_PathElementTypes_h_GUID_5CC817E5_C7CB_45AE_399D_0B0D39579374
EmptyElementBase()
Protected constructor to force subclassing.
The element type corresponding to a path alias, with a priority level for sorting out whether automat...
Header defining some special values that may be passed to some functions that request a port number t...
AliasPriority & priority()
Get/set whether this alias was automatically set (and thus subject to being override by explicit rout...
std::string & getSource()
Get the source of data for this alias.
The element type corresponding to a particular sensor of an interface.
The element type corresponding to a plugin.
static DeviceElement createDeviceElement(std::string const &deviceName, std::string const &server, int port=util::UseDefaultPort)
The element type corresponding to a device, which implements 0 or more interfaces.
bool operator==(DeviceElement const &other) const
Equality comparison operator.
bool operator==(AliasElement const &rhs) const
Equality comparison operator.
Namespace for the various element types that may constitute a node in the path tree.
Base, using the CRTP, of "empty" path elements (those that don't store additional data but derive the...
The element type corresponding to a string value such as a JSON string.
The element type corresponding to an interface, which often may have one or more sensors.
ElementBase()
Protected constructor to force subclassing.
std::string & getString()
Get/set (if non const) the stored string.
void setSource(std::string const &source)
Sets the source of this alias.
Automatically-generated export header - do not edit!
Header forward-declaring the types in PathElementTypes.h and including the PathElement typedef...
Base, using the CRTP, providing some basic functionality for path elements.
The element type created when requesting a path that isn't yet in the tree.
bool operator==(EmptyElementBase< Type > const &) const
Trivial equality comparison operator.
bool operator==(StringElement const &other) const
Equality comparison operator.