1509f1ba00e59be41da99eac33bef34710c0a2c1
[cacao.git] / src / toolbox / list.hpp
1 /* src/toolbox/list.hpp - linked list
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _LIST_HPP
27 #define _LIST_HPP
28
29 #include "config.h"
30
31 #include <stdint.h>
32
33 #ifdef __cplusplus
34
35 #include <list>
36
37 /**
38  * List implementation.
39  */
40 template<class T> class List : protected std::list<T> {
41 public:
42         // make iterator of std::list visible
43         using std::list<T>::iterator;
44         using std::list<T>::reverse_iterator;
45
46         // make functions of std::list visible
47         using std::list<T>::back;
48         using std::list<T>::begin;
49         using std::list<T>::clear;
50         using std::list<T>::empty;
51         using std::list<T>::end;
52         using std::list<T>::front;
53         using std::list<T>::push_back;
54         using std::list<T>::push_front;
55         using std::list<T>::rbegin;
56         using std::list<T>::remove;
57         using std::list<T>::rend;
58         using std::list<T>::size;
59 };
60
61
62 // Required by LockedList.
63 #include "threads/mutex.hpp"
64
65
66 /**
67  * List implementation with a Mutex.
68  */
69 template<class T> class LockedList : public List<T> {
70 private:
71         Mutex _mutex;
72
73 public:
74         virtual ~LockedList() {}
75
76         void lock  () { _mutex.lock(); }
77         void unlock() { _mutex.unlock(); }
78 };
79
80
81 // Required by DumpList.
82 #include "mm/dumpmemory.hpp"
83
84
85 /**
86  * List implementation with dump memory.
87  */
88 template<class T> class DumpList : protected std::list<T, DumpMemoryAllocator<T> > {
89 public:
90         virtual ~DumpList() {}
91
92         // make iterator of std::list visible
93         using std::list<T, DumpMemoryAllocator<T> >::iterator;
94         using std::list<T, DumpMemoryAllocator<T> >::reverse_iterator;
95
96         // make functions of std::list visible
97         using std::list<T, DumpMemoryAllocator<T> >::back;
98         using std::list<T, DumpMemoryAllocator<T> >::begin;
99         using std::list<T, DumpMemoryAllocator<T> >::clear;
100         using std::list<T, DumpMemoryAllocator<T> >::empty;
101         using std::list<T, DumpMemoryAllocator<T> >::end;
102         using std::list<T, DumpMemoryAllocator<T> >::front;
103         using std::list<T, DumpMemoryAllocator<T> >::push_back;
104         using std::list<T, DumpMemoryAllocator<T> >::push_front;
105         using std::list<T, DumpMemoryAllocator<T> >::rbegin;
106         using std::list<T, DumpMemoryAllocator<T> >::remove;
107         using std::list<T, DumpMemoryAllocator<T> >::rend;
108         using std::list<T, DumpMemoryAllocator<T> >::size;
109
110         void* operator new(size_t size) {
111                 return DumpMemory::allocate(size);
112         }
113
114         void operator delete(void* p) {}
115 };
116
117 #else
118
119 typedef struct List List;
120 typedef struct LockedList LockedList;
121 typedef struct DumpList DumpList;
122
123 #endif
124
125 #endif // _LIST_HPP
126
127
128 /*
129  * These are local overrides for various environment variables in Emacs.
130  * Please do not remove this and leave it at the end of the file, where
131  * Emacs will automagically detect them.
132  * ---------------------------------------------------------------------
133  * Local variables:
134  * mode: c++
135  * indent-tabs-mode: t
136  * c-basic-offset: 4
137  * tab-width: 4
138  * End:
139  */