clingo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
hashable.hh
Go to the documentation of this file.
1 // {{{ GPL License
2 
3 // This file is part of gringo - a grounder for logic programs.
4 // Copyright (C) 2013 Roland Kaminski
5 
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 // }}}
20 
21 #ifndef _GRINGO_HASHABLE_HH
22 #define _GRINGO_HASHABLE_HH
23 
24 #include <ostream>
25 #include <typeinfo>
26 #include <functional>
27 #include <gringo/utility.hh>
28 
29 #define GRINGO_HASH(T) namespace std { template <> struct hash<T> : hash<Gringo::Hashable> { }; }
30 #define GRINGO_CALL_HASH(T) namespace std { template <> struct hash<T> { size_t operator()(T const &x) const { return x.hash(); } }; }
31 
32 namespace Gringo {
33 
34 // {{{ declaration of Hashable
35 
36 class Hashable {
37 public:
38  virtual size_t hash() const = 0;
39  virtual ~Hashable() { }
40 };
41 
42 // }}}
43 // {{{ definition of call_hash
44 
45 template <class T>
46 struct call_hash {
47  size_t operator()(T const &x) const { return x.hash(); }
48 };
49 
50 // }}}
51 
52 } // namespace Gringo
53 
54 namespace std {
55 
56 // {{{ definition of hash<Gringo::Hashable>
57 
58 template <>
59 struct hash<Gringo::Hashable> {
60  size_t operator()(Gringo::Hashable const &x) const { return x.hash(); }
61 };
62 
63 // }}}
64 
65 } // namespace std
66 
67 #endif // _GRINGO_HASHABLE_HH
68 
size_t operator()(T const &x) const
Definition: hashable.hh:47
virtual ~Hashable()
Definition: hashable.hh:39
size_t operator()(Gringo::Hashable const &x) const
Definition: hashable.hh:60
Definition: hashable.hh:36
Definition: hashable.hh:46
int x
Definition: utility.cc:65
virtual size_t hash() const =0