#ifndef RANGEMATCHER_H_ #define RANGEMATCHER_H_ #include #include template class RangeMatcher: public SerializeableMatcherIF { 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) { return ~doMatch(input); } else { return doMatch(input); } } ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, const uint32_t max_size, bool bigEndian) const { ReturnValue_t result = SerializeAdapter::serialize(&lowerBound, buffer, size, max_size, bigEndian); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } result = SerializeAdapter::serialize(&upperBound, buffer, size, max_size, bigEndian); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } return SerializeAdapter::serialize(&inverted, buffer, size, max_size, bigEndian); } uint32_t getSerializedSize() const { return sizeof(lowerBound) + sizeof(upperBound) + sizeof(bool); } ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian) { ReturnValue_t result = SerializeAdapter::deSerialize(&lowerBound, buffer, size, bigEndian); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } result = SerializeAdapter::deSerialize(&upperBound, buffer, size, bigEndian); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } return SerializeAdapter::deSerialize(&inverted, buffer, size, bigEndian); } protected: bool doMatch(T input) { return (input >= lowerBound) && (input <= upperBound); } }; #endif /* RANGEMATCHER_H_ */