/* Web Polygraph http://www.web-polygraph.org/ * (C) 2003-2006 The Measurement Factory * Licensed under the Apache License, Version 2.0 */ #ifndef POLYGRAPH__RUNTIME_MEASRANGE_H #define POLYGRAPH__RUNTIME_MEASRANGE_H // a [min, max] range of measurements or desired properties template class MeasRange { public: inline MeasRange(); inline bool known() const; inline bool contains(const Base &meas) const; inline void min(const Base &meas); inline void max(const Base &meas); inline ostream &print(ostream &os) const; protected: Base theMin; Base theMax; bool isMinSet; bool isMaxSet; }; template inline ostream &operator <<(ostream &os, const MeasRange &measRange) { return measRange.print(os); } template inline MeasRange::MeasRange(): isMinSet(false), isMaxSet(false) { } template inline bool MeasRange::known() const { return isMinSet || isMaxSet; } template inline bool MeasRange::contains(const Base &meas) const { return (!isMinSet || theMin <= meas) && (!isMaxSet || meas <= theMax); } template inline void MeasRange::min(const Base &meas) { theMin = meas; isMinSet = true; } template inline void MeasRange::max(const Base &meas) { theMax = meas; isMaxSet = true; } template inline ostream &MeasRange::print(ostream &os) const { if (isMinSet && isMaxSet) os << "from " << theMin << " to " << theMax; else if (isMinSet) os << "at least " << theMin; else if (isMaxSet) os << "at most " << theMax; else os << "any"; return os; } #endif