source: src/Range.hpp@ a80f419

Last change on this file since a80f419 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
Line 
1/*
2 * Range.hpp
3 *
4 * Created on: Jul 22, 2010
5 * Author: crueger
6 */
7
8#ifndef RANGE_HPP_
9#define RANGE_HPP_
10template <class T>
11struct 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
21template <class T>
22inline range<T>::range(const T &_first,const T &_last) :
23first(_first),last(_last)
24{}
25
26template <class T>
27inline bool range<T>::isInRange(const T &value) const{
28 return first <= value && value < last;
29}
30
31template <class T>
32inline bool range<T>::isBefore(const T &value) const{
33 return value < first;
34}
35
36template <class T>
37inline bool range<T>::isBeyond(const T &value) const{
38 return last <= value;
39}
40
41template <class T>
42inline range<T> makeRange(const T&first, const T&last){
43 return range<T>(first,last);
44}
45
46template <class T>
47inline 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
51template <class T>
52inline bool operator==(const range<T> &x,const range<T> &y){
53 return x.first==y.first && x.last==y.last;
54}
55
56template <class T>
57inline bool operator!= (const range<T>& x, const range<T>& y) { return !(x==y); }
58template <class T>
59inline bool operator> (const range<T>& x, const range<T>& y) { return y<x; }
60template <class T>
61inline bool operator<=(const range<T>& x, const range<T>& y) { return !(y<x); }
62template <class T>
63inline 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.