OSVR-Core
InterfaceState.h
Go to the documentation of this file.
1 
11 // Copyright 2014 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_InterfaceState_h_GUID_FFF8951B_3677_4EB5_373A_3A1A697AECDE
26 #define INCLUDED_InterfaceState_h_GUID_FFF8951B_3677_4EB5_373A_3A1A697AECDE
27 
28 // Internal Includes
30 #include <osvr/Common/StateType.h>
32 #include <osvr/Util/TimeValue.h>
33 #include <osvr/Common/Tracing.h>
35 #include <osvr/TypePack/Quote.h>
36 
37 // Library/third-party includes
38 #include <boost/optional.hpp>
39 
40 // Standard includes
41 // - none
42 
43 namespace osvr {
44 namespace common {
47  template <typename ReportType> struct StateMapContents {
48  using state_type = traits::StateFromReport_t<ReportType>;
49  state_type state;
50  util::time::TimeValue timestamp;
51  };
52 
55  template <typename ReportType>
56  using StateMapValueType = boost::optional<StateMapContents<ReportType>>;
57 
60  using StateMap =
63 
67  public:
68  template <typename ReportType>
69  void setStateFromReport(util::time::TimeValue const &timestamp,
70  ReportType const &report) {
72  c.state = reportState(report);
73  c.timestamp = timestamp;
74  typepack::get<ReportType, StateMap>(m_states) = c;
75  m_hasState = true;
76  }
77 
78  template <typename ReportType> bool hasState() const {
79  // using typepack::get;
80  return m_hasState && bool(typepack::cget<ReportType>(m_states));
81  }
82 
83  bool hasAnyState() const { return m_hasState; }
84 
85  template <typename ReportType>
88  if (hasState<ReportType>()) {
89  timestamp = typepack::cget<ReportType>(m_states)->timestamp;
90  state = typepack::cget<ReportType>(m_states)->state;
91  }
94  }
95 
96  private:
97  StateMap m_states;
98  bool m_hasState = false;
99  };
100 
101 } // namespace common
102 } // namespace osvr
103 
104 #endif // INCLUDED_InterfaceState_h_GUID_FFF8951B_3677_4EB5_373A_3A1A697AECDE
typepack::t_< StateType< T >> StateFromReport_t
Alias for the StateType associated with a given ReportType.
Definition: ReportTraits.h:83
A templated type containing state and a timestamp for known, specialized report types.
Definition: InterfaceState.h:47
Handles spatial transformations.
Definition: SerializationTraitExample_Complicated.h:40
Turn a class template or alias template C into a Alias Class.
Definition: Quote.h:46
Class to maintain state for an interface for each report (and thus state) type explicitly enumerated...
Definition: InterfaceState.h:66
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
typepack::list< OSVR_AnalogReport, OSVR_ButtonReport, OSVR_PoseReport, OSVR_PositionReport, OSVR_OrientationReport, OSVR_VelocityReport, OSVR_LinearVelocityReport, OSVR_AngularVelocityReport, OSVR_AccelerationReport, OSVR_LinearAccelerationReport, OSVR_AngularAccelerationReport, OSVR_ImagingReport, OSVR_ImagingReport, OSVR_Location2DReport, OSVR_DirectionReport, OSVR_EyeTracker2DReport, OSVR_EyeTracker3DReport, OSVR_EyeTrackerBlinkReport, OSVR_NaviVelocityReport, OSVR_NaviPositionReport, OSVR_SkeletonReport > ReportTypeList
A typelist containing all internally-handled report types.
Definition: ReportTypes.h:53
boost::optional< StateMapContents< ReportType >> StateMapValueType
Alias taking a report type and returning a state map value type.
Definition: InterfaceState.h:56
Provides a data structure where a value of heterogeneous data types may be stored at runtime for each...
Definition: TypeKeyedTuple.h:48
Header.
traits::StateType< ReportType >::type const & reportState(ReportType const &r)
Generic const accessor for the "state" member of a report.
Definition: ReportState.h:115
Header containing a typelist of all special report types.
Header.
void getState(util::time::TimeValue &timestamp, traits::StateFromReport_t< ReportType > &state) const
Definition: InterfaceState.h:86
Header providing a C++ wrapper around TimeValueC.h.
Header.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81