Line data Source code
1 : // Copyright 2024 Accenture. 2 : 3 : #include "can/filter/IntervalFilter.h" 4 : 5 : #include <estd/algorithm.h> 6 : 7 : #include <algorithm> 8 : 9 : namespace can 10 : { 11 52 : IntervalFilter::IntervalFilter() : _from(MAX_ID), _to(0U) {} 12 : 13 39 : IntervalFilter::IntervalFilter(uint32_t const from, uint32_t const to) : IntervalFilter() 14 : { 15 78 : IntervalFilter::add(from, to); 16 39 : } 17 : 18 : // virtual 19 6 : void IntervalFilter::add(uint32_t const filterId) { add(filterId, filterId); } 20 : 21 61 : void IntervalFilter::add(uint32_t from, uint32_t to) 22 : { 23 61 : if (from > MAX_ID) 24 : { 25 : from = MAX_ID; 26 : } 27 61 : if (to > MAX_ID) 28 : { 29 : to = MAX_ID; 30 : } 31 : // assert order 32 61 : if (from > to) 33 : { 34 1 : ::std::swap(from, to); 35 : } 36 : // adjust lower bound 37 61 : _from = ::estd::min(_from, from); 38 : // adjust upper bound 39 61 : _to = ::estd::max(_to, to); 40 22 : } 41 : 42 : // virtual 43 37138 : bool IntervalFilter::match(uint32_t const filterId) const 44 : { 45 37138 : return (filterId >= _from) && (filterId <= _to); 46 : } 47 : 48 11 : void IntervalFilter::clear() 49 : { 50 11 : _from = MAX_ID; 51 11 : _to = 0U; 52 11 : } 53 : 54 1 : void IntervalFilter::open() 55 : { 56 1 : _from = 0x00U; 57 1 : _to = MAX_ID; 58 1 : } 59 : 60 : } /*namespace can*/