|
Last change
on this file since 8931ef was a80f419, checked in by Frederik Heber <heber@…>, 15 years ago |
|
First version.
Everything was extracted from project MoleCuilder and adapted such that it
runs on its own (i.e. new configure.ac, Makefile.am structure, stuff for
libtool versioning, ...)
|
-
Property mode
set to
100644
|
|
File size:
1.5 KB
|
| Rev | Line | |
|---|
| [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_
|
|---|
| 10 | template <class T>
|
|---|
| 11 | struct range {
|
|---|
| 12 | range(const T&,const T&);
|
|---|
| 13 | bool isInRange(const T&) const;
|
|---|
| 14 | bool isBefore(const T&) const;
|
|---|
| 15 | bool isBeyond(const T&) const;
|
|---|
| 16 |
|
|---|
| 17 | T first;
|
|---|
| 18 | T last;
|
|---|
| 19 | };
|
|---|
| 20 |
|
|---|
| 21 | template <class T>
|
|---|
| 22 | inline range<T>::range(const T &_first,const T &_last) :
|
|---|
| 23 | first(_first),last(_last)
|
|---|
| 24 | {}
|
|---|
| 25 |
|
|---|
| 26 | template <class T>
|
|---|
| 27 | inline bool range<T>::isInRange(const T &value) const{
|
|---|
| 28 | return first <= value && value < last;
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | template <class T>
|
|---|
| 32 | inline bool range<T>::isBefore(const T &value) const{
|
|---|
| 33 | return value < first;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | template <class T>
|
|---|
| 37 | inline bool range<T>::isBeyond(const T &value) const{
|
|---|
| 38 | return last <= value;
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | template <class T>
|
|---|
| 42 | inline range<T> makeRange(const T&first, const T&last){
|
|---|
| 43 | return range<T>(first,last);
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | template <class T>
|
|---|
| 47 | inline bool operator<(const range <T> &x, const range<T> &y){
|
|---|
| 48 | return (x.first!=y.first)?x.first<y.first:x.last<y.last;
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | template <class T>
|
|---|
| 52 | inline bool operator==(const range<T> &x,const range<T> &y){
|
|---|
| 53 | return x.first==y.first && x.last==y.last;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | template <class T>
|
|---|
| 57 | inline bool operator!= (const range<T>& x, const range<T>& y) { return !(x==y); }
|
|---|
| 58 | template <class T>
|
|---|
| 59 | inline bool operator> (const range<T>& x, const range<T>& y) { return y<x; }
|
|---|
| 60 | template <class T>
|
|---|
| 61 | inline bool operator<=(const range<T>& x, const range<T>& y) { return !(y<x); }
|
|---|
| 62 | template <class T>
|
|---|
| 63 | inline bool operator>= (const range<T>& x, const range<T>& y) { return !(x<y); }
|
|---|
| 64 |
|
|---|
| 65 | #endif /* RANGE_HPP_ */
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.