Mercurial > projects > qtd
annotate generator/parser/rxx_allocator.h @ 414:b2a803c73b89 default tip
Declare tabArray const.
author | David Nadlinger <code@klickverbot.at> |
---|---|
date | Fri, 06 May 2011 13:39:49 +0200 |
parents | 09a0f1d048f2 |
children |
rev | line source |
---|---|
1 | 1 /**************************************************************************** |
2 ** | |
52
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
3 ** Copyright (C) 1992-2009 Nokia. All rights reserved. |
1 | 4 ** Copyright (C) 2002-2005 Roberto Raggi <roberto@kdevelop.org> |
5 ** | |
6 ** This file is part of Qt Jambi. | |
7 ** | |
52
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
8 ** Commercial Usage |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
9 Licensees holding valid Qt Commercial licenses may use this file in |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
10 accordance with the Qt Commercial License Agreement provided with the |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
11 Software or, alternatively, in accordance with the terms contained in |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
12 a written agreement between you and Nokia. |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
13 |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
14 GNU Lesser General Public License Usage |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
15 Alternatively, this file may be used under the terms of the GNU Lesser |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
16 General Public License version 2.1 as published by the Free Software |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
17 Foundation and appearing in the file LICENSE.LGPL included in the |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
18 packaging of this file. Please review the following information to |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
19 ensure the GNU Lesser General Public License version 2.1 requirements |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
20 will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
21 |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
22 In addition, as a special exception, Nokia gives you certain |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
23 additional rights. These rights are described in the Nokia Qt LGPL |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
24 Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
25 package. |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
26 |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
27 GNU General Public License Usage |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
28 Alternatively, this file may be used under the terms of the GNU |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
29 General Public License version 3.0 as published by the Free Software |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
30 Foundation and appearing in the file LICENSE.GPL included in the |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
31 packaging of this file. Please review the following information to |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
32 ensure the GNU General Public License version 3.0 requirements will be |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
33 met: http://www.gnu.org/copyleft/gpl.html. |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
34 |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
35 If you are unsure which license is appropriate for your use, please |
09a0f1d048f2
update parser to that from jambi 4.5, attemt to fix building with gcc 4.4
eldar
parents:
1
diff
changeset
|
36 contact the sales department at qt-sales@nokia.com. |
1 | 37 |
38 ** | |
39 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | |
40 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
41 ** | |
42 ****************************************************************************/ | |
43 | |
44 | |
45 #ifndef RXX_ALLOCATOR_H | |
46 #define RXX_ALLOCATOR_H | |
47 | |
48 #include <cstddef> | |
49 #include <cstdlib> | |
50 #include <cstring> | |
51 #include <memory> | |
52 | |
53 template <class _Tp> class rxx_allocator { | |
54 public: | |
55 typedef _Tp value_type; | |
56 typedef _Tp* pointer; | |
57 typedef const _Tp* const_pointer; | |
58 typedef _Tp& reference; | |
59 typedef const _Tp& const_reference; | |
60 typedef std::size_t size_type; | |
61 typedef std::ptrdiff_t difference_type; | |
62 | |
63 static const size_type max_block_count = size_type(-1); | |
64 static const size_type _S_block_size = 1 << 16; // 64K | |
65 | |
66 rxx_allocator() { | |
67 _M_block_index = max_block_count; | |
68 _M_current_index = 0; | |
69 _M_storage = 0; | |
70 _M_current_block = 0; | |
71 } | |
72 | |
73 ~rxx_allocator() { | |
74 for (size_type index = 0; index < _M_block_index + 1; ++index) | |
75 delete[] _M_storage[index]; | |
76 | |
77 ::free(_M_storage); | |
78 } | |
79 | |
80 pointer address(reference __val) { return &__val; } | |
81 const_pointer address(const_reference __val) const { return &__val; } | |
82 | |
83 pointer allocate(size_type __n, const void* = 0) { | |
84 const size_type bytes = __n * sizeof(_Tp); | |
85 | |
86 if (_M_current_block == 0 | |
87 || _S_block_size < _M_current_index + bytes) | |
88 { | |
89 ++_M_block_index; | |
90 | |
91 _M_storage = reinterpret_cast<char**> | |
92 (::realloc(_M_storage, sizeof(char*) * (1 + _M_block_index))); | |
93 | |
94 _M_current_block = _M_storage[_M_block_index] = reinterpret_cast<char*> | |
95 (new char[_S_block_size]); | |
96 | |
97 #if defined(RXX_ALLOCATOR_INIT_0) // ### make it a policy | |
98 ::memset(_M_current_block, 0, _S_block_size); | |
99 #endif | |
100 _M_current_index = 0; | |
101 } | |
102 | |
103 pointer p = reinterpret_cast<pointer> | |
104 (_M_current_block + _M_current_index); | |
105 | |
106 _M_current_index += bytes; | |
107 | |
108 return p; | |
109 } | |
110 | |
111 void deallocate(pointer __p, size_type __n) {} | |
112 | |
113 size_type max_size() const { return size_type(-1) / sizeof(_Tp); } | |
114 | |
115 void contruct(pointer __p, const_reference __val) { new (__p) _Tp(__val); } | |
116 void destruct(pointer __p) { __p->~_Tp(); } | |
117 | |
118 private: | |
119 template <class _Tp1> struct rebind { | |
120 typedef rxx_allocator<_Tp1> other; | |
121 }; | |
122 | |
123 template <class _Tp1> rxx_allocator(const rxx_allocator<_Tp1> &__o) {} | |
124 | |
125 private: | |
126 size_type _M_block_index; | |
127 size_type _M_current_index; | |
128 char *_M_current_block; | |
129 char **_M_storage; | |
130 }; | |
131 | |
132 #endif // RXX_ALLOCATOR_H | |
133 | |
134 // kate: space-indent on; indent-width 2; replace-tabs on; |