ReactOS  0.4.13-dev-249-gcba1a2f
_ostream.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1999
3  * Silicon Graphics Computer Systems, Inc.
4  *
5  * Copyright (c) 1999
6  * Boris Fomitchev
7  *
8  * This material is provided "as is", with absolutely no warranty expressed
9  * or implied. Any use is at your own risk.
10  *
11  * Permission to use or copy this software for any purpose is hereby granted
12  * without fee, provided the above notices are retained on all copies.
13  * Permission to modify the code and to distribute modified code is granted,
14  * provided the above notices are retained, and a notice that the code was
15  * modified is included with the above copyright notice.
16  *
17  */
18 
19 
20 #ifndef _STLP_INTERNAL_OSTREAM_H
21 #define _STLP_INTERNAL_OSTREAM_H
22 
23 #ifndef _STLP_INTERNAL_IOS_H
24 # include <stl/_ios.h> // For basic_ios<>. Includes <iosfwd>.
25 #endif
26 
27 #ifndef _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H
29 #endif
30 
31 #if !defined (_STLP_NO_UNCAUGHT_EXCEPT_SUPPORT) && !defined (_STLP_INTERNAL_EXCEPTION)
32 # include <stl/_exception.h>
33 #endif
34 
36 
37 #if defined (_STLP_USE_TEMPLATE_EXPORT)
38 template <class _CharT, class _Traits>
39 class _Osentry;
40 #endif
41 
43 
44 template <class _CharT, class _Traits>
46 
48 
49 //----------------------------------------------------------------------
50 // class basic_ostream<>
51 
52 template <class _CharT, class _Traits>
53 class basic_ostream : virtual public basic_ios<_CharT, _Traits> {
55 
56 #if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310)
57  //explicitely defined as private to avoid warnings:
58  basic_ostream(_Self const&);
59  _Self& operator = (_Self const&);
60 #endif
61 
62 public: // Types
63  typedef _CharT char_type;
64  typedef typename _Traits::int_type int_type;
65  typedef typename _Traits::pos_type pos_type;
66  typedef typename _Traits::off_type off_type;
67  typedef _Traits traits_type;
69 
70 public: // Constructor and destructor.
73 
74 public: // Hooks for manipulators.
78  _Self& operator<< (__ostream_fn __f) { return __f(*this); }
79  _Self & operator<< (__ios_base_fn __f) { __f(*this); return *this; }
80  _Self& operator<< (__ios_fn __ff) { __ff(*this); return *this; }
81 
82 private:
87 
88 public:
89  void _M_put_char(_CharT __c);
90 
91  void _M_put_nowiden(const _CharT* __s);
92  void _M_put_widen(const char* __s);
93  bool _M_put_widen_aux(const char* __s, streamsize __n);
94 
95 public: // Unformatted output.
97  _Self& write(const char_type* __s, streamsize __n);
98 
99 public: // Formatted output.
100  // Formatted output from a streambuf.
102 # ifndef _STLP_NO_FUNCTION_TMPL_PARTIAL_ORDER
103  // this is needed for compiling with option char = unsigned
104  _Self& operator<<(unsigned char __x) { _M_put_char(__x); return *this; }
105 # endif
106  _Self& operator<<(short __x);
107  _Self& operator<<(unsigned short __x);
108  _Self& operator<<(int __x);
109 #if defined (_WIN64) || !defined (_STLP_MSVC) || (_STLP_MSVC < 1300)
110  _Self& operator<<(unsigned int __x);
111 #else
112 /* We define this operator with size_t rather than unsigned int to avoid
113  * 64 bits warning.
114  */
115  _Self& operator<<(size_t __x);
116 #endif
117  _Self& operator<<(long __x);
118  _Self& operator<<(unsigned long __x);
119 #ifdef _STLP_LONG_LONG
121  _Self& operator<< (unsigned _STLP_LONG_LONG __x);
122 #endif
123  _Self& operator<<(float __x);
124  _Self& operator<<(double __x);
125 # ifndef _STLP_NO_LONG_DOUBLE
126  _Self& operator<<(long double __x);
127 # endif
128  _Self& operator<<(const void* __x);
129 # ifndef _STLP_NO_BOOL
130  _Self& operator<<(bool __x);
131 # endif
132 
133 public: // Buffer positioning and manipulation.
135  if (this->rdbuf())
136  if (this->rdbuf()->pubsync() == -1)
137  this->setstate(ios_base::badbit);
138  return *this;
139  }
140 
142  return this->rdbuf() && !this->fail()
143  ? this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out)
144  : pos_type(-1);
145  }
146 
147  _Self& seekp(pos_type __pos) {
148  if (this->rdbuf() && !this->fail()) {
149  if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1)) {
150  this->setstate(ios_base::failbit);
151  }
152  }
153  return *this;
154  }
155 
157  if (this->rdbuf() && !this->fail())
158  this->rdbuf()->pubseekoff(__off, __dir, ios_base::out);
159  return *this;
160  }
161 
162 #if defined (_STLP_USE_TEMPLATE_EXPORT)
163  // If we are using DLL specs, we have not to use inner classes
164  // end class declaration here
165  typedef _Osentry<_CharT, _Traits> sentry;
166 };
167 # define sentry _Osentry
168  template <class _CharT, class _Traits>
169  class _Osentry {
170  typedef _Osentry<_CharT, _Traits> _Self;
171 #else
172  class sentry {
173  typedef sentry _Self;
174 #endif
175  private:
177  // basic_streambuf<_CharT, _Traits>* _M_buf;
178  bool _M_ok;
179  public:
181  : _M_str(__str), /* _M_buf(__str.rdbuf()), */ _M_ok(_STLP_PRIV __init_bostr(__str))
182  {}
183 
185  if (_M_str.flags() & ios_base::unitbuf)
187  if (!uncaught_exception())
188 #endif
189  _M_str.flush();
190  }
191 
192  operator bool() const { return _M_ok; }
193  private: // Disable assignment and copy constructor.
194  //Implementation is here only to avoid warning with some compilers.
195  sentry(const _Self& __s) : _M_str(__s._M_str) {}
196  _Self& operator=(const _Self&) { return *this; }
197  };
198 #if defined (_STLP_USE_TEMPLATE_EXPORT)
199 # undef sentry
200 #else
201  // close basic_ostream class definition here
202 };
203 #endif
204 
205 #if defined (_STLP_USE_TEMPLATE_EXPORT)
207 _STLP_EXPORT_TEMPLATE_CLASS _Osentry<char, char_traits<char> >;
208 # if !defined (_STLP_NO_WCHAR_T)
210 _STLP_EXPORT_TEMPLATE_CLASS _Osentry<wchar_t, char_traits<wchar_t> >;
211 # endif
212 #endif /* _STLP_USE_TEMPLATE_EXPORT */
213 
215 
216 // Helper functions for istream<>::sentry constructor.
217 template <class _CharT, class _Traits>
219  if (__str.good()) {
220  // boris : check if this is needed !
221  if (!__str.rdbuf())
222  __str.setstate(ios_base::badbit);
223  if (__str.tie())
224  __str.tie()->flush();
225  return __str.good();
226  }
227  else
228  return false;
229 }
230 
231 template <class _CharT, class _Traits>
234 { return __St.rdbuf(); }
235 
237 
238 // Non-member functions.
239 template <class _CharT, class _Traits>
242  __os._M_put_char(__c);
243  return __os;
244 }
245 
246 template <class _CharT, class _Traits>
248 operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __s) {
249  __os._M_put_nowiden(__s);
250  return __os;
251 }
252 
253 #if defined (_STLP_NO_FUNCTION_TMPL_PARTIAL_ORDER)
254 // some specializations
255 
257 operator<<(basic_ostream<char, char_traits<char> >& __os, char __c) {
258  __os._M_put_char(__c);
259  return __os;
260 }
261 
263 operator<<(basic_ostream<char, char_traits<char> >& __os, signed char __c) {
264  __os._M_put_char(__c);
265  return __os;
266 }
267 
269 operator<<(basic_ostream<char, char_traits<char> >& __os, unsigned char __c) {
270  __os._M_put_char(__c);
271  return __os;
272 }
273 
275 operator<<(basic_ostream<char, char_traits<char> >& __os, const char* __s) {
276  __os._M_put_nowiden(__s);
277  return __os;
278 }
279 
281 operator<<(basic_ostream<char, char_traits<char> >& __os, const signed char* __s) {
282  __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
283  return __os;
284 }
285 
287 operator<<(basic_ostream<char, char_traits<char> >& __os, const unsigned char* __s) {
288  __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
289  return __os;
290 }
291 
292 #else
293 
294 // also for compilers who might use that
295 template <class _CharT, class _Traits>
298  __os._M_put_char(__os.widen(__c));
299  return __os;
300 }
301 
302 template <class _Traits>
305  __os._M_put_char(__c);
306  return __os;
307 }
308 
309 template <class _Traits>
312  __os._M_put_char(__c);
313  return __os;
314 }
315 
316 template <class _Traits>
319  __os._M_put_char(__c);
320  return __os;
321 }
322 
323 template <class _CharT, class _Traits>
326  __os._M_put_widen(__s);
327  return __os;
328 }
329 
330 template <class _Traits>
332 operator<<(basic_ostream<char, _Traits>& __os, const char* __s) {
333  __os._M_put_nowiden(__s);
334  return __os;
335 }
336 
337 template <class _Traits>
339 operator<<(basic_ostream<char, _Traits>& __os, const signed char* __s) {
340  __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
341  return __os;
342 }
343 
344 template <class _Traits>
346 operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __s) {
347  __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
348  return __os;
349 }
350 #endif /* _STLP_NO_FUNCTION_TMPL_PARTIAL_ORDER */
351 
352 //----------------------------------------------------------------------
353 // basic_ostream manipulators.
354 
355 template <class _CharT, class _Traits>
358  __os.put(__os.widen('\n'));
359  __os.flush();
360  return __os;
361 }
362 
363 template <class _CharT, class _Traits>
366  __os.put(_STLP_DEFAULT_CONSTRUCTED(_CharT));
367  return __os;
368 }
369 
370 template <class _CharT, class _Traits>
373  __os.flush();
374  return __os;
375 }
376 
378 
379 #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
380 # include <stl/_ostream.c>
381 #endif
382 
383 #endif /* _STLP_INTERNAL_OSTREAM_H */
384 
385 // Local Variables:
386 // mode:C++
387 // End:
ios_base &(_STLP_CALL * __ios_base_fn)(ios_base &)
Definition: _ostream.h:76
return __n
Definition: _algo.h:75
_Self & put(char_type __c)
Definition: _ostream.c:408
sentry(basic_ostream< _CharT, _Traits > &__str)
Definition: _ostream.h:180
basic_streambuf< _CharT, _Traits > * rdbuf() const
Definition: _ios.h:72
void operator=(const ios_base &)
_STLP_MOVE_TO_STD_NAMESPACE basic_ostream< _CharT, _Traits > &_STLP_CALL operator<<(basic_ostream< _CharT, _Traits > &__os, _CharT __c)
Definition: _ostream.h:241
#define _STLP_NO_UNCAUGHT_EXCEPT_SUPPORT
Definition: _apple.h:104
_Self & operator=(const _Self &)
Definition: _ostream.h:196
_Self & flush()
Definition: _ostream.h:134
bool _M_put_widen_aux(const char *__s, streamsize __n)
Definition: _ostream.c:395
bool fail() const
Definition: _ios_base.h:174
basic_ios< _CharT, _Traits > &(_STLP_CALL * __ios_fn)(basic_ios< _CharT, _Traits > &)
Definition: _ostream.h:75
sentry(const _Self &__s)
Definition: _ostream.h:195
basic_ostream< _CharT, _Traits > _Self
Definition: _ostream.h:54
int seekdir
Definition: _ios_base.h:60
void _M_put_widen(const char *__s)
Definition: _ostream.c:363
void _M_put_char(_CharT __c)
Definition: _ostream.c:300
#define __c
Definition: schilyio.h:209
#define _STLP_MOVE_TO_PRIV_NAMESPACE
Definition: features.h:524
bool _M_copy_unbuffered(basic_streambuf< _CharT, _Traits > *__from, basic_streambuf< _CharT, _Traits > *__to)
Definition: _ostream.c:145
char_traits< char > ::off_type off_type
Definition: _ios.h:54
basic_ostream< _CharT, _Traits > &_STLP_CALL endl(basic_ostream< _CharT, _Traits > &__os)
Definition: _ostream.h:357
_STLP_BEGIN_NAMESPACE _STLP_MOVE_TO_PRIV_NAMESPACE bool __init_bostr(basic_ostream< _CharT, _Traits > &__str)
Definition: _ostream.h:218
bool _M_copy_buffered(basic_streambuf< _CharT, _Traits > *__from, basic_streambuf< _CharT, _Traits > *__to)
Definition: _ostream.c:73
_Self &(_STLP_CALL * __ostream_fn)(_Self &)
Definition: _ostream.h:77
#define _STLP_DEFAULT_CONSTRUCTED(_TTp)
Definition: _construct.h:265
_CharT widen(char) const
Definition: _ios.h:150
#define _STLP_LONG_LONG
Definition: _apcc.h:12
_Traits::int_type int_type
Definition: _ostream.h:64
fmtflags flags() const
Definition: _ios_base.h:107
Definition: _ios.h:48
_Traits traits_type
Definition: _ostream.h:67
typedef bool(CARDLIBPROC *pCanDragProc)(CardRegion &stackobj
basic_ostream< _CharT, _Traits > & _M_str
Definition: _ostream.h:176
#define _STLP_MOVE_TO_STD_NAMESPACE
Definition: features.h:525
_Traits::off_type off_type
Definition: _ostream.h:66
basic_streambuf< _CharT, _Traits > *_STLP_CALL __get_ostreambuf(basic_ostream< _CharT, _Traits > &__St)
Definition: _ostream.h:233
_Self & write(const char_type *__s, streamsize __n)
Definition: _ostream.c:430
basic_ostream(basic_streambuf< _CharT, _Traits > *__buf)
Definition: _ostream.c:37
_CharT char_type
Definition: _ostream.h:63
static FILE * out
Definition: regtests2xml.c:44
#define _STLP_EXPORT_TEMPLATE_CLASS
Definition: features.h:987
_Self & operator<<(unsigned char __x)
Definition: _ostream.h:104
#define _STLP_PRIV
Definition: _dm.h:70
void _M_put_nowiden(const _CharT *__s)
Definition: _ostream.c:331
void setstate(iostate __state)
Definition: _ios.h:95
#define __REINTERPRET_CAST(__x, __y)
Definition: features.h:586
basic_ostream< _CharT, _Traits > &_STLP_CALL ends(basic_ostream< _CharT, _Traits > &__os)
Definition: _ostream.h:365
bool good() const
Definition: _ios_base.h:172
basic_ostream< _CharT, _Traits > * tie() const
Definition: _ios.h:62
_Self & seekp(pos_type __pos)
Definition: _ostream.h:147
_Self & seekp(off_type __off, ios_base::seekdir __dir)
Definition: _ostream.h:156
#define _STLP_END_NAMESPACE
Definition: features.h:503
pos_type tellp()
Definition: _ostream.h:141
basic_ios< _CharT, _Traits > _Basic_ios
Definition: _ostream.h:68
_Self & operator<<(__ostream_fn __f)
Definition: _ostream.h:78
~basic_ostream()
Definition: _ostream.c:43
ptrdiff_t streamsize
Definition: char_traits.h:81
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
_Traits::pos_type pos_type
Definition: _ostream.h:65
#define _STLP_CALL
Definition: _bc.h:131
char_traits< char > ::pos_type pos_type
Definition: _ios.h:53
ios_base &_STLP_CALL unitbuf(ios_base &__s)
Definition: _ios_base.h:303
basic_ostream< _CharT, _Traits > &_STLP_CALL flush(basic_ostream< _CharT, _Traits > &__os)
Definition: _ostream.h:372