LCOV - code coverage report
Current view: top level - docan/include/docan/datalink - DoCanDataLinkAddressPair.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 17 17 100.0 %
Date: 2025-01-20 13:53:09 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2024 Accenture.
       2             : 
       3             : #ifndef GUARD_E5BDAACC_712F_4A89_9D5B_C3C2E72CE454
       4             : #define GUARD_E5BDAACC_712F_4A89_9D5B_C3C2E72CE454
       5             : 
       6             : #include <platform/estdint.h>
       7             : 
       8             : namespace docan
       9             : {
      10             : /**
      11             :  * helper class to store a pair of addresses. An address pair is valid if
      12             :  * at least one of the addresses is not invalid.
      13             :  * \tparam T address type
      14             :  */
      15             : template<class T>
      16             : class DoCanDataLinkAddressPair
      17             : {
      18             : public:
      19             :     using AddressType = T;
      20             : 
      21             :     DoCanDataLinkAddressPair();
      22             :     DoCanDataLinkAddressPair(AddressType receptionAddress, AddressType targetAddress);
      23             :     DoCanDataLinkAddressPair(DoCanDataLinkAddressPair const& other);
      24             : 
      25             :     bool isValid() const;
      26             : 
      27             :     AddressType getReceptionAddress() const;
      28             :     AddressType getTransmissionAddress() const;
      29             : 
      30             :     bool operator==(DoCanDataLinkAddressPair const& other) const;
      31             :     DoCanDataLinkAddressPair& operator=(DoCanDataLinkAddressPair const& other);
      32             : 
      33             : private:
      34             :     AddressType _receptionAddress;
      35             :     AddressType _transmissionAddress;
      36             : };
      37             : 
      38             : /**
      39             :  * Inline implementations.
      40             :  */
      41             : template<class T>
      42          56 : inline DoCanDataLinkAddressPair<T>::DoCanDataLinkAddressPair() : DoCanDataLinkAddressPair(0, 0)
      43             : {}
      44             : 
      45             : template<class T>
      46         217 : inline DoCanDataLinkAddressPair<T>::DoCanDataLinkAddressPair(
      47             :     AddressType const receptionAddress, AddressType const targetAddress)
      48         120 : : _receptionAddress(receptionAddress), _transmissionAddress(targetAddress)
      49             : {}
      50             : 
      51             : template<class T>
      52         324 : inline DoCanDataLinkAddressPair<T>::DoCanDataLinkAddressPair(DoCanDataLinkAddressPair const& other)
      53         324 : : _receptionAddress(other.getReceptionAddress())
      54         324 : , _transmissionAddress(other.getTransmissionAddress())
      55             : {}
      56             : 
      57             : template<class T>
      58             : inline bool DoCanDataLinkAddressPair<T>::isValid() const
      59             : {
      60             :     return _receptionAddress != _transmissionAddress;
      61             : }
      62             : 
      63             : template<class T>
      64             : inline typename DoCanDataLinkAddressPair<T>::AddressType
      65        2344 : DoCanDataLinkAddressPair<T>::getReceptionAddress() const
      66             : {
      67        1976 :     return _receptionAddress;
      68             : }
      69             : 
      70             : template<class T>
      71             : inline typename DoCanDataLinkAddressPair<T>::AddressType
      72         115 : DoCanDataLinkAddressPair<T>::getTransmissionAddress() const
      73             : {
      74         110 :     return _transmissionAddress;
      75             : }
      76             : 
      77             : template<class T>
      78          31 : inline bool DoCanDataLinkAddressPair<T>::operator==(DoCanDataLinkAddressPair const& other) const
      79             : {
      80          31 :     return (_receptionAddress == other._receptionAddress)
      81          31 :            && (_transmissionAddress == other._transmissionAddress);
      82             : }
      83             : 
      84             : template<class T>
      85             : inline DoCanDataLinkAddressPair<T>&
      86          73 : DoCanDataLinkAddressPair<T>::operator=(DoCanDataLinkAddressPair const& other)
      87             : {
      88          43 :     if (&other != this)
      89             :     {
      90          73 :         _receptionAddress    = other._receptionAddress;
      91          73 :         _transmissionAddress = other._transmissionAddress;
      92             :     }
      93             :     return *this;
      94             : }
      95             : } // namespace docan
      96             : 
      97             : #endif // GUARD_E5BDAACC_712F_4A89_9D5B_C3C2E72CE454

Generated by: LCOV version 1.14