LCOV - code coverage report
Current view: top level - cpp2can/include/can/filter - AbstractStaticBitFieldFilter.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 6 13 46.2 %
Date: 2025-04-15 08:32:23 Functions: 2 6 33.3 %

          Line data    Source code
       1             : // Copyright 2024 Accenture.
       2             : 
       3             : /**
       4             :  * Contains AbstractStaticBitFieldFilter class.
       5             :  * \file AbstractStaticBitFieldFilter.h
       6             :  * \ingroup filter
       7             :  */
       8             : #pragma once
       9             : 
      10             : #include "can/canframes/CANFrame.h"
      11             : #include "can/filter/IFilter.h"
      12             : #include "can/filter/IMerger.h"
      13             : 
      14             : #include <estd/assert.h>
      15             : #include <platform/estdint.h>
      16             : 
      17             : #include <cstring>
      18             : 
      19             : namespace can
      20             : {
      21             : /**
      22             :  * Cpp2CAN AbstractStaticBitFieldFilter
      23             :  *
      24             :  *
      25             :  * A StaticBitFieldFilter allows to filter an id range
      26             :  * on CAN (0 - MAX_ID) and has a constant bitfield.
      27             :  */
      28             : class AbstractStaticBitFieldFilter : public IFilter
      29             : {
      30             : public:
      31             :     /** maximum id storable in this filter */
      32             :     static uint16_t const MAX_ID         = static_cast<uint16_t>(CANFrame::MAX_FRAME_ID);
      33             :     /** number of bits occupied by this filter */
      34             :     static uint16_t const NUMBER_OF_BITS = MAX_ID + 1U;
      35             :     /** size (in byte) of filters bitmask */
      36             :     static uint16_t const MASK_SIZE      = NUMBER_OF_BITS / 8U;
      37             : 
      38             :     /**
      39             :      * default constructor
      40             :      */
      41           4 :     AbstractStaticBitFieldFilter() : IFilter() {}
      42             : 
      43             :     /**
      44             :      * \see IFilter::add()
      45             :      */
      46           0 :     void add(uint32_t) override
      47             :     {
      48             :         // not applicable with a static filter
      49           0 :     }
      50             : 
      51             :     /**
      52             :      * \see IFilter::add()
      53             :      */
      54           0 :     void add(uint32_t, uint32_t) override
      55             :     {
      56             :         // not applicable with a static filter
      57           0 :     }
      58             : 
      59             :     /**
      60             :      * \see IFilter::match()
      61             :      * \param filterId        id to check
      62             :      * \return *             - true if internal mask matches filterId
      63             :      *             - false else
      64             :      */
      65             :     bool match(uint32_t filterId) const override;
      66             : 
      67             :     /**
      68             :      * \see IFilter::clear()
      69             :      */
      70           0 :     void clear() override
      71             :     {
      72             :         // not applicable with a static filter
      73           0 :     }
      74             : 
      75             :     /**
      76             :      * \see IFilter::open()
      77             :      */
      78           1 :     void open() override
      79             :     {
      80             :         // not applicable with a static filter
      81           0 :     }
      82             : 
      83             :     /**
      84             :      * \see IFilter::acceptMerger()
      85             :      */
      86           1 :     void acceptMerger(IMerger& merger) override { merger.mergeWithStaticBitField(*this); }
      87             : 
      88             :     /**
      89             :      * Get the byte at position byteIndex from the filter mask
      90             :      * \param byteIndex index of byte to retreive
      91             :      */
      92             :     virtual uint8_t getMaskValue(uint16_t byteIndex) const = 0;
      93             : 
      94             : private:
      95             :     // friends
      96             :     friend bool
      97             :     operator==(AbstractStaticBitFieldFilter const& x, AbstractStaticBitFieldFilter const& y);
      98             :     // no copies
      99             :     AbstractStaticBitFieldFilter(AbstractStaticBitFieldFilter const&);
     100             :     AbstractStaticBitFieldFilter& operator=(AbstractStaticBitFieldFilter const&);
     101             : };
     102             : 
     103             : /**
     104             :  * compares two AbstractStaticBitFieldFilter objects
     105             :  * \param x    first operand of comparison
     106             :  * \param y    second operand of comparison
     107             :  * \return *             - true: both filters are equal
     108             :  *             - false: filters are not equal
     109             :  */
     110           2 : inline bool operator==(AbstractStaticBitFieldFilter const& x, AbstractStaticBitFieldFilter const& y)
     111             : {
     112         258 :     for (uint16_t i = 0U; i < AbstractStaticBitFieldFilter::MASK_SIZE; ++i)
     113             :     {
     114         257 :         if (x.getMaskValue(i) != y.getMaskValue(i))
     115             :         {
     116             :             return false;
     117             :         }
     118             :     }
     119             :     return true;
     120             : }
     121             : 
     122             : } // namespace can

Generated by: LCOV version 1.14