Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AutoComparator.h
1 /*
2  * AutoComparator class interface
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2007, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef ELM_UTIL_AUTO_COMPARATOR_H
22 #define ELM_UTIL_AUTO_COMPARATOR_H
23 
24 #include <elm/assert.h>
25 
26 namespace elm {
27 
28 // AutoComparator template
29 template <class T>
31 public:
32  inline int _compare(const T& v) const { return ((T*)this)->compare(v); }
33  inline bool operator==(const T& v) const { return _compare(v) == 0; }
34  inline bool operator!=(const T& v) const { return _compare(v) != 0; }
35  inline bool operator<(const T& v) const { return _compare(v) < 0; }
36  inline bool operator<=(const T& v) const { return _compare(v) <= 0; }
37  inline bool operator>(const T& v) const { return _compare(v) > 0; }
38  inline bool operator>=(const T& v) const { return _compare(v) >= 0; }
39 };
40 
41 // AutoComparator template
42 template <class T>
44 public:
45  inline int _compare(const T& v) const { return ((T*)this)->compare(v); }
46  inline int _equals(const T& v) const { return ((T*)this)->equals(v); }
47  inline bool operator==(const T& v) const { return _equals(v); }
48  inline bool operator!=(const T& v) const { return !_equals(v); }
49  inline bool operator<(const T& v) const { return _compare(v) < 0; }
50  inline bool operator<=(const T& v) const { return _compare(v) <= 0; }
51  inline bool operator>(const T& v) const { return _compare(v) > 0; }
52  inline bool operator>=(const T& v) const { return _compare(v) >= 0; }
53 };
54 } // elm
55 
56 #endif // ELM_UTIL_AUTO_COMPARATOR_H
bool operator!=(const T &v) const
Definition: AutoComparator.h:48
bool operator==(const T &v) const
Definition: AutoComparator.h:47
bool operator>=(const T &v) const
Definition: AutoComparator.h:52
bool operator>(const T &v) const
Definition: AutoComparator.h:37
Definition: AutoComparator.h:30
bool operator<(const T &v) const
Definition: AutoComparator.h:35
bool operator<(const T &v) const
Definition: AutoComparator.h:49
int _compare(const T &v) const
Definition: AutoComparator.h:45
bool operator==(const T &v) const
Definition: AutoComparator.h:33
bool operator<=(const T &v) const
Definition: AutoComparator.h:36
Definition: AutoComparator.h:43
bool operator>(const T &v) const
Definition: AutoComparator.h:51
bool operator!=(const T &v) const
Definition: AutoComparator.h:34
int _compare(const T &v) const
Definition: AutoComparator.h:32
bool operator<=(const T &v) const
Definition: AutoComparator.h:50
bool operator>=(const T &v) const
Definition: AutoComparator.h:38
int _equals(const T &v) const
Definition: AutoComparator.h:46