25 #ifndef INCLUDED_BeaconIdTypes_h_GUID_8C85DE41_5CAC_4DA2_6C2A_962680202E1B
26 #define INCLUDED_BeaconIdTypes_h_GUID_8C85DE41_5CAC_4DA2_6C2A_962680202E1B
33 #include <boost/assert.hpp>
42 struct ZeroBasedBeaconIdTag;
44 struct OneBasedBeaconIdTag;
49 using UnderlyingBeaconIdType = int;
55 namespace typesafeid_traits {
59 using type = vbtracker::UnderlyingBeaconIdType;
62 template <>
struct WrappedType<vbtracker::detail::OneBasedBeaconIdTag> {
63 using type = vbtracker::UnderlyingBeaconIdType;
73 using ZeroBasedBeaconId = util::TypeSafeId<detail::ZeroBasedBeaconIdTag>;
75 using OneBasedBeaconId = util::TypeSafeId<detail::OneBasedBeaconIdTag>;
79 inline OneBasedBeaconId makeOneBased(ZeroBasedBeaconId
id) {
83 }
else if (
id.value() < 0) {
84 ret = OneBasedBeaconId(
id.value());
86 ret = OneBasedBeaconId(
id.value() + 1);
93 inline OneBasedBeaconId
const &makeOneBased(OneBasedBeaconId
const &
id) {
99 inline ZeroBasedBeaconId makeZeroBased(OneBasedBeaconId
id) {
100 ZeroBasedBeaconId ret;
103 }
else if (
id.value() < 0) {
104 ret = ZeroBasedBeaconId(
id.value());
106 ret = ZeroBasedBeaconId(
id.value() - 1);
113 inline ZeroBasedBeaconId
const &makeZeroBased(ZeroBasedBeaconId
const &
id) {
118 inline bool beaconIdentified(ZeroBasedBeaconId
id) {
119 return (!
id.empty() &&
id.value() >= 0);
122 inline bool beaconIdentified(OneBasedBeaconId
id) {
123 return (!
id.empty() &&
id.value() > 0);
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!");
140 inline std::size_t asIndex(OneBasedBeaconId
id) {
141 return asIndex(makeZeroBased(
id));
146 #endif // INCLUDED_BeaconIdTypes_h_GUID_8C85DE41_5CAC_4DA2_6C2A_962680202E1B
Explicitly specialize for your tag type if you want a different underlying type.