Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
equiv.h
1 /*
2  * $Id$
3  * Equiv class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2008, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef ELM_EQUIV_H_
23 #define ELM_EQUIV_H_
24 
25 #include <elm/string.h>
26 #include <elm/util/Pair.h>
27 
28 namespace elm {
29 
30 // Equiv class
31 template <class T>
32 class Equiv {
33 public:
34  typedef T t;
35  static inline bool equals(const T& v1, const T& v2) { return v1 == v2; }
36  inline bool isEqual(const T& v1, const T& v2) const { return equals(v1, v2); }
37  static Equiv<T> def;
38 };
39 template <class T> Equiv<T> Equiv<T>::def;
40 
41 
42 // EqualsEquiv class
43 template <class T>
44 class EqualsEquiv {
45 public:
46  typedef T t;
47  static inline int equal(const T& v1, const T& v2) { return v1.equals(v2); }
48  inline bool isEqual(const T& v1, const T& v2) const { return equals(v1, v2); }
50 };
51 template <class T> EqualsEquiv<T> EqualsEquiv<T>::def;
52 
53 
54 // AssocEquiv class
55 template <class K, class T, class E = Equiv<K> >
56 class AssocEquiv {
57 public:
58  typedef Pair<K, T> pair_t;
59  typedef pair_t t;
60  static inline bool equals(const pair_t& v1, const pair_t& v2) { return E::equals(v1.fst, v2. fst); }
61  inline bool isEqual(const pair_t& v1, const pair_t& v2) const { return equals(v1, v2); }
63 };
64 template <class K, class T, class E> AssocEquiv<K, T, E> AssocEquiv<K, T, E>::def;
65 
66 
67 // CompareEquiv class
68 template <class C>
69 class CompareEquiv: public C {
70 public:
71  typedef typename C::t t;
72  inline bool isEqual(const t& v1, const t& v2) const { return C::doCompare(v1, v2) == 0; }
73  static inline bool equals(const t& v1, const t& v2) { return C::compare(v1, v2) == 0; }
74 };
75 
76 } // elm
77 
78 #endif /* ELM_EQUIV_H_ */
elm::EqualsEquiv
Definition: equiv.h:44
elm::CompareEquiv::isEqual
bool isEqual(const t &v1, const t &v2) const
Definition: equiv.h:72
elm::CompareEquiv
Definition: equiv.h:69
elm::AssocEquiv::def
static AssocEquiv< K, T, E > def
Definition: equiv.h:62
elm::EqualsEquiv::t
T t
Definition: equiv.h:46
elm::AssocEquiv
Definition: equiv.h:56
elm::equals
bool equals(const C1 &c1, const C2 &c2)
Definition: util.h:107
elm::Equiv::def
static Equiv< T > def
Definition: equiv.h:37
elm::Pair< K, T >
elm::EqualsEquiv::def
static EqualsEquiv< T > def
Definition: equiv.h:49
elm::EqualsEquiv::isEqual
bool isEqual(const T &v1, const T &v2) const
Definition: equiv.h:48
elm::AssocEquiv::equals
static bool equals(const pair_t &v1, const pair_t &v2)
Definition: equiv.h:60
elm::Equiv::isEqual
bool isEqual(const T &v1, const T &v2) const
Definition: equiv.h:36
elm::CompareEquiv::t
C::t t
Definition: equiv.h:71
elm
Definition: adapter.h:26
elm::AssocEquiv::isEqual
bool isEqual(const pair_t &v1, const pair_t &v2) const
Definition: equiv.h:61
elm::EqualsEquiv::equal
static int equal(const T &v1, const T &v2)
Definition: equiv.h:47
elm::AssocEquiv::pair_t
Pair< K, T > pair_t
Definition: equiv.h:58
elm::Equiv::t
T t
Definition: equiv.h:34
elm::String
Definition: String.h:30
elm::AssocEquiv::t
pair_t t
Definition: equiv.h:59
elm::CompareEquiv::equals
static bool equals(const t &v1, const t &v2)
Definition: equiv.h:73
elm::Equiv
Definition: equiv.h:32
elm::Equiv::equals
static bool equals(const T &v1, const T &v2)
Definition: equiv.h:35
elm::Pair::fst
T1 fst
Definition: Pair.h:35