OSVR-Core
BeaconIdTypes.h
Go to the documentation of this file.
1 
11 // Copyright 2016 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_BeaconIdTypes_h_GUID_8C85DE41_5CAC_4DA2_6C2A_962680202E1B
26 #define INCLUDED_BeaconIdTypes_h_GUID_8C85DE41_5CAC_4DA2_6C2A_962680202E1B
27 
28 // Internal Includes
29 #include "BodyIdTypes.h"
30 
31 // Library/third-party includes
32 #include <osvr/Util/TypeSafeId.h>
33 #include <boost/assert.hpp>
34 
35 // Standard includes
36 #include <stdexcept>
37 
38 namespace osvr {
39 namespace vbtracker {
40  namespace detail {
42  struct ZeroBasedBeaconIdTag;
44  struct OneBasedBeaconIdTag;
45 
46  } // namespace detail
47 
50 } // namespace vbtracker
51 } // namespace osvr
52 
53 namespace osvr {
54 namespace util {
55  namespace typesafeid_traits {
57  template <>
58  struct WrappedType<vbtracker::detail::ZeroBasedBeaconIdTag> {
60  };
62  template <> struct WrappedType<vbtracker::detail::OneBasedBeaconIdTag> {
64  };
65  } // namespace typesafeid_traits
66 
67 } // namespace util
68 } // namespace osvr
69 
70 namespace osvr {
71 namespace vbtracker {
76 
80  OneBasedBeaconId ret;
81  if (id.empty()) {
82  return ret;
83  } else if (id.value() < 0) {
84  ret = OneBasedBeaconId(id.value());
85  } else {
86  ret = OneBasedBeaconId(id.value() + 1);
87  }
88  return ret;
89  }
90 
93  inline OneBasedBeaconId const &makeOneBased(OneBasedBeaconId const &id) {
94  return id;
95  }
96 
100  ZeroBasedBeaconId ret;
101  if (id.empty()) {
102  return ret;
103  } else if (id.value() < 0) {
104  ret = ZeroBasedBeaconId(id.value());
105  } else {
106  ret = ZeroBasedBeaconId(id.value() - 1);
107  }
108  return ret;
109  }
110 
114  return id;
115  }
116 
119  return (!id.empty() && id.value() >= 0);
120  }
122  inline bool beaconIdentified(OneBasedBeaconId id) {
123  return (!id.empty() && id.value() > 0);
124  }
125 
128  inline std::size_t asIndex(ZeroBasedBeaconId id) {
129  BOOST_ASSERT_MSG(beaconIdentified(id), "A beacon id must correspond to "
130  "an identified beacon to be "
131  "used as an index!");
132  if (!beaconIdentified(id)) {
133  throw std::logic_error("A beacon id must correspond to an "
134  "identified beacon to be used as an index!");
135  }
136  return id.value();
137  }
138 
140  inline std::size_t asIndex(OneBasedBeaconId id) {
141  return asIndex(makeZeroBased(id));
142  }
143 
144 } // namespace vbtracker
145 } // namespace osvr
146 #endif // INCLUDED_BeaconIdTypes_h_GUID_8C85DE41_5CAC_4DA2_6C2A_962680202E1B
ZeroBasedBeaconId makeZeroBased(OneBasedBeaconId id)
Overloaded conversion function to turn any beacon ID into zero-based, respecting the convention that ...
Definition: BeaconIdTypes.h:99
Definition: RunLoopManager.h:42
std::size_t asIndex(ZeroBasedBeaconId id)
Turn a (valid non-sentinel, i.e.
Definition: BeaconIdTypes.h:128
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Definition: newuoa.h:1888
OneBasedBeaconId makeOneBased(ZeroBasedBeaconId id)
Overloaded conversion function to turn any beacon ID into one-based, respecting the convention that n...
Definition: BeaconIdTypes.h:79
bool beaconIdentified(ZeroBasedBeaconId id)
Does the given beacon ID indicate that it&#39;s identified?
Definition: BeaconIdTypes.h:118
Explicitly specialize for your tag type if you want a different underlying type.
Definition: TypeSafeId.h:49
int UnderlyingBeaconIdType
All beacon IDs, whether 0 or 1 based, are ints on the inside.
Definition: BeaconIdTypes.h:49
Header.