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_ */
elm::DefaultAllocator::allocate
void * allocate(t::size size)
Definition: alloc_DefaultAllocator.cpp:131
elm::io::p
Printable< T, M > p(const T &data, const M &man)
Definition: Output.h:302
elm::EquivDelegate::isEqual
bool isEqual(const T &x, const T &y) const
Definition: custom.h:72
elm::AllocatorDelegate::AllocatorDelegate
AllocatorDelegate(A &alloc)
Definition: custom.h:39
elm::HashDelegate::computeHash
t::hash computeHash(const T &key) const
Definition: custom.h:62
elm::AllocatorDelegate::free
void free(t::ptr p) const
Definition: custom.h:41
elm::DefaultAlloc
DefaultAllocatorDelegate DefaultAlloc
Definition: custom.h:47
elm::HashDelegate::HashDelegate
HashDelegate(const H &hash)
Definition: custom.h:61
elm::EquivDelegate::EquivDelegate
EquivDelegate(const E &equ)
Definition: custom.h:71
elm::HashDelegate
Definition: custom.h:59
void
elm::AllocatorDelegate
Definition: custom.h:37
elm::DefaultAllocatorDelegate::allocate
t::ptr allocate(t::size size) const
Definition: custom.h:31
elm::ComparatorDelegate
Definition: custom.h:50
elm::AllocatorDelegate::allocate
t::ptr allocate(t::size size) const
Definition: custom.h:40
elm::HashDelegate::isEqual
bool isEqual(const T &key1, const T &key2) const
Definition: custom.h:63
elm::DefaultAllocatorDelegate::free
void free(t::ptr p) const
Definition: custom.h:32
elm::DefaultAllocator::free
void free(void *block)
Definition: DefaultAllocator.h:44
elm::EquivDelegate
Definition: custom.h:69
elm
Definition: adapter.h:26
elm::t::size
uint64 size
Definition: arch.h:35
elm::DefaultAllocatorDelegate
Definition: custom.h:29
elm::DefaultAllocator::DEFAULT
static DefaultAllocator DEFAULT
Definition: DefaultAllocator.h:41
elm::AllocatorDelegate::alloc
T * alloc() const
Definition: custom.h:42
elm::ComparatorDelegate::ComparatorDelegate
ComparatorDelegate(const C &comp)
Definition: custom.h:52
elm::ComparatorDelegate::doCompare
int doCompare(const T &x, const T &y) const
Definition: custom.h:53
elm::hash
t::hash hash(const T &x)
Definition: hash.h:155
elm::DefaultAllocatorDelegate::alloc
T * alloc() const
Definition: custom.h:33
elm::t::hash
t::intptr hash
Definition: hash.h:34