Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
podarray.h
Go to the documentation of this file.
1
32#ifndef _RWSTD_PODARRAY_H_INCLUDED
33#define _RWSTD_PODARRAY_H_INCLUDED
34
35
36#if __GNUG__ >= 3
37# pragma GCC system_header
38#endif // gcc >= 3
39
40
41#include <string.h>
42#include <rw/_traits.h>
43#include <rw/_defs.h>
44
45
47
48
49// __rw_aligned_buffer specializations should be objects with static
50// storage duration that must "survive" all other static objects and
51// that do not need to be destroyed; this is a POD
52template <class _TypeT>
53struct __rw_aligned_buffer
54{
55 union {
56#ifndef _RWSTD_NO_LONG_DOUBLE
57 long double _C_pad; // guarantee suitable alignment
58#else
59 double _C_pad;
60#endif // _RWSTD_NO_LONG_DOUBLE
61 void *_C_void_pad;
62 void (*_C_pfn_pad)();
63 char _C_data [sizeof (_TypeT)]; // data to back _TypeT up with
64 } _C_buf;
65
66 void* _C_store () {
67 return _C_buf._C_data;
68 }
69
70 _TypeT* _C_data () {
71 return _RWSTD_REINTERPRET_CAST (_TypeT*, _C_buf._C_data);
72 }
73};
74
75
76// typedef prevents an MSVC 6.0 ICE
77typedef _RWSTD_SIZE_T _SizeT;
78
79_EXPORT template <class _TypeT, _SizeT _Size>
80class __rw_pod_array
81{
82 _SizeT _C_len;
83 _TypeT *_C_pbuf;
84 _TypeT _C_buffer [_Size];
85
86public:
87
88 __rw_pod_array (): _C_len (0), _C_pbuf (_C_buffer) {
89 *_C_pbuf = _TypeT ();
90 }
91
92 explicit __rw_pod_array (const _TypeT *__a)
93 : _C_len (_C_length (__a))
94 // , _C_pbuf (_C_len < _Size ? _C_buffer : new _TypeT [_C_len + 1])
95 {
96 // initialze _C_pbuf here in order to prevent HP aCC 3.70
97 // ICE: see http://issues.apache.org/jira/browse/STDCXX-276
98 if (_C_len < _Size)
99 _C_pbuf = _C_buffer;
100 else
101 _C_pbuf = new _TypeT [_C_len + 1];
102 memcpy (_C_pbuf, __a, (_C_len + 1) * sizeof *__a);
103 }
104
105 __rw_pod_array (const _TypeT *__a, _SizeT __len)
106 : _C_len (__len) {
107 // initialze _C_pbuf here in order to prevent HP aCC 3.70
108 // ICE: see http://issues.apache.org/jira/browse/STDCXX-276
109 if (__len < _Size)
110 _C_pbuf = _C_buffer;
111 else
112 _C_pbuf = new _TypeT [__len + 1];
113 memcpy (_C_pbuf, __a, __len * sizeof *__a);
114 _C_pbuf [_C_len] = _TypeT ();
115 }
116
117 __rw_pod_array (const __rw_pod_array &__rhs)
118 : _C_len (__rhs._C_len) {
119 // initialze _C_pbuf here in order to prevent HP aCC 3.70
120 // ICE: see http://issues.apache.org/jira/browse/STDCXX-276
121 if (_C_len < _Size)
122 _C_pbuf = _C_buffer;
123 else
124 _C_pbuf = new _TypeT [_C_len + 1];
125 memcpy (_C_pbuf, __rhs._C_pbuf,
126 (_C_len + !!__rhs._C_pbuf) * sizeof *_C_pbuf);
127 }
128
129 ~__rw_pod_array () {
130 if (_C_pbuf != _C_buffer)
131 delete[] _C_pbuf;
132 }
133
134 _TypeT* data () {
135 return _C_pbuf;
136 }
137
138 const _TypeT* data () const {
139 return _C_pbuf;
140 }
141
142 _TypeT* acquire (_TypeT *__a, _SizeT __len) {
143 _TypeT *__pbuf = _C_pbuf;
144 _C_pbuf = __a;
145 _C_len = __len;
146 return __pbuf;
147 }
148
149 _TypeT* acquire (_TypeT *__a) {
150 return acquire (__a, _C_length (__a));
151 }
152
153 _TypeT* release () {
154 _TypeT* const __pbuf = _C_pbuf;
155 _C_pbuf = _C_buffer;
156 return __pbuf;
157 }
158
159 static _SizeT max_size () {
160 return _Size;
161 }
162
163 _SizeT size () const {
164 return _C_len;
165 }
166
167 __rw_pod_array& append (const _TypeT*, _SizeT);
168
169 __rw_pod_array& append (const _TypeT *__a) {
170 _RWSTD_ASSERT (__a);
171 return append (__a, _C_length (__a));
172 }
173
174 __rw_pod_array& operator+= (const _TypeT *__a) {
175 _RWSTD_ASSERT (__a);
176 return append (__a);
177 }
178
179
180 __rw_pod_array& assign (const _TypeT *__a, _SizeT __len) {
181 return (_C_len = 0), append (__a, __len);
182 }
183
184 __rw_pod_array& assign (const _TypeT *__a) {
185 _RWSTD_ASSERT (__a);
186 return assign (__a, _C_length (__a));
187 }
188
189 __rw_pod_array& operator= (const _TypeT *__a) {
190 _RWSTD_ASSERT (__a);
191 return assign (__a);
192 }
193
194 __rw_pod_array& operator= (const __rw_pod_array &__rhs) {
195 return assign (__rhs._C_pbuf, __rhs._C_len);
196 }
197
198private:
199
200 static _RWSTD_SIZE_T _C_length (const _TypeT *__a) {
201#ifndef _RWSTD_NO_EXT_CHAR_TRAITS_PRIMARY
202 return _STD::char_traits<_TypeT>::length (__a);
203#else // #ifdef _RWSTD_NO_EXT_CHAR_TRAITS_PRIMARY
204 _RWSTD_SIZE_T __len = 0;
205 for (; _TypeT () != *__a; ++__a, ++__len) ;
206 return __len;
207#endif // _RWSTD_NO_EXT_CHAR_TRAITS_PRIMARY
208 }
209};
210
211
212typedef __rw_pod_array<char, 256> __rw_chararray;
213
214
215} // namespace __rw
216
217
218#if _RWSTD_DEFINE_TEMPLATE_FIRST (_POD_ARRAY)
219# include "podarray.cc"
220#endif // _RWSTD_DEFINE_TEMPLATE_FIRST (_POD_ARRAY)
221
222
224
225#if _RWSTD_INSTANTIATE (_POD_ARRAY, _CHAR)
226
227// used throughout locale
228_RWSTD_INSTANTIATE_2 (class __rw_pod_array<char, 256>);
229
230#endif // _RWSTD_INSTANTIATE (_POD_ARRAY, _CHAR)
231
232#if _RWSTD_INSTANTIATE (_POD_ARRAY, _UINT)
233
234// used in collate.cpp
235_RWSTD_INSTANTIATE_2 (class __rw_pod_array<const unsigned int*, 1024>);
236
237#endif // _RWSTD_INSTANTIATE (_POD_ARRAY, _UINT)
238
239} // namespace __rw
240
241
242#if _RWSTD_DEFINE_TEMPLATE_LAST (_POD_ARRAY)
243# include "podarray.cc"
244#endif // _RWSTD_DEFINE_TEMPLATE_LAST (_POD_ARRAY)
245
246
247#endif // _RWSTD_PODARRAY_H_INCLUDED
const char *const data[]
char * append(char *dst, const char *src)
#define _RWSTD_INSTANTIATE_2(a1, a2)
Definition _defs.h:1375
#define _RWSTD_REINTERPRET_CAST(T, x)
Definition _defs.h:535
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _EXPORT
Definition _defs.h:498
#define _RWSTD_ASSERT(ignore)
Definition _defs.h:1108