Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
custom.h
1 /*
2  * customization for data structures
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2019, 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_DATA_CUSTOM_H_
22 #define ELM_DATA_CUSTOM_H_
23 
24 #include <elm/alloc/DefaultAllocator.h>
25 #include <elm/hash.h>
26 
27 namespace elm {
28 
30 public:
32  inline void free(t::ptr p) const { DefaultAllocator::DEFAULT.free(p); }
33  template <class T> T *alloc() const { return static_cast<T *>(allocate(sizeof(T))); }
34 };
35 
36 template <class A>
38 public:
39  inline AllocatorDelegate(A& alloc): a(alloc) { }
40  inline t::ptr allocate(t::size size) const { return a.allocate(size); }
41  inline void free(t::ptr p) const { a.free(p); }
42  template <class T> T *alloc() const { return static_cast<T *>(allocate(sizeof(T))); }
43 private:
44  A& a;
45 };
46 
48 
49 template <class T, class C>
51 public:
52  inline ComparatorDelegate(const C& comp): c(comp) { }
53  inline int doCompare(const T& x, const T& y) const { return c.doCompare(x, y); }
54 private:
55  const C& c;
56 };
57 
58 template <class T, class H>
59 class HashDelegate {
60 public:
61  inline HashDelegate(const H& hash): h(hash) { }
62  inline t::hash computeHash(const T& key) const { return h.computeHash(key); }
63  inline bool isEqual(const T& key1, const T& key2) const { return h.isEquals(key1, key2); }
64 private:
65  const H& h;
66 };
67 
68 template <class T, class E>
70 public:
71  inline EquivDelegate(const E& equ): e(equ) { }
72  inline bool isEqual(const T& x, const T& y) const { return e.isEquals(x, y); }
73 private:
74  const E& e;
75 };
76 
77 } // elm
78 
79 #endif /* ELM_DATA_CUSTOM_H_ */
Definition: custom.h:37
T * alloc() const
Definition: custom.h:42
void free(t::ptr p) const
Definition: custom.h:41
AllocatorDelegate(A &alloc)
Definition: custom.h:39
t::ptr allocate(t::size size) const
Definition: custom.h:40
Definition: custom.h:50
int doCompare(const T &x, const T &y) const
Definition: custom.h:53
ComparatorDelegate(const C &comp)
Definition: custom.h:52
Definition: custom.h:29
T * alloc() const
Definition: custom.h:33
void free(t::ptr p) const
Definition: custom.h:32
t::ptr allocate(t::size size) const
Definition: custom.h:31
void * allocate(t::size size)
Definition: alloc_DefaultAllocator.cpp:131
static DefaultAllocator DEFAULT
Definition: DefaultAllocator.h:41
void free(void *block)
Definition: DefaultAllocator.h:44
Definition: custom.h:69
bool isEqual(const T &x, const T &y) const
Definition: custom.h:72
EquivDelegate(const E &equ)
Definition: custom.h:71
Definition: custom.h:59
bool isEqual(const T &key1, const T &key2) const
Definition: custom.h:63
HashDelegate(const H &hash)
Definition: custom.h:61
t::hash computeHash(const T &key) const
Definition: custom.h:62
Printable< T, M > p(const T &data, const M &man)
Definition: Output.h:302
uint64 size
Definition: arch.h:35
t::hash hash(const T &x)
Definition: hash.h:155
t::intptr hash
Definition: hash.h:34
Definition: adapter.h:26
DefaultAllocatorDelegate DefaultAlloc
Definition: custom.h:47