ad_map_access
LaneId.hpp
Go to the documentation of this file.
1 /*
2  * ----------------- BEGIN LICENSE BLOCK ---------------------------------
3  *
4  * Copyright (C) 2018-2020 Intel Corporation
5  *
6  * SPDX-License-Identifier: MIT
7  *
8  * ----------------- END LICENSE BLOCK -----------------------------------
9  */
10 
18 #pragma once
19 
20 #include <cmath>
21 #include <cstdint>
22 #include <iostream>
23 #include <limits>
24 #include <sstream>
25 #include <stdexcept>
26 #include "spdlog/fmt/ostr.h"
27 #include "spdlog/spdlog.h"
31 namespace ad {
35 namespace map {
41 namespace lane {
42 
46 #define AD_MAP_LANE_LANEID_THROWS_EXCEPTION 1
47 
48 #if SAFE_DATATYPES_EXPLICIT_CONVERSION
49 
52 #define _AD_MAP_LANE_LANEID_EXPLICIT_CONVERSION_ explicit
53 #else
54 
57 #define _AD_MAP_LANE_LANEID_EXPLICIT_CONVERSION_
58 #endif
59 
66 class LaneId
67 {
68 public:
72  static const uint64_t cMinValue;
73 
77  static const uint64_t cMaxValue;
78 
86  : mLaneId(std::numeric_limits<uint64_t>::quiet_NaN())
87  {
88  }
89 
96  : mLaneId(iLaneId)
97  {
98  }
99 
103  LaneId(const LaneId &other) = default;
104 
108  LaneId(LaneId &&other) = default;
109 
117  LaneId &operator=(const LaneId &other) = default;
118 
126  LaneId &operator=(LaneId &&other) = default;
127 
135  bool operator==(const LaneId &other) const
136  {
137  ensureValid();
138  other.ensureValid();
139  return mLaneId == other.mLaneId;
140  }
141 
149  bool operator!=(const LaneId &other) const
150  {
151  return !operator==(other);
152  }
153 
163  bool operator>(const LaneId &other) const
164  {
165  ensureValid();
166  other.ensureValid();
167  return (mLaneId > other.mLaneId) && operator!=(other);
168  }
169 
179  bool operator<(const LaneId &other) const
180  {
181  ensureValid();
182  other.ensureValid();
183  return (mLaneId < other.mLaneId) && operator!=(other);
184  }
185 
195  bool operator>=(const LaneId &other) const
196  {
197  ensureValid();
198  other.ensureValid();
199  return ((mLaneId > other.mLaneId) || operator==(other));
200  }
201 
211  bool operator<=(const LaneId &other) const
212  {
213  ensureValid();
214  other.ensureValid();
215  return ((mLaneId < other.mLaneId) || operator==(other));
216  }
217 
228  LaneId operator+(const LaneId &other) const
229  {
230  ensureValid();
231  other.ensureValid();
232  LaneId const result(mLaneId + other.mLaneId);
233  result.ensureValid();
234  return result;
235  }
236 
247  LaneId &operator+=(const LaneId &other)
248  {
249  ensureValid();
250  other.ensureValid();
251  mLaneId += other.mLaneId;
252  ensureValid();
253  return *this;
254  }
255 
266  LaneId operator-(const LaneId &other) const
267  {
268  ensureValid();
269  other.ensureValid();
270  LaneId const result(mLaneId - other.mLaneId);
271  result.ensureValid();
272  return result;
273  }
274 
285  LaneId operator-=(const LaneId &other)
286  {
287  ensureValid();
288  other.ensureValid();
289  mLaneId -= other.mLaneId;
290  ensureValid();
291  return *this;
292  }
293 
301  {
302  return mLaneId;
303  }
304 
312  bool isValid() const
313  {
314  auto const valueClass = std::fpclassify(mLaneId);
315  return ((valueClass == FP_NORMAL) || (valueClass == FP_ZERO)) && (cMinValue <= mLaneId) && (mLaneId <= cMaxValue);
316  }
317 
324  void ensureValid() const
325  {
326  if (!isValid())
327  {
328  spdlog::info("ensureValid(::ad::map::lane::LaneId)>> {} value out of range", *this); // LCOV_EXCL_BR_LINE
329 #if (AD_MAP_LANE_LANEID_THROWS_EXCEPTION == 1)
330  throw std::out_of_range("LaneId value out of range"); // LCOV_EXCL_BR_LINE
331 #endif
332  }
333  }
334 
341  void ensureValidNonZero() const
342  {
343  ensureValid();
344  if (operator==(LaneId(0))) // LCOV_EXCL_BR_LINE
345  {
346  spdlog::info("ensureValid(::ad::map::lane::LaneId)>> {} value is zero", *this); // LCOV_EXCL_BR_LINE
347 #if (AD_MAP_LANE_LANEID_THROWS_EXCEPTION == 1)
348  throw std::out_of_range("LaneId value is zero"); // LCOV_EXCL_BR_LINE
349 #endif
350  }
351  }
352 
356  static LaneId getMin()
357  {
358  return LaneId(cMinValue);
359  }
360 
364  static LaneId getMax()
365  {
366  return LaneId(cMaxValue);
367  }
368 
369 private:
373  uint64_t mLaneId;
374 };
375 
376 } // namespace lane
377 } // namespace map
378 } // namespace ad
382 namespace std {
383 
392 template <> class numeric_limits<::ad::map::lane::LaneId> : public numeric_limits<uint64_t>
393 {
394 public:
398  static inline ::ad::map::lane::LaneId lowest()
399  {
400  return ::ad::map::lane::LaneId::getMin();
401  }
405  static inline ::ad::map::lane::LaneId max()
406  {
407  return ::ad::map::lane::LaneId::getMax();
408  }
409 
413  static inline ::ad::map::lane::LaneId epsilon()
414  {
415  return ::ad::map::lane::LaneId(0);
416  }
417 };
418 
419 } // namespace std
420 
424 #ifndef GEN_GUARD_AD_MAP_LANE_LANEID
425 #define GEN_GUARD_AD_MAP_LANE_LANEID
426 
429 namespace ad {
433 namespace map {
439 namespace lane {
440 
450 inline std::ostream &operator<<(std::ostream &os, LaneId const &_value)
451 {
452  return os << uint64_t(_value);
453 }
454 
455 } // namespace lane
456 } // namespace map
457 } // namespace ad
458 
459 namespace std {
463 inline std::string to_string(::ad::map::lane::LaneId const &value)
464 {
465  return to_string(static_cast<uint64_t>(value));
466 }
467 } // namespace std
468 #endif // GEN_GUARD_AD_MAP_LANE_LANEID
ad
namespace ad
Definition: GeometryStoreItem.hpp:28
ad::map::lane::LaneId::operator+=
LaneId & operator+=(const LaneId &other)
standard arithmetic operator
Definition: LaneId.hpp:247
ad::map::lane::LaneId::operator-=
LaneId operator-=(const LaneId &other)
standard arithmetic operator
Definition: LaneId.hpp:285
ad::map::lane::LaneId::isValid
bool isValid() const
Definition: LaneId.hpp:312
_AD_MAP_LANE_LANEID_EXPLICIT_CONVERSION_
#define _AD_MAP_LANE_LANEID_EXPLICIT_CONVERSION_
Enable/Disable explicit conversion. Currently set to "implicit conversion allowed".
Definition: LaneId.hpp:57
ad::map::lane::LaneId::operator-
LaneId operator-(const LaneId &other) const
standard arithmetic operator
Definition: LaneId.hpp:266
ad::map::lane::LaneId::ensureValidNonZero
void ensureValidNonZero() const
ensure that the LaneId is valid and non zero
Definition: LaneId.hpp:341
ad::map::lane::LaneId::operator>
bool operator>(const LaneId &other) const
standard comparison operator
Definition: LaneId.hpp:163
std::to_string
std::string to_string(::ad::map::access::GeometryStoreItem const &value)
overload of the std::to_string for GeometryStoreItem
Definition: GeometryStoreItem.hpp:183
ad::map::lane::LaneId::operator>=
bool operator>=(const LaneId &other) const
standard comparison operator
Definition: LaneId.hpp:195
ad::map::lane::LaneId::LaneId
LaneId()
default constructor
Definition: LaneId.hpp:85
ad::map::lane::LaneId::operator=
LaneId & operator=(const LaneId &other)=default
standard assignment operator
ad::map::lane::LaneId::cMaxValue
static const uint64_t cMaxValue
constant defining the maximum valid LaneId value (used in isValid())
Definition: LaneId.hpp:77
ad::map::lane::LaneId
DataType LaneId.
Definition: LaneId.hpp:66
ad::map::lane::LaneId::getMax
static LaneId getMax()
get maximum valid LaneId (i.e. cMaxValue)
Definition: LaneId.hpp:364
std::numeric_limits<::ad::map::lane::LaneId >::max
static inline ::ad::map::lane::LaneId max()
Definition: LaneId.hpp:405
ad::map::lane::LaneId::operator==
bool operator==(const LaneId &other) const
standard comparison operator
Definition: LaneId.hpp:135
ad::map::lane::operator<<
std::ostream & operator<<(std::ostream &os, ContactLane const &_value)
standard ostream operator
Definition: ContactLane.hpp:182
ad::map::lane::LaneId::operator+
LaneId operator+(const LaneId &other) const
standard arithmetic operator
Definition: LaneId.hpp:228
ad::map::lane::LaneId::getMin
static LaneId getMin()
get minimum valid LaneId (i.e. cMinValue)
Definition: LaneId.hpp:356
ad::map::lane::LaneId::operator!=
bool operator!=(const LaneId &other) const
standard comparison operator
Definition: LaneId.hpp:149
ad::map::lane::LaneId::operator<
bool operator<(const LaneId &other) const
standard comparison operator
Definition: LaneId.hpp:179
ad::map::lane::LaneId::ensureValid
void ensureValid() const
ensure that the LaneId is valid
Definition: LaneId.hpp:324
ad::map::lane::LaneId::cMinValue
static const uint64_t cMinValue
constant defining the minimum valid LaneId value (used in isValid())
Definition: LaneId.hpp:72
std::numeric_limits<::ad::map::lane::LaneId >::epsilon
static inline ::ad::map::lane::LaneId epsilon()
Definition: LaneId.hpp:413
ad::map::lane::LaneId::LaneId
_AD_MAP_LANE_LANEID_EXPLICIT_CONVERSION_ LaneId(uint64_t const iLaneId)
standard constructor
Definition: LaneId.hpp:95
ad::map::lane::LaneId::operator<=
bool operator<=(const LaneId &other) const
standard comparison operator
Definition: LaneId.hpp:211
std::numeric_limits<::ad::map::lane::LaneId >::lowest
static inline ::ad::map::lane::LaneId lowest()
Definition: LaneId.hpp:398