LCOV - code coverage report
Current view: top level - generated/include/ad/map/lane - LaneId.hpp (source / functions) Hit Total Coverage
Test: ad_map_access Lines: 75 78 96.2 %
Date: 2022-10-04 09:48:07 Functions: 21 21 100.0 %
Branches: 22 38 57.9 %

           Branch data     Line data    Source code
       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                 :            : 
      11                 :            : /**
      12                 :            :  * Generated file
      13                 :            :  * @file
      14                 :            :  *
      15                 :            :  * Generator Version : 11.0.0-1997
      16                 :            :  */
      17                 :            : 
      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"
      28                 :            : /*!
      29                 :            :  * @brief namespace ad
      30                 :            :  */
      31                 :            : namespace ad {
      32                 :            : /*!
      33                 :            :  * @brief namespace map
      34                 :            :  */
      35                 :            : namespace map {
      36                 :            : /*!
      37                 :            :  * @brief namespace lane
      38                 :            :  *
      39                 :            :  * Handling of lanes
      40                 :            :  */
      41                 :            : namespace lane {
      42                 :            : 
      43                 :            : /*!
      44                 :            :  * \brief Define to indicate whether throwing exceptions is enabled
      45                 :            :  */
      46                 :            : #define AD_MAP_LANE_LANEID_THROWS_EXCEPTION 1
      47                 :            : 
      48                 :            : #if SAFE_DATATYPES_EXPLICIT_CONVERSION
      49                 :            : /*!
      50                 :            :  * \brief Enable/Disable explicit conversion. Currently set to "only explicit conversion".
      51                 :            :  */
      52                 :            : #define _AD_MAP_LANE_LANEID_EXPLICIT_CONVERSION_ explicit
      53                 :            : #else
      54                 :            : /*!
      55                 :            :  * \brief Enable/Disable explicit conversion. Currently set to "implicit conversion allowed".
      56                 :            :  */
      57                 :            : #define _AD_MAP_LANE_LANEID_EXPLICIT_CONVERSION_
      58                 :            : #endif
      59                 :            : 
      60                 :            : /*!
      61                 :            :  * \brief DataType LaneId
      62                 :            :  *
      63                 :            :  * Defines the identifier of a lane of the map.
      64                 :            :  * The unit is: Identifier
      65                 :            :  */
      66                 :            : class LaneId
      67                 :            : {
      68                 :            : public:
      69                 :            :   /*!
      70                 :            :    * \brief constant defining the minimum valid LaneId value (used in isValid())
      71                 :            :    */
      72                 :            :   static const uint64_t cMinValue;
      73                 :            : 
      74                 :            :   /*!
      75                 :            :    * \brief constant defining the maximum valid LaneId value (used in isValid())
      76                 :            :    */
      77                 :            :   static const uint64_t cMaxValue;
      78                 :            : 
      79                 :            :   /*!
      80                 :            :    * \brief default constructor
      81                 :            :    *
      82                 :            :    * The default value of LaneId is:
      83                 :            :    * std::numeric_limits<uint64_t>::quiet_NaN()
      84                 :            :    */
      85                 :     101186 :   LaneId()
      86                 :     101186 :     : mLaneId(std::numeric_limits<uint64_t>::quiet_NaN())
      87                 :            :   {
      88                 :     101186 :   }
      89                 :            : 
      90                 :            :   /*!
      91                 :            :    * \brief standard constructor
      92                 :            :    *
      93                 :            :    * \note \ref \_AD_MAP_LANE_LANEID_EXPLICIT_CONVERSION\_ defines, if only an explicit conversion is allowed.
      94                 :            :    */
      95                 :    1974510 :   _AD_MAP_LANE_LANEID_EXPLICIT_CONVERSION_ LaneId(uint64_t const iLaneId)
      96                 :    1974510 :     : mLaneId(iLaneId)
      97                 :            :   {
      98                 :    1974510 :   }
      99                 :            : 
     100                 :            :   /*!
     101                 :            :    * \brief standard copy constructor
     102                 :            :    */
     103                 :            :   LaneId(const LaneId &other) = default;
     104                 :            : 
     105                 :            :   /*!
     106                 :            :    * \brief standard move constructor
     107                 :            :    */
     108                 :            :   LaneId(LaneId &&other) = default;
     109                 :            : 
     110                 :            :   /**
     111                 :            :    * \brief standard assignment operator
     112                 :            :    *
     113                 :            :    * \param[in] other Other LaneId
     114                 :            :    *
     115                 :            :    * \returns Reference to this LaneId.
     116                 :            :    */
     117                 :            :   LaneId &operator=(const LaneId &other) = default;
     118                 :            : 
     119                 :            :   /**
     120                 :            :    * \brief standard move operator
     121                 :            :    *
     122                 :            :    * \param[in] other Other LaneId
     123                 :            :    *
     124                 :            :    * \returns Reference to this LaneId.
     125                 :            :    */
     126                 :            :   LaneId &operator=(LaneId &&other) = default;
     127                 :            : 
     128                 :            :   /**
     129                 :            :    * \brief standard comparison operator
     130                 :            :    *
     131                 :            :    * \param[in] other Other LaneId
     132                 :            :    *
     133                 :            :    * \returns \c true if both LaneId are valid and can be taken as numerically equal
     134                 :            :    */
     135                 :    6231412 :   bool operator==(const LaneId &other) const
     136                 :            :   {
     137                 :    6231412 :     ensureValid();
     138                 :    6231412 :     other.ensureValid();
     139                 :    6231412 :     return mLaneId == other.mLaneId;
     140                 :            :   }
     141                 :            : 
     142                 :            :   /**
     143                 :            :    * \brief standard comparison operator
     144                 :            :    *
     145                 :            :    * \param[in] other Other LaneId.
     146                 :            :    *
     147                 :            :    * \returns \c true if one of the LaneId is not valid or they can be taken as numerically different
     148                 :            :    */
     149                 :    5350573 :   bool operator!=(const LaneId &other) const
     150                 :            :   {
     151                 :    5350573 :     return !operator==(other);
     152                 :            :   }
     153                 :            : 
     154                 :            :   /**
     155                 :            :    * \brief standard comparison operator
     156                 :            :    *
     157                 :            :    * \param[in] other Other LaneId.
     158                 :            :    *
     159                 :            :    * \returns \c true if both LaneId are valid and
     160                 :            :    *   this LaneId is strictly numerically greater than other.
     161                 :            :    * \note the precision of LaneId is considered
     162                 :            :    */
     163                 :          1 :   bool operator>(const LaneId &other) const
     164                 :            :   {
     165                 :          1 :     ensureValid();
     166                 :          1 :     other.ensureValid();
     167   [ +  -  +  - ]:          1 :     return (mLaneId > other.mLaneId) && operator!=(other);
     168                 :            :   }
     169                 :            : 
     170                 :            :   /**
     171                 :            :    * \brief standard comparison operator
     172                 :            :    *
     173                 :            :    * \param[in] other Other LaneId.
     174                 :            :    *
     175                 :            :    * \returns \c true if both LaneId are valid and
     176                 :            :    *   this LaneId is strictly numerically smaller than other.
     177                 :            :    * \note the precision of LaneId is considered
     178                 :            :    */
     179                 :   12788501 :   bool operator<(const LaneId &other) const
     180                 :            :   {
     181                 :   12788501 :     ensureValid();
     182                 :   12788501 :     other.ensureValid();
     183   [ +  +  +  - ]:   12788501 :     return (mLaneId < other.mLaneId) && operator!=(other);
     184                 :            :   }
     185                 :            : 
     186                 :            :   /**
     187                 :            :    * \brief standard comparison operator
     188                 :            :    *
     189                 :            :    * \param[in] other Other LaneId.
     190                 :            :    *
     191                 :            :    * \returns \c true if both LaneId are valid and
     192                 :            :    *   this LaneId is numerically greater than other.
     193                 :            :    * \note the precision of LaneId is considered
     194                 :            :    */
     195                 :          1 :   bool operator>=(const LaneId &other) const
     196                 :            :   {
     197                 :          1 :     ensureValid();
     198                 :          1 :     other.ensureValid();
     199   [ -  +  -  - ]:          1 :     return ((mLaneId > other.mLaneId) || operator==(other));
     200                 :            :   }
     201                 :            : 
     202                 :            :   /**
     203                 :            :    * \brief standard comparison operator
     204                 :            :    *
     205                 :            :    * \param[in] other Other LaneId
     206                 :            :    *
     207                 :            :    * \returns \c true if both LaneId are valid and
     208                 :            :    *   this LaneId is numerically smaller than other.
     209                 :            :    * \note the precision of LaneId is considered
     210                 :            :    */
     211                 :      97573 :   bool operator<=(const LaneId &other) const
     212                 :            :   {
     213                 :      97573 :     ensureValid();
     214                 :      97573 :     other.ensureValid();
     215   [ +  +  +  + ]:      97573 :     return ((mLaneId < other.mLaneId) || operator==(other));
     216                 :            :   }
     217                 :            : 
     218                 :            :   /**
     219                 :            :    * \brief standard arithmetic operator
     220                 :            :    *
     221                 :            :    * \param[in] other Other LaneId
     222                 :            :    *
     223                 :            :    * \returns Result of arithmetic operation.
     224                 :            :    *
     225                 :            :    * \note throws a std::out_of_range exception if one of the two operands or the result of
     226                 :            :    *   the operation is not valid
     227                 :            :    */
     228                 :          9 :   LaneId operator+(const LaneId &other) const
     229                 :            :   {
     230         [ +  - ]:          9 :     ensureValid();
     231         [ +  - ]:          9 :     other.ensureValid();
     232                 :          9 :     LaneId const result(mLaneId + other.mLaneId);
     233         [ +  - ]:          9 :     result.ensureValid();
     234                 :          9 :     return result;
     235                 :            :   }
     236                 :            : 
     237                 :            :   /**
     238                 :            :    * \brief standard arithmetic operator
     239                 :            :    *
     240                 :            :    * \param[in] other Other LaneId
     241                 :            :    *
     242                 :            :    * \returns Result of arithmetic operation.
     243                 :            :    *
     244                 :            :    * \note throws a std::out_of_range exception if one of the two operands or the result of
     245                 :            :    *   the operation is not valid
     246                 :            :    */
     247                 :          8 :   LaneId &operator+=(const LaneId &other)
     248                 :            :   {
     249                 :          8 :     ensureValid();
     250                 :          8 :     other.ensureValid();
     251                 :          8 :     mLaneId += other.mLaneId;
     252                 :          8 :     ensureValid();
     253                 :          8 :     return *this;
     254                 :            :   }
     255                 :            : 
     256                 :            :   /**
     257                 :            :    * \brief standard arithmetic operator
     258                 :            :    *
     259                 :            :    * \param[in] other Other LaneId
     260                 :            :    *
     261                 :            :    * \returns Result of arithmetic operation.
     262                 :            :    *
     263                 :            :    * \note throws a std::out_of_range exception if one of the two operands or the result of
     264                 :            :    *   the operation is not valid
     265                 :            :    */
     266                 :          1 :   LaneId operator-(const LaneId &other) const
     267                 :            :   {
     268         [ +  - ]:          1 :     ensureValid();
     269         [ +  - ]:          1 :     other.ensureValid();
     270                 :          1 :     LaneId const result(mLaneId - other.mLaneId);
     271         [ +  - ]:          1 :     result.ensureValid();
     272                 :          1 :     return result;
     273                 :            :   }
     274                 :            : 
     275                 :            :   /**
     276                 :            :    * \brief standard arithmetic operator
     277                 :            :    *
     278                 :            :    * \param[in] other Other LaneId
     279                 :            :    *
     280                 :            :    * \returns Result of arithmetic operation.
     281                 :            :    *
     282                 :            :    * \note throws a std::out_of_range exception if one of the two operands or the result of
     283                 :            :    *   the operation is not valid
     284                 :            :    */
     285                 :          1 :   LaneId operator-=(const LaneId &other)
     286                 :            :   {
     287                 :          1 :     ensureValid();
     288                 :          1 :     other.ensureValid();
     289                 :          1 :     mLaneId -= other.mLaneId;
     290                 :          1 :     ensureValid();
     291                 :          1 :     return *this;
     292                 :            :   }
     293                 :            : 
     294                 :            :   /*!
     295                 :            :    * \brief conversion to base type: uint64_t
     296                 :            :    *
     297                 :            :    * \note the conversion to the base type removes the physical unit.
     298                 :            :    *       \ref \_AD_MAP_LANE_LANEID_EXPLICIT_CONVERSION\_ defines, if only explicit calls are allowed.
     299                 :            :    */
     300                 :       8918 :   _AD_MAP_LANE_LANEID_EXPLICIT_CONVERSION_ operator uint64_t() const
     301                 :            :   {
     302                 :       8918 :     return mLaneId;
     303                 :            :   }
     304                 :            : 
     305                 :            :   /*!
     306                 :            :    * \returns \c true if the LaneId in a valid range
     307                 :            :    *
     308                 :            :    * An LaneId value is defined to be valid if:
     309                 :            :    * - It is normal or zero (see std::fpclassify())
     310                 :            :    * - \ref cMinValue <= value <= \ref cMaxValue
     311                 :            :    */
     312                 :   38267520 :   bool isValid() const
     313                 :            :   {
     314                 :   38267520 :     auto const valueClass = std::fpclassify(mLaneId);
     315   [ +  +  +  -  :   38267520 :     return ((valueClass == FP_NORMAL) || (valueClass == FP_ZERO)) && (cMinValue <= mLaneId) && (mLaneId <= cMaxValue);
             +  -  +  - ]
     316                 :            :   }
     317                 :            : 
     318                 :            :   /*!
     319                 :            :    * \brief ensure that the LaneId is valid
     320                 :            :    *
     321                 :            :    * Throws an std::out_of_range() exception if the LaneId
     322                 :            :    * in not valid (i.e. isValid() returns false)
     323                 :            :    */
     324                 :   38234938 :   void ensureValid() const
     325                 :            :   {
     326         [ -  + ]:   38234938 :     if (!isValid())
     327                 :            :     {
     328                 :          0 :       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                 :          0 :       throw std::out_of_range("LaneId value out of range"); // LCOV_EXCL_BR_LINE
     331                 :            : #endif
     332                 :            :     }
     333                 :   38234938 :   }
     334                 :            : 
     335                 :            :   /*!
     336                 :            :    * \brief ensure that the LaneId is valid and non zero
     337                 :            :    *
     338                 :            :    * Throws an std::out_of_range() exception if the LaneId
     339                 :            :    * in not valid or zero (i.e. isValid() returns false)
     340                 :            :    */
     341                 :          2 :   void ensureValidNonZero() const
     342                 :            :   {
     343                 :          2 :     ensureValid();
     344                 :          2 :     if (operator==(LaneId(0))) // LCOV_EXCL_BR_LINE
     345                 :            :     {
     346                 :          2 :       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                 :          2 :       throw std::out_of_range("LaneId value is zero"); // LCOV_EXCL_BR_LINE
     349                 :            : #endif
     350                 :            :     }
     351                 :          0 :   }
     352                 :            : 
     353                 :            :   /*!
     354                 :            :    * \brief get minimum valid LaneId (i.e. \ref cMinValue)
     355                 :            :    */
     356                 :      32527 :   static LaneId getMin()
     357                 :            :   {
     358                 :      32527 :     return LaneId(cMinValue);
     359                 :            :   }
     360                 :            : 
     361                 :            :   /*!
     362                 :            :    * \brief get maximum valid LaneId (i.e. \ref cMaxValue)
     363                 :            :    */
     364                 :      32564 :   static LaneId getMax()
     365                 :            :   {
     366                 :      32564 :     return LaneId(cMaxValue);
     367                 :            :   }
     368                 :            : 
     369                 :            : private:
     370                 :            :   /*!
     371                 :            :    * \brief the actual value of the type
     372                 :            :    */
     373                 :            :   uint64_t mLaneId;
     374                 :            : };
     375                 :            : 
     376                 :            : } // namespace lane
     377                 :            : } // namespace map
     378                 :            : } // namespace ad
     379                 :            : /*!
     380                 :            :  * \brief namespace std
     381                 :            :  */
     382                 :            : namespace std {
     383                 :            : 
     384                 :            : /*!
     385                 :            :  * \brief specialization of the std::numeric_limits for LaneId
     386                 :            :  *
     387                 :            :  * Derived from std::numeric_limits<uint64_t> with overloaded functions:
     388                 :            :  * std::numeric_limits<LaneId>::lowest()  (\see LaneId::getMin())
     389                 :            :  * std::numeric_limits<LaneId>::max()  (\see LaneId::getMax())
     390                 :            :  * std::numeric_limits<LaneId>::epsilon()  (\see LaneId::getPrecision())
     391                 :            :  */
     392                 :            : template <> class numeric_limits<::ad::map::lane::LaneId> : public numeric_limits<uint64_t>
     393                 :            : {
     394                 :            : public:
     395                 :            :   /*!
     396                 :            :    * \see std::numeric_limits::lowest()
     397                 :            :    */
     398                 :      32525 :   static inline ::ad::map::lane::LaneId lowest()
     399                 :            :   {
     400                 :      32525 :     return ::ad::map::lane::LaneId::getMin();
     401                 :            :   }
     402                 :            :   /*!
     403                 :            :    * \see std::numeric_limits::max()
     404                 :            :    */
     405                 :      32562 :   static inline ::ad::map::lane::LaneId max()
     406                 :            :   {
     407                 :      32562 :     return ::ad::map::lane::LaneId::getMax();
     408                 :            :   }
     409                 :            : 
     410                 :            :   /*!
     411                 :            :    * \see std::numeric_limits::epsilon()
     412                 :            :    */
     413                 :            :   static inline ::ad::map::lane::LaneId epsilon()
     414                 :            :   {
     415                 :            :     return ::ad::map::lane::LaneId(0);
     416                 :            :   }
     417                 :            : };
     418                 :            : 
     419                 :            : } // namespace std
     420                 :            : 
     421                 :            : /*!
     422                 :            :  * \brief protect the definition of functions from duplicates by typedef usage within other data types
     423                 :            :  */
     424                 :            : #ifndef GEN_GUARD_AD_MAP_LANE_LANEID
     425                 :            : #define GEN_GUARD_AD_MAP_LANE_LANEID
     426                 :            : /*!
     427                 :            :  * @brief namespace ad
     428                 :            :  */
     429                 :            : namespace ad {
     430                 :            : /*!
     431                 :            :  * @brief namespace map
     432                 :            :  */
     433                 :            : namespace map {
     434                 :            : /*!
     435                 :            :  * @brief namespace lane
     436                 :            :  *
     437                 :            :  * Handling of lanes
     438                 :            :  */
     439                 :            : namespace lane {
     440                 :            : 
     441                 :            : /**
     442                 :            :  * \brief standard ostream operator
     443                 :            :  *
     444                 :            :  * \param[in] os The output stream to write to
     445                 :            :  * \param[in] _value LaneId value
     446                 :            :  *
     447                 :            :  * \returns The stream object.
     448                 :            :  *
     449                 :            :  */
     450                 :        389 : inline std::ostream &operator<<(std::ostream &os, LaneId const &_value)
     451                 :            : {
     452                 :        389 :   return os << uint64_t(_value);
     453                 :            : }
     454                 :            : 
     455                 :            : } // namespace lane
     456                 :            : } // namespace map
     457                 :            : } // namespace ad
     458                 :            : 
     459                 :            : namespace std {
     460                 :            : /*!
     461                 :            :  * \brief overload of the std::to_string for LaneId
     462                 :            :  */
     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

Generated by: LCOV version 1.14