0ca05c82e7b53f90496b94440eb23681afefff5c
[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 #include <list>
35 #endif
36
37 #include "threads/mutex.hpp"
38
39
40 #ifdef __cplusplus
41
42 /**
43  * List implementation with a Mutex.
44  */
45 template<class T> class List : protected std::list<T> {
46 private:
47         Mutex _mutex;
48
49 public:
50         virtual ~List() {}
51
52         void lock  () { _mutex.lock(); }
53         void unlock() { _mutex.unlock(); }
54
55         // make iterator of std::list visible
56         using std::list<T>::iterator;
57         using std::list<T>::reverse_iterator;
58
59         // make functions of std::list visible
60         using std::list<T>::back;
61         using std::list<T>::begin;
62         using std::list<T>::clear;
63         using std::list<T>::empty;
64         using std::list<T>::end;
65         using std::list<T>::front;
66         using std::list<T>::push_back;
67         using std::list<T>::push_front;
68         using std::list<T>::rbegin;
69         using std::list<T>::remove;
70         using std::list<T>::rend;
71         using std::list<T>::size;
72 };
73
74
75 // Required by DumpList.
76 #include "mm/dumpmemory.hpp"
77
78
79 /**
80  * List implementation with dump memory.
81  */
82 template<class T> class DumpList : protected std::list<T, DumpMemoryAllocator<T> > {
83 public:
84         virtual ~DumpList() {}
85
86         // make iterator of std::list visible
87         using std::list<T, DumpMemoryAllocator<T> >::iterator;
88         using std::list<T, DumpMemoryAllocator<T> >::reverse_iterator;
89
90         // make functions of std::list visible
91         using std::list<T, DumpMemoryAllocator<T> >::back;
92         using std::list<T, DumpMemoryAllocator<T> >::begin;
93         using std::list<T, DumpMemoryAllocator<T> >::clear;
94         using std::list<T, DumpMemoryAllocator<T> >::empty;
95         using std::list<T, DumpMemoryAllocator<T> >::end;
96         using std::list<T, DumpMemoryAllocator<T> >::front;
97         using std::list<T, DumpMemoryAllocator<T> >::push_back;
98         using std::list<T, DumpMemoryAllocator<T> >::push_front;
99         using std::list<T, DumpMemoryAllocator<T> >::rbegin;
100         using std::list<T, DumpMemoryAllocator<T> >::remove;
101         using std::list<T, DumpMemoryAllocator<T> >::rend;
102         using std::list<T, DumpMemoryAllocator<T> >::size;
103
104         void* operator new(size_t size) {
105                 return DumpMemory::allocate(size);
106         }
107
108         void operator delete(void* p) {}
109 };
110
111 #else
112
113 typedef struct List List;
114 typedef struct DumpList DumpList;
115
116 #endif
117
118 #endif // _LIST_HPP
119
120
121 /*
122  * These are local overrides for various environment variables in Emacs.
123  * Please do not remove this and leave it at the end of the file, where
124  * Emacs will automagically detect them.
125  * ---------------------------------------------------------------------
126  * Local variables:
127  * mode: c++
128  * indent-tabs-mode: t
129  * c-basic-offset: 4
130  * tab-width: 4
131  * End:
132  */