Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_basic_ios.h
Go to the documentation of this file.
1// -*- C++ -*-
2
30#ifndef _RWSTD_RW_BASIC_IOS_H_INCLUDED
31#define _RWSTD_RW_BASIC_IOS_H_INCLUDED
32
33
34#if __GNUG__ >= 3
35# pragma GCC system_header
36#endif // gcc >= 3
37
38
39#ifndef _RWSTD_NO_REDUNDANT_DEFINITIONS
40# include <streambuf>
41#endif // _RWSTD_NO_REDUNDANT_DEFINITIONS
42
43#include <loc/_ctype.h> // for ctype
44
45#ifndef _RWSTD_RW_IOSBASE_H_INCLUDED
46# include <rw/_iosbase.h> // for ios_base
47#endif // _RWSTD_RW_IOSBASE_H_INCLUDED
48
49#ifndef _RWSTD_RW_IOSFWD_H_INCLUDED
50# include <rw/_iosfwd.h>
51#endif // _RWSTD_RW_IOSFWD_H_INCLUDED
52
53
55
56#ifndef _RWSTD_IOSFWD_INCLUDED
57
59template <class _CharT, class _Traits = char_traits<_CharT> >
60class basic_ios;
61
62typedef basic_ios<char> ios;
63
64# ifndef _RWSTD_NO_WCHAR_T
65
66typedef basic_ios<wchar_t> wios;
67
68# endif // _RWSTD_NO_WCHAR_T
69#endif // _RWSTD_IOSFWD_INCLUDED
70
71
73template <class _CharT, class _Traits>
74class basic_ios: public ios_base
75{
76public:
77
78 typedef _CharT char_type;
79 typedef _Traits traits_type;
80 typedef typename traits_type::int_type int_type;
81 typedef typename traits_type::pos_type pos_type;
82 typedef typename traits_type::int_type off_type;
83
84protected:
85
86 typedef basic_streambuf<char_type, traits_type> streambuf_type;
87 typedef basic_ostream<char_type, traits_type> ostream_type;
88
89public:
90
91 // 27.4.4.1, p1 - NOTE: `sb' may point to a yet uninitialized
92 // object; it is unsafe to reference any of its members
93 explicit basic_ios (streambuf_type *__sb) {
94 init (__sb);
95 }
96
97 // 27.4.4.3, p1
98
99#ifndef _RWSTD_NO_EXT_IOS_SAFE_CONVERSION
100
101private:
102
103# if !defined (__INTEL_COMPILER) || !defined (_WIN32)
104
105 // SunPro 5.7 needs a data pointer and misoptimizes the conversion
106 // operator when this is a pointer to a member function (bug #446)
107 struct _C_uniq_type { int _C_foo; /* never used */ };
108 typedef int _C_uniq_type::*_C_uniq_ptr;
109
110# else // if __INTEL_COMPILER && _WIN32
111
112 // working around Intel C++ 8.1 -Zi bug #570 on Win32
113 struct _C_uniq_type { void _C_foo () { }; /* never used */ };
114 typedef void (_C_uniq_type::*_C_uniq_ptr)();
115
116# endif // __INTEL_COMPILER/_WIN32
117
118public:
119
120 operator _C_uniq_ptr () const {
121 return fail () ? _C_uniq_ptr (0) : &_C_uniq_type::_C_foo;
122 }
123
124#else // if defined (_RWSTD_NO_EXT_IOS_SAFE_CONVERSION)
125
126 operator void*() const {
127 return fail () ? (void*)0 : (void*)1;
128 }
129
130#endif // _RWSTD_NO_EXT_IOS_SAFE_CONVERSION
131
132 // 27.4.4.3, p2
133 bool operator! () const {
134 return fail ();
135 }
136
137 // 27.4.4.3, p3
138 iostate rdstate () const {
139 return iostate (_C_state);
140 }
141
142 // 27.4.4.3, p4
143 void clear (iostate __state = goodbit) {
144 _C_set (__state, _C_except, rdbuf ());
145 }
146
147 // 27.4.4.3, p6
148 void setstate (iostate __st) {
149 clear (rdstate () | __st);
150 }
151
152 // 27.4.4.3, p7
153 bool good () const {
154 return goodbit == rdstate ();
155 }
156
157 // 27.4.4.3, p8
158 bool eof () const {
159 return 0 != (rdstate () & eofbit);
160 }
161
162 // 27.4.4.3, p9
163 bool fail () const {
164 return 0 != (rdstate () & (failbit | badbit));
165 }
166
167 // 27.4.4.3, p10
168 bool bad () const {
169 return 0 != (rdstate () & badbit);
170 }
171
172 // 27.4.4.3, p11
173 iostate exceptions () const {
174 return iostate (_C_except);
175 }
176
177 // 27.4.4.3, p12
178 void exceptions (iostate __state) {
179 _C_set (rdstate (), __state, rdbuf ());
180 }
181
182 // 27.4.4.2, p1
183 ostream_type* tie () const {
184 return _C_usr ? _RWSTD_STATIC_CAST (ostream_type*, _C_tie ()) : 0;
185 }
186
187 // 27.4.4.2, p2
188 ostream_type* tie (ostream_type *__strm) {
189 return _RWSTD_STATIC_CAST (ostream_type*, _C_tie (__strm));
190 }
191
192 // 27.4.4.2, p4 - NOTE: the pointer returned from rdbuf() in derived
193 // classes may be different from the one passed to rdbuf (streambuf_type*)
194 streambuf_type* rdbuf () const {
195 return _RWSTD_STATIC_CAST (streambuf_type*, _C_rdbuf);
196 }
197
198 // 27.4.4.2, p5
199 streambuf_type* rdbuf (streambuf_type *__rdbuf) {
200 return _RWSTD_STATIC_CAST (streambuf_type*,
201 _C_set (goodbit, _C_except, __rdbuf));
202 }
203
204 // 27.4.4.2, p15
205 basic_ios& copyfmt (const basic_ios &__x) {
206 return _C_copyfmt (__x, &_C_fill, &__x._C_fill, sizeof _C_fill), *this;
207 }
208
209 // 27.4.4.2, p12
210 char_type fill () const;
211
212 // 27.4.4.2, p13
213 char_type fill (char_type);
214
215 // 27.4.4.2, p8
216 locale imbue (const locale&);
217
218 // 27.4.4.2, p10
219 char narrow (char_type __c, char __dflt) const {
220 return _USE_FACET (ctype<char_type>, getloc ()).narrow (__c, __dflt);
221 }
222
223 // 27.4.4.2, p11
224 char_type widen (char __c) const {
225 return _USE_FACET (ctype<char_type>, getloc ()).widen (__c);
226 }
227
228protected:
229
230 // initialization of standard iostream objects may depend on
231 // the default ctor not to re-initialize the object
232 basic_ios () { /* no-op as per 27.4.4.1, p2 */ }
233
234 // 27.4.4.1, p3
235 void init (streambuf_type*);
236
237 // (conditionally) returns a pointer to a mutex in the associated
238 // basic_streambuf object
239 _RW::__rw_mutex* _C_bufmutex () const;
240
241private:
242
243 basic_ios (const basic_ios&); // not defined
244 basic_ios& operator= (const basic_ios&); // not defined
245
246 int_type _C_fill; // fill character (space by default)
247};
248
249
250template<class _CharT, class _Traits>
251inline typename basic_ios<_CharT, _Traits>::char_type
252basic_ios<_CharT, _Traits>::fill () const
253{
254 // delayed initialization used to allow objects of stream types other
255 // than those whose char_type is char or wchar_t to be successfully
256 // constructed even if the global locale doesn't contain a ctype facet
257 // specialized on the stream type's char_type
258 if (traits_type::eq_int_type (traits_type::eof (), _C_fill))
259 _RWSTD_CONST_CAST (basic_ios*, this)->fill (widen (' '));
260
261 return traits_type::to_char_type (_C_fill);
262}
263
264
265template<class _CharT, class _Traits>
266inline typename basic_ios<_CharT, _Traits>::char_type
267basic_ios<_CharT, _Traits>::fill (char_type __ch)
268{
269 // convert to int type before swapping
270 const int_type __c = traits_type::to_int_type (__ch);
271
272 _RWSTD_MT_GUARD (flags () & _RWSTD_IOS_NOLOCK ? 0 : &_C_mutex);
273
274 // save the previous value of the fill character
275 traits_type::assign (__ch, traits_type::to_char_type (_C_fill));
276
277 _C_fill = __c;
278
279 return __ch;
280}
281
282
283template<class _CharT, class _Traits>
284inline locale
285basic_ios<_CharT, _Traits>::imbue (const locale& __loc)
286{
287 _RWSTD_MT_GUARD (flags () & _RWSTD_IOS_NOLOCK ? 0 : &_C_mutex);
288
289 const locale __tmp = _C_unsafe_imbue (__loc);
290
291 if (rdbuf ())
292 rdbuf ()->pubimbue (__loc);
293
294 return __tmp;
295}
296
297
298template<class _CharT, class _Traits>
299inline void
300basic_ios<_CharT, _Traits>::init (streambuf_type *__sb)
301{
302 // invalidate the fill character
303 // the character will be initialized the first time fill() is called
304 // so that objects of stream types other than those specialized on char
305 // and wchar_t can be successfully constructed even if the global locale
306 // doesn't contain a ctype facet specialized on the stream type's
307 // char_type
308 _C_fill = traits_type::eof ();
309
310 _C_init (__sb);
311}
312
313
314template<class _CharT, class _Traits>
315inline _RW::__rw_mutex*
316basic_ios<_CharT, _Traits>::_C_bufmutex () const
317{
318#if !defined (_RWSTD_REENTRANT) || defined (_RWSTD_NO_EXT_REENTRANT_IO)
319
320 // unconditionally return pointer to buffer's mutex
321 // (real or fake if not in an MT environment)
322 return rdbuf () ? &rdbuf ()->_C_mutex : 0;
323
324#else
325
326 // return pointer to buffer's mutex unless the object is in
327 // a state where buffer locking is disabled)
328 return flags () & _RWSTD_IOS_NOLOCKBUF || !rdbuf ()
329 ? 0 : &rdbuf ()->_C_mutex;
330
331#endif // !_RWSTD_REENTRANT || !_RWSTD_NO_EXT_REENTRANT_IO
332}
333
334
335} // namespace std
336
337
338#if _RWSTD_DEFINE_TEMPLATE_FIRST (_BASIC_IOS)
339# include <rw/_basic_ios.cc>
340#endif // _RWSTD_DEFINE_TEMPLATE_FIRST (_BASIC_IOS)
341
342
343#ifdef _RWSTD_MSVC
344# pragma warning (push)
345# pragma warning (disable: 4231)
346#endif // _RWSTD_MSVC
347
348
350
351#if _RWSTD_INSTANTIATE (_BASIC_IOS, _CHAR)
352
354 basic_ios<char, char_traits<char> >);
355
356#endif // _RWSTD_INSTANTIATE (_BASIC_IOS, _CHAR)
357
358#if _RWSTD_INSTANTIATE (_BASIC_IOS, _WCHAR_T)
359
361 basic_ios<wchar_t, char_traits<wchar_t> >);
362
363#endif // _RWSTD_INSTANTIATE (_BASIC_IOS, _WCHAR_T)
364
365} // namespace std
366
367
368#ifdef _RWSTD_MSVC
369# pragma warning (pop)
370#endif // _RWSTD_MSVC
371
372
373#if _RWSTD_DEFINE_TEMPLATE_LAST (_BASIC_IOS)
374# include <rw/_basic_ios.cc>
375#endif // _RWSTD_DEFINE_TEMPLATE_LAST (_BASIC_IOS)
376
377
378#endif // _RWSTD_RW_BASIC_IOS_H_INCLUDED
int fail
const char * widen(char *dst, const char *src)
const char * narrow(char *dst, const char *src)
#define failbit
#define badbit
#define goodbit
#define eofbit
#define flags
void tie(std::ostringstream *ps, std::size_t n)
#define _RWSTD_INSTANTIATE_2(a1, a2)
Definition _defs.h:1375
#define _RWSTD_IOS_NOLOCKBUF
Definition _defs.h:785
#define _RWSTD_IOS_NOLOCK
Definition _defs.h:784
#define _RWSTD_STATIC_CAST(T, x)
Definition _defs.h:534
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _USE_FACET(type, arg)
Definition _defs.h:921
#define _RWSTD_MT_GUARD(ignore)
Definition _defs.h:695
#define _EXPORT
Definition _defs.h:498
#define _RWSTD_TI_EXPORT
Definition _defs.h:1331
#define _RWSTD_CONST_CAST(T, x)
Definition _defs.h:536
std::mbstate_t init
Definition codecvt1.cpp:80
Definition json.h:5363