Line data Source code
1 : /* src/toolbox/list.hpp - linked list
2 :
3 : Copyright (C) 1996-2012
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 : #include <list>
33 : #include "mm/dumpmemory.hpp"
34 : #include "threads/mutex.hpp"
35 :
36 : /**
37 : * List implementation.
38 : */
39 105381 : template<class T> class List : protected std::list<T> {
40 : public:
41 : // make iterator of std::list visible
42 : using typename std::list<T>::iterator;
43 : using typename std::list<T>::reverse_iterator;
44 :
45 : // make functions of std::list visible
46 : using std::list<T>::back;
47 : using std::list<T>::begin;
48 : using std::list<T>::clear;
49 : using std::list<T>::empty;
50 : using std::list<T>::end;
51 : using std::list<T>::front;
52 : using std::list<T>::pop_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 : /**
63 : * List implementation with a Mutex.
64 : */
65 105324 : template<class T> class LockedList : public List<T> {
66 : private:
67 : Mutex _mutex;
68 :
69 : public:
70 37 : virtual ~LockedList() {}
71 :
72 71146 : void lock () { _mutex.lock(); }
73 71146 : void unlock() { _mutex.unlock(); }
74 : };
75 :
76 :
77 : /**
78 : * List implementation with dump memory.
79 : */
80 : template<class T> class DumpList :
81 : public DumpClass,
82 250530 : protected std::list<T, DumpMemoryAllocator<T> > {
83 : public:
84 250530 : virtual ~DumpList() {}
85 :
86 : // make iterator of std::list visible
87 : using typename std::list<T, DumpMemoryAllocator<T> >::iterator;
88 : using typename 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 : using std::list<T, DumpMemoryAllocator<T> >::sort;
104 : };
105 :
106 : #endif // _LIST_HPP
107 :
108 :
109 : /*
110 : * These are local overrides for various environment variables in Emacs.
111 : * Please do not remove this and leave it at the end of the file, where
112 : * Emacs will automagically detect them.
113 : * ---------------------------------------------------------------------
114 : * Local variables:
115 : * mode: c++
116 : * indent-tabs-mode: t
117 : * c-basic-offset: 4
118 : * tab-width: 4
119 : * End:
120 : * vim:noexpandtab:sw=4:ts=4:
121 : */
|