ad_map_access
LandmarkId.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 landmark {
42 
46 #define AD_MAP_LANDMARK_LANDMARKID_THROWS_EXCEPTION 1
47 
48 #if SAFE_DATATYPES_EXPLICIT_CONVERSION
49 
52 #define _AD_MAP_LANDMARK_LANDMARKID_EXPLICIT_CONVERSION_ explicit
53 #else
54 
57 #define _AD_MAP_LANDMARK_LANDMARKID_EXPLICIT_CONVERSION_
58 #endif
59 
67 {
68 public:
72  static const uint64_t cMinValue;
73 
77  static const uint64_t cMaxValue;
78 
86  : mLandmarkId(std::numeric_limits<uint64_t>::quiet_NaN())
87  {
88  }
89 
96  : mLandmarkId(iLandmarkId)
97  {
98  }
99 
103  LandmarkId(const LandmarkId &other) = default;
104 
108  LandmarkId(LandmarkId &&other) = default;
109 
117  LandmarkId &operator=(const LandmarkId &other) = default;
118 
126  LandmarkId &operator=(LandmarkId &&other) = default;
127 
135  bool operator==(const LandmarkId &other) const
136  {
137  ensureValid();
138  other.ensureValid();
139  return mLandmarkId == other.mLandmarkId;
140  }
141 
149  bool operator!=(const LandmarkId &other) const
150  {
151  return !operator==(other);
152  }
153 
163  bool operator>(const LandmarkId &other) const
164  {
165  ensureValid();
166  other.ensureValid();
167  return (mLandmarkId > other.mLandmarkId) && operator!=(other);
168  }
169 
179  bool operator<(const LandmarkId &other) const
180  {
181  ensureValid();
182  other.ensureValid();
183  return (mLandmarkId < other.mLandmarkId) && operator!=(other);
184  }
185 
195  bool operator>=(const LandmarkId &other) const
196  {
197  ensureValid();
198  other.ensureValid();
199  return ((mLandmarkId > other.mLandmarkId) || operator==(other));
200  }
201 
211  bool operator<=(const LandmarkId &other) const
212  {
213  ensureValid();
214  other.ensureValid();
215  return ((mLandmarkId < other.mLandmarkId) || operator==(other));
216  }
217 
228  LandmarkId operator+(const LandmarkId &other) const
229  {
230  ensureValid();
231  other.ensureValid();
232  LandmarkId const result(mLandmarkId + other.mLandmarkId);
233  result.ensureValid();
234  return result;
235  }
236 
248  {
249  ensureValid();
250  other.ensureValid();
251  mLandmarkId += other.mLandmarkId;
252  ensureValid();
253  return *this;
254  }
255 
266  LandmarkId operator-(const LandmarkId &other) const
267  {
268  ensureValid();
269  other.ensureValid();
270  LandmarkId const result(mLandmarkId - other.mLandmarkId);
271  result.ensureValid();
272  return result;
273  }
274 
286  {
287  ensureValid();
288  other.ensureValid();
289  mLandmarkId -= other.mLandmarkId;
290  ensureValid();
291  return *this;
292  }
293 
301  {
302  return mLandmarkId;
303  }
304 
312  bool isValid() const
313  {
314  auto const valueClass = std::fpclassify(mLandmarkId);
315  return ((valueClass == FP_NORMAL) || (valueClass == FP_ZERO)) && (cMinValue <= mLandmarkId)
316  && (mLandmarkId <= cMaxValue);
317  }
318 
325  void ensureValid() const
326  {
327  if (!isValid())
328  {
329  spdlog::info("ensureValid(::ad::map::landmark::LandmarkId)>> {} value out of range", *this); // LCOV_EXCL_BR_LINE
330 #if (AD_MAP_LANDMARK_LANDMARKID_THROWS_EXCEPTION == 1)
331  throw std::out_of_range("LandmarkId value out of range"); // LCOV_EXCL_BR_LINE
332 #endif
333  }
334  }
335 
342  void ensureValidNonZero() const
343  {
344  ensureValid();
345  if (operator==(LandmarkId(0))) // LCOV_EXCL_BR_LINE
346  {
347  spdlog::info("ensureValid(::ad::map::landmark::LandmarkId)>> {} value is zero", *this); // LCOV_EXCL_BR_LINE
348 #if (AD_MAP_LANDMARK_LANDMARKID_THROWS_EXCEPTION == 1)
349  throw std::out_of_range("LandmarkId value is zero"); // LCOV_EXCL_BR_LINE
350 #endif
351  }
352  }
353 
358  {
359  return LandmarkId(cMinValue);
360  }
361 
366  {
367  return LandmarkId(cMaxValue);
368  }
369 
370 private:
374  uint64_t mLandmarkId;
375 };
376 
377 } // namespace landmark
378 } // namespace map
379 } // namespace ad
383 namespace std {
384 
393 template <> class numeric_limits<::ad::map::landmark::LandmarkId> : public numeric_limits<uint64_t>
394 {
395 public:
399  static inline ::ad::map::landmark::LandmarkId lowest()
400  {
401  return ::ad::map::landmark::LandmarkId::getMin();
402  }
406  static inline ::ad::map::landmark::LandmarkId max()
407  {
408  return ::ad::map::landmark::LandmarkId::getMax();
409  }
410 
414  static inline ::ad::map::landmark::LandmarkId epsilon()
415  {
416  return ::ad::map::landmark::LandmarkId(0);
417  }
418 };
419 
420 } // namespace std
421 
425 #ifndef GEN_GUARD_AD_MAP_LANDMARK_LANDMARKID
426 #define GEN_GUARD_AD_MAP_LANDMARK_LANDMARKID
427 
430 namespace ad {
434 namespace map {
440 namespace landmark {
441 
451 inline std::ostream &operator<<(std::ostream &os, LandmarkId const &_value)
452 {
453  return os << uint64_t(_value);
454 }
455 
456 } // namespace landmark
457 } // namespace map
458 } // namespace ad
459 
460 namespace std {
464 inline std::string to_string(::ad::map::landmark::LandmarkId const &value)
465 {
466  return to_string(static_cast<uint64_t>(value));
467 }
468 } // namespace std
469 #endif // GEN_GUARD_AD_MAP_LANDMARK_LANDMARKID
ad
namespace ad
Definition: GeometryStoreItem.hpp:28
std::numeric_limits<::ad::map::landmark::LandmarkId >::max
static inline ::ad::map::landmark::LandmarkId max()
Definition: LandmarkId.hpp:406
ad::map::landmark::operator<<
std::ostream & operator<<(std::ostream &os, ENULandmark const &_value)
standard ostream operator
Definition: ENULandmark.hpp:179
ad::map::landmark::LandmarkId::operator<
bool operator<(const LandmarkId &other) const
standard comparison operator
Definition: LandmarkId.hpp:179
ad::map::landmark::LandmarkId::cMaxValue
static const uint64_t cMaxValue
constant defining the maximum valid LandmarkId value (used in isValid())
Definition: LandmarkId.hpp:77
ad::map::landmark::LandmarkId::operator+=
LandmarkId & operator+=(const LandmarkId &other)
standard arithmetic operator
Definition: LandmarkId.hpp:247
ad::map::landmark::LandmarkId::LandmarkId
_AD_MAP_LANDMARK_LANDMARKID_EXPLICIT_CONVERSION_ LandmarkId(uint64_t const iLandmarkId)
standard constructor
Definition: LandmarkId.hpp:95
ad::map::landmark::LandmarkId::operator>
bool operator>(const LandmarkId &other) const
standard comparison operator
Definition: LandmarkId.hpp:163
ad::map::landmark::LandmarkId::operator==
bool operator==(const LandmarkId &other) const
standard comparison operator
Definition: LandmarkId.hpp:135
ad::map::landmark::LandmarkId
DataType LandmarkId.
Definition: LandmarkId.hpp:66
ad::map::landmark::LandmarkId::LandmarkId
LandmarkId()
default constructor
Definition: LandmarkId.hpp:85
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
std::numeric_limits<::ad::map::landmark::LandmarkId >::epsilon
static inline ::ad::map::landmark::LandmarkId epsilon()
Definition: LandmarkId.hpp:414
ad::map::landmark::LandmarkId::operator=
LandmarkId & operator=(const LandmarkId &other)=default
standard assignment operator
ad::map::landmark::LandmarkId::isValid
bool isValid() const
Definition: LandmarkId.hpp:312
ad::map::landmark::LandmarkId::getMax
static LandmarkId getMax()
get maximum valid LandmarkId (i.e. cMaxValue)
Definition: LandmarkId.hpp:365
ad::map::landmark::LandmarkId::getMin
static LandmarkId getMin()
get minimum valid LandmarkId (i.e. cMinValue)
Definition: LandmarkId.hpp:357
ad::map::landmark::LandmarkId::operator>=
bool operator>=(const LandmarkId &other) const
standard comparison operator
Definition: LandmarkId.hpp:195
ad::map::landmark::LandmarkId::cMinValue
static const uint64_t cMinValue
constant defining the minimum valid LandmarkId value (used in isValid())
Definition: LandmarkId.hpp:72
ad::map::landmark::LandmarkId::operator+
LandmarkId operator+(const LandmarkId &other) const
standard arithmetic operator
Definition: LandmarkId.hpp:228
ad::map::landmark::LandmarkId::operator<=
bool operator<=(const LandmarkId &other) const
standard comparison operator
Definition: LandmarkId.hpp:211
_AD_MAP_LANDMARK_LANDMARKID_EXPLICIT_CONVERSION_
#define _AD_MAP_LANDMARK_LANDMARKID_EXPLICIT_CONVERSION_
Enable/Disable explicit conversion. Currently set to "implicit conversion allowed".
Definition: LandmarkId.hpp:57
ad::map::landmark::LandmarkId::operator-
LandmarkId operator-(const LandmarkId &other) const
standard arithmetic operator
Definition: LandmarkId.hpp:266
ad::map::landmark::LandmarkId::operator-=
LandmarkId operator-=(const LandmarkId &other)
standard arithmetic operator
Definition: LandmarkId.hpp:285
ad::map::landmark::LandmarkId::ensureValidNonZero
void ensureValidNonZero() const
ensure that the LandmarkId is valid and non zero
Definition: LandmarkId.hpp:342
ad::map::landmark::LandmarkId::operator!=
bool operator!=(const LandmarkId &other) const
standard comparison operator
Definition: LandmarkId.hpp:149
std::numeric_limits<::ad::map::landmark::LandmarkId >::lowest
static inline ::ad::map::landmark::LandmarkId lowest()
Definition: LandmarkId.hpp:399
ad::map::landmark::LandmarkId::ensureValid
void ensureValid() const
ensure that the LandmarkId is valid
Definition: LandmarkId.hpp:325