| [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 | 
 | 
|---|
| [a80f419] | 16 | template <class T>
 | 
|---|
 | 17 | struct range {
 | 
|---|
 | 18 |   range(const T&,const T&);
 | 
|---|
 | 19 |   bool isInRange(const T&) const;
 | 
|---|
 | 20 |   bool isBefore(const T&) const;
 | 
|---|
 | 21 |   bool isBeyond(const T&) const;
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 |   T first;
 | 
|---|
 | 24 |   T last;
 | 
|---|
 | 25 | };
 | 
|---|
 | 26 | 
 | 
|---|
 | 27 | template <class T>
 | 
|---|
 | 28 | inline range<T>::range(const T &_first,const T &_last) :
 | 
|---|
 | 29 | first(_first),last(_last)
 | 
|---|
 | 30 | {}
 | 
|---|
 | 31 | 
 | 
|---|
 | 32 | template <class T>
 | 
|---|
 | 33 | inline bool range<T>::isInRange(const T &value) const{
 | 
|---|
 | 34 |   return first <= value && value < last;
 | 
|---|
 | 35 | }
 | 
|---|
 | 36 | 
 | 
|---|
 | 37 | template <class T>
 | 
|---|
 | 38 | inline bool range<T>::isBefore(const T &value) const{
 | 
|---|
 | 39 |   return value < first;
 | 
|---|
 | 40 | }
 | 
|---|
 | 41 | 
 | 
|---|
 | 42 | template <class T>
 | 
|---|
 | 43 | inline bool range<T>::isBeyond(const T &value) const{
 | 
|---|
 | 44 |  return last <= value;
 | 
|---|
 | 45 | }
 | 
|---|
 | 46 | 
 | 
|---|
 | 47 | template <class T>
 | 
|---|
 | 48 | inline range<T> makeRange(const T&first, const T&last){
 | 
|---|
 | 49 |   return range<T>(first,last);
 | 
|---|
 | 50 | }
 | 
|---|
 | 51 | 
 | 
|---|
 | 52 | template <class T>
 | 
|---|
 | 53 | inline bool operator<(const range <T> &x, const range<T> &y){
 | 
|---|
 | 54 |   return (x.first!=y.first)?x.first<y.first:x.last<y.last;
 | 
|---|
 | 55 | }
 | 
|---|
 | 56 | 
 | 
|---|
 | 57 | template <class T>
 | 
|---|
 | 58 | inline bool operator==(const range<T> &x,const range<T> &y){
 | 
|---|
 | 59 |   return x.first==y.first && x.last==y.last;
 | 
|---|
 | 60 | }
 | 
|---|
 | 61 | 
 | 
|---|
 | 62 | template <class T>
 | 
|---|
 | 63 | inline bool operator!= (const range<T>& x, const range<T>& y) { return !(x==y); }
 | 
|---|
 | 64 | template <class T>
 | 
|---|
 | 65 | inline bool operator>  (const range<T>& x, const range<T>& y) { return y<x; }
 | 
|---|
 | 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 !(x<y); }
 | 
|---|
| [6b898c] | 70 | template <class T>
 | 
|---|
 | 71 | std::ostream &operator<< (std::ostream &ost, const range<T>& y)
 | 
|---|
 | 72 | {
 | 
|---|
 | 73 |   ost << "[" << y.first << ";" << y.last << "]";
 | 
|---|
 | 74 |   return ost;
 | 
|---|
 | 75 | }
 | 
|---|
| [a80f419] | 76 | 
 | 
|---|
 | 77 | #endif /* RANGE_HPP_ */
 | 
|---|