| [a80f419] | 1 | /* | 
|---|
|  | 2 | * Range.hpp | 
|---|
|  | 3 | * | 
|---|
|  | 4 | *  Created on: Jul 22, 2010 | 
|---|
|  | 5 | *      Author: crueger | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #ifndef RANGE_HPP_ | 
|---|
|  | 9 | #define RANGE_HPP_ | 
|---|
| [70672e3] | 10 |  | 
|---|
|  | 11 | // include config.h | 
|---|
|  | 12 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 13 | #include <config.h> | 
|---|
|  | 14 | #endif | 
|---|
|  | 15 |  | 
|---|
| [9c643e] | 16 | #include <iosfwd> | 
|---|
|  | 17 |  | 
|---|
| [a80f419] | 18 | template <class T> | 
|---|
|  | 19 | struct range { | 
|---|
|  | 20 | range(const T&,const T&); | 
|---|
|  | 21 | bool isInRange(const T&) const; | 
|---|
|  | 22 | bool isBefore(const T&) const; | 
|---|
|  | 23 | bool isBeyond(const T&) const; | 
|---|
|  | 24 |  | 
|---|
|  | 25 | T first; | 
|---|
|  | 26 | T last; | 
|---|
|  | 27 | }; | 
|---|
|  | 28 |  | 
|---|
|  | 29 | template <class T> | 
|---|
|  | 30 | inline range<T>::range(const T &_first,const T &_last) : | 
|---|
|  | 31 | first(_first),last(_last) | 
|---|
|  | 32 | {} | 
|---|
|  | 33 |  | 
|---|
|  | 34 | template <class T> | 
|---|
|  | 35 | inline bool range<T>::isInRange(const T &value) const{ | 
|---|
|  | 36 | return first <= value && value < last; | 
|---|
|  | 37 | } | 
|---|
|  | 38 |  | 
|---|
|  | 39 | template <class T> | 
|---|
|  | 40 | inline bool range<T>::isBefore(const T &value) const{ | 
|---|
|  | 41 | return value < first; | 
|---|
|  | 42 | } | 
|---|
|  | 43 |  | 
|---|
|  | 44 | template <class T> | 
|---|
|  | 45 | inline bool range<T>::isBeyond(const T &value) const{ | 
|---|
|  | 46 | return last <= value; | 
|---|
|  | 47 | } | 
|---|
|  | 48 |  | 
|---|
|  | 49 | template <class T> | 
|---|
|  | 50 | inline range<T> makeRange(const T&first, const T&last){ | 
|---|
|  | 51 | return range<T>(first,last); | 
|---|
|  | 52 | } | 
|---|
|  | 53 |  | 
|---|
|  | 54 | template <class T> | 
|---|
|  | 55 | inline bool operator<(const range <T> &x, const range<T> &y){ | 
|---|
|  | 56 | return (x.first!=y.first)?x.first<y.first:x.last<y.last; | 
|---|
|  | 57 | } | 
|---|
|  | 58 |  | 
|---|
|  | 59 | template <class T> | 
|---|
|  | 60 | inline bool operator==(const range<T> &x,const range<T> &y){ | 
|---|
|  | 61 | return x.first==y.first && x.last==y.last; | 
|---|
|  | 62 | } | 
|---|
|  | 63 |  | 
|---|
|  | 64 | template <class T> | 
|---|
|  | 65 | inline bool operator!= (const range<T>& x, const range<T>& y) { return !(x==y); } | 
|---|
|  | 66 | template <class T> | 
|---|
|  | 67 | inline bool operator>  (const range<T>& x, const range<T>& y) { return y<x; } | 
|---|
|  | 68 | template <class T> | 
|---|
|  | 69 | inline bool operator<=(const range<T>& x, const range<T>& y) { return !(y<x); } | 
|---|
|  | 70 | template <class T> | 
|---|
|  | 71 | inline bool operator>= (const range<T>& x, const range<T>& y) { return !(x<y); } | 
|---|
| [6b898c] | 72 | template <class T> | 
|---|
|  | 73 | std::ostream &operator<< (std::ostream &ost, const range<T>& y) | 
|---|
|  | 74 | { | 
|---|
|  | 75 | ost << "[" << y.first << ";" << y.last << "]"; | 
|---|
|  | 76 | return ost; | 
|---|
|  | 77 | } | 
|---|
| [a80f419] | 78 |  | 
|---|
|  | 79 | #endif /* RANGE_HPP_ */ | 
|---|