2016-06-15 23:48:41 +02:00
|
|
|
#ifndef RANGEMATCHER_H_
|
|
|
|
#define RANGEMATCHER_H_
|
|
|
|
|
|
|
|
#include <framework/globalfunctions/matching/SerializeableMatcherIF.h>
|
|
|
|
#include <framework/serialize/SerializeAdapter.h>
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class RangeMatcher: public SerializeableMatcherIF<T> {
|
|
|
|
public:
|
|
|
|
bool inverted;
|
|
|
|
T lowerBound;
|
|
|
|
T upperBound;
|
|
|
|
|
|
|
|
RangeMatcher() :
|
|
|
|
inverted(true), lowerBound(1), upperBound(0) {
|
|
|
|
}
|
|
|
|
RangeMatcher(T lowerBound, T upperBound, bool inverted = false) :
|
|
|
|
inverted(inverted), lowerBound(lowerBound), upperBound(upperBound) {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool match(T input) {
|
|
|
|
if (inverted) {
|
2018-07-12 16:29:32 +02:00
|
|
|
return !doMatch(input);
|
2016-06-15 23:48:41 +02:00
|
|
|
} else {
|
|
|
|
return doMatch(input);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 17:58:39 +02:00
|
|
|
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
|
|
|
const size_t max_size, bool bigEndian) const {
|
2016-06-15 23:48:41 +02:00
|
|
|
ReturnValue_t result = SerializeAdapter<T>::serialize(&lowerBound, buffer, size, max_size, bigEndian);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = SerializeAdapter<T>::serialize(&upperBound, buffer, size, max_size, bigEndian);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return SerializeAdapter<bool>::serialize(&inverted, buffer, size, max_size, bigEndian);
|
|
|
|
}
|
|
|
|
|
2020-04-05 21:54:11 +02:00
|
|
|
size_t getSerializedSize() const {
|
2016-06-15 23:48:41 +02:00
|
|
|
return sizeof(lowerBound) + sizeof(upperBound) + sizeof(bool);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size,
|
|
|
|
bool bigEndian) {
|
|
|
|
ReturnValue_t result = SerializeAdapter<T>::deSerialize(&lowerBound, buffer, size, bigEndian);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = SerializeAdapter<T>::deSerialize(&upperBound, buffer, size, bigEndian);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return SerializeAdapter<bool>::deSerialize(&inverted, buffer, size, bigEndian);
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
bool doMatch(T input) {
|
|
|
|
return (input >= lowerBound) && (input <= upperBound);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* RANGEMATCHER_H_ */
|