ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

_ostream.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */
00018 
00019 
00020 #ifndef _STLP_INTERNAL_OSTREAM_H
00021 #define _STLP_INTERNAL_OSTREAM_H
00022 
00023 #ifndef _STLP_INTERNAL_IOS_H
00024 #  include <stl/_ios.h>                  // For basic_ios<>.  Includes <iosfwd>.
00025 #endif
00026 
00027 #ifndef _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H
00028 #  include <stl/_ostreambuf_iterator.h>
00029 #endif
00030 
00031 #if !defined (_STLP_NO_UNCAUGHT_EXCEPT_SUPPORT) && !defined (_STLP_INTERNAL_EXCEPTION)
00032 #  include <stl/_exception.h>
00033 #endif
00034 
00035 _STLP_BEGIN_NAMESPACE
00036 
00037 #if defined (_STLP_USE_TEMPLATE_EXPORT)
00038 template <class _CharT, class _Traits>
00039 class _Osentry;
00040 #endif
00041 
00042 _STLP_MOVE_TO_PRIV_NAMESPACE
00043 
00044 template <class _CharT, class _Traits>
00045 bool __init_bostr(basic_ostream<_CharT, _Traits>& __str);
00046 
00047 _STLP_MOVE_TO_STD_NAMESPACE
00048 
00049 //----------------------------------------------------------------------
00050 // class basic_ostream<>
00051 
00052 template <class _CharT, class _Traits>
00053 class basic_ostream : virtual public basic_ios<_CharT, _Traits> {
00054   typedef basic_ostream<_CharT, _Traits> _Self;
00055 
00056 #if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310)
00057   //explicitely defined as private to avoid warnings:
00058   basic_ostream(_Self const&);
00059   _Self& operator = (_Self const&);
00060 #endif
00061 
00062 public:                         // Types
00063   typedef _CharT                     char_type;
00064   typedef typename _Traits::int_type int_type;
00065   typedef typename _Traits::pos_type pos_type;
00066   typedef typename _Traits::off_type off_type;
00067   typedef _Traits                    traits_type;
00068   typedef basic_ios<_CharT, _Traits> _Basic_ios;
00069 
00070 public:                         // Constructor and destructor.
00071   explicit basic_ostream(basic_streambuf<_CharT, _Traits>* __buf);
00072   ~basic_ostream();
00073 
00074 public:                         // Hooks for manipulators.
00075   typedef basic_ios<_CharT, _Traits>& (_STLP_CALL *__ios_fn)(basic_ios<_CharT, _Traits>&);
00076   typedef ios_base& (_STLP_CALL *__ios_base_fn)(ios_base&);
00077   typedef _Self& (_STLP_CALL *__ostream_fn)(_Self&);
00078   _Self& operator<< (__ostream_fn __f) { return __f(*this); }
00079   _Self & operator<< (__ios_base_fn __f) { __f(*this); return *this; }
00080   _Self& operator<< (__ios_fn __ff) { __ff(*this); return *this; }
00081 
00082 private:
00083   bool _M_copy_buffered(basic_streambuf<_CharT, _Traits>* __from,
00084                         basic_streambuf<_CharT, _Traits>* __to);
00085   bool _M_copy_unbuffered(basic_streambuf<_CharT, _Traits>* __from,
00086                           basic_streambuf<_CharT, _Traits>* __to);
00087 
00088 public:
00089   void _M_put_char(_CharT __c);
00090 
00091   void _M_put_nowiden(const _CharT* __s);
00092   void _M_put_widen(const char* __s);
00093   bool _M_put_widen_aux(const char* __s, streamsize __n);
00094 
00095 public:                         // Unformatted output.
00096   _Self& put(char_type __c);
00097   _Self& write(const char_type* __s, streamsize __n);
00098 
00099 public:                         // Formatted output.
00100   // Formatted output from a streambuf.
00101   _Self& operator<<(basic_streambuf<_CharT, _Traits>* __buf);
00102 # ifndef _STLP_NO_FUNCTION_TMPL_PARTIAL_ORDER
00103   // this is needed for compiling with option char = unsigned
00104   _Self& operator<<(unsigned char __x) { _M_put_char(__x); return *this; }
00105 # endif
00106   _Self& operator<<(short __x);
00107   _Self& operator<<(unsigned short __x);
00108   _Self& operator<<(int __x);
00109 #if defined (_WIN64) || !defined (_STLP_MSVC) || (_STLP_MSVC < 1300)
00110   _Self& operator<<(unsigned int __x);
00111 #else
00112 /* We define this operator with size_t rather than unsigned int to avoid
00113  * 64 bits warning.
00114  */
00115   _Self& operator<<(size_t __x);
00116 #endif
00117   _Self& operator<<(long __x);
00118   _Self& operator<<(unsigned long __x);
00119 #ifdef _STLP_LONG_LONG
00120   _Self& operator<< (_STLP_LONG_LONG __x);
00121   _Self& operator<< (unsigned _STLP_LONG_LONG __x);
00122 #endif
00123   _Self& operator<<(float __x);
00124   _Self& operator<<(double __x);
00125 # ifndef _STLP_NO_LONG_DOUBLE
00126   _Self& operator<<(long double __x);
00127 # endif
00128   _Self& operator<<(const void* __x);
00129 # ifndef _STLP_NO_BOOL
00130   _Self& operator<<(bool __x);
00131 # endif
00132 
00133 public:                         // Buffer positioning and manipulation.
00134   _Self& flush() {
00135     if (this->rdbuf())
00136       if (this->rdbuf()->pubsync() == -1)
00137         this->setstate(ios_base::badbit);
00138     return *this;
00139   }
00140 
00141   pos_type tellp() {
00142     return this->rdbuf() && !this->fail()
00143       ? this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out)
00144       : pos_type(-1);
00145   }
00146 
00147   _Self& seekp(pos_type __pos) {
00148     if (this->rdbuf() && !this->fail()) {
00149       if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1)) {
00150         this->setstate(ios_base::failbit);
00151       }
00152     }
00153     return *this;
00154   }
00155 
00156   _Self& seekp(off_type __off, ios_base::seekdir __dir) {
00157     if (this->rdbuf() && !this->fail())
00158       this->rdbuf()->pubseekoff(__off, __dir, ios_base::out);
00159     return *this;
00160   }
00161 
00162 #if defined (_STLP_USE_TEMPLATE_EXPORT)
00163   // If we are using DLL specs, we have not to use inner classes
00164   // end class declaration here
00165   typedef _Osentry<_CharT, _Traits>  sentry;
00166 };
00167 #  define sentry _Osentry
00168   template <class _CharT, class _Traits>
00169   class _Osentry {
00170     typedef _Osentry<_CharT, _Traits> _Self;
00171 #else
00172     class sentry {
00173       typedef sentry _Self;
00174 #endif
00175     private:
00176       basic_ostream<_CharT, _Traits>& _M_str;
00177       //      basic_streambuf<_CharT, _Traits>* _M_buf;
00178       bool _M_ok;
00179     public:
00180       explicit sentry(basic_ostream<_CharT, _Traits>& __str)
00181         : _M_str(__str), /* _M_buf(__str.rdbuf()), */ _M_ok(_STLP_PRIV __init_bostr(__str))
00182       {}
00183 
00184       ~sentry() {
00185         if (_M_str.flags() & ios_base::unitbuf)
00186 #if !defined (_STLP_NO_UNCAUGHT_EXCEPT_SUPPORT)
00187           if (!uncaught_exception())
00188 #endif
00189             _M_str.flush();
00190       }
00191 
00192       operator bool() const { return _M_ok; }
00193     private:                        // Disable assignment and copy constructor.
00194       //Implementation is here only to avoid warning with some compilers.
00195       sentry(const _Self& __s) : _M_str(__s._M_str) {}
00196       _Self& operator=(const _Self&) { return *this; }
00197     };
00198 #if defined (_STLP_USE_TEMPLATE_EXPORT)
00199 #  undef sentry
00200 #else
00201   // close basic_ostream class definition here
00202 };
00203 #endif
00204 
00205 #if defined (_STLP_USE_TEMPLATE_EXPORT)
00206 _STLP_EXPORT_TEMPLATE_CLASS basic_ostream<char, char_traits<char> >;
00207 _STLP_EXPORT_TEMPLATE_CLASS _Osentry<char, char_traits<char> >;
00208 #  if !defined (_STLP_NO_WCHAR_T)
00209 _STLP_EXPORT_TEMPLATE_CLASS basic_ostream<wchar_t, char_traits<wchar_t> >;
00210 _STLP_EXPORT_TEMPLATE_CLASS _Osentry<wchar_t, char_traits<wchar_t> >;
00211 #  endif
00212 #endif /* _STLP_USE_TEMPLATE_EXPORT */
00213 
00214 _STLP_MOVE_TO_PRIV_NAMESPACE
00215 
00216 // Helper functions for istream<>::sentry constructor.
00217 template <class _CharT, class _Traits>
00218 bool __init_bostr(basic_ostream<_CharT, _Traits>& __str) {
00219   if (__str.good()) {
00220     // boris : check if this is needed !
00221     if (!__str.rdbuf())
00222       __str.setstate(ios_base::badbit);
00223     if (__str.tie())
00224       __str.tie()->flush();
00225     return __str.good();
00226   }
00227   else
00228     return false;
00229 }
00230 
00231 template <class _CharT, class _Traits>
00232 inline basic_streambuf<_CharT, _Traits>* _STLP_CALL
00233 __get_ostreambuf(basic_ostream<_CharT, _Traits>& __St)
00234 { return __St.rdbuf(); }
00235 
00236 _STLP_MOVE_TO_STD_NAMESPACE
00237 
00238 // Non-member functions.
00239 template <class _CharT, class _Traits>
00240 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
00241 operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c){
00242   __os._M_put_char(__c);
00243   return __os;
00244 }
00245 
00246 template <class _CharT, class _Traits>
00247 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
00248 operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __s) {
00249   __os._M_put_nowiden(__s);
00250   return __os;
00251 }
00252 
00253 #if defined (_STLP_NO_FUNCTION_TMPL_PARTIAL_ORDER)
00254 // some specializations
00255 
00256 inline basic_ostream<char, char_traits<char> >& _STLP_CALL
00257 operator<<(basic_ostream<char, char_traits<char> >& __os, char __c) {
00258   __os._M_put_char(__c);
00259   return __os;
00260 }
00261 
00262 inline basic_ostream<char, char_traits<char> >& _STLP_CALL
00263 operator<<(basic_ostream<char, char_traits<char> >& __os, signed char __c) {
00264   __os._M_put_char(__c);
00265   return __os;
00266 }
00267 
00268 inline basic_ostream<char, char_traits<char> >& _STLP_CALL
00269 operator<<(basic_ostream<char, char_traits<char> >& __os, unsigned char __c) {
00270   __os._M_put_char(__c);
00271   return __os;
00272 }
00273 
00274 inline basic_ostream<char, char_traits<char> >& _STLP_CALL
00275 operator<<(basic_ostream<char, char_traits<char> >& __os, const char* __s) {
00276   __os._M_put_nowiden(__s);
00277   return __os;
00278 }
00279 
00280 inline basic_ostream<char, char_traits<char> >& _STLP_CALL
00281 operator<<(basic_ostream<char, char_traits<char> >& __os, const signed char* __s) {
00282   __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
00283   return __os;
00284 }
00285 
00286 inline basic_ostream<char, char_traits<char> >&
00287 operator<<(basic_ostream<char, char_traits<char> >& __os, const unsigned char* __s) {
00288   __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
00289   return __os;
00290 }
00291 
00292 #else
00293 
00294 // also for compilers who might use that
00295 template <class _CharT, class _Traits>
00296 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
00297 operator<<(basic_ostream<_CharT, _Traits>& __os, char __c) {
00298   __os._M_put_char(__os.widen(__c));
00299   return __os;
00300 }
00301 
00302 template <class _Traits>
00303 inline basic_ostream<char, _Traits>& _STLP_CALL
00304 operator<<(basic_ostream<char, _Traits>& __os, char __c) {
00305   __os._M_put_char(__c);
00306   return __os;
00307 }
00308 
00309 template <class _Traits>
00310 inline basic_ostream<char, _Traits>& _STLP_CALL
00311 operator<<(basic_ostream<char, _Traits>& __os, signed char __c) {
00312   __os._M_put_char(__c);
00313   return __os;
00314 }
00315 
00316 template <class _Traits>
00317 inline basic_ostream<char, _Traits>& _STLP_CALL
00318 operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c) {
00319   __os._M_put_char(__c);
00320   return __os;
00321 }
00322 
00323 template <class _CharT, class _Traits>
00324 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
00325 operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __s) {
00326   __os._M_put_widen(__s);
00327   return __os;
00328 }
00329 
00330 template <class _Traits>
00331 inline basic_ostream<char, _Traits>& _STLP_CALL
00332 operator<<(basic_ostream<char, _Traits>& __os, const char* __s) {
00333   __os._M_put_nowiden(__s);
00334   return __os;
00335 }
00336 
00337 template <class _Traits>
00338 inline basic_ostream<char, _Traits>& _STLP_CALL
00339 operator<<(basic_ostream<char, _Traits>& __os, const signed char* __s) {
00340   __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
00341   return __os;
00342 }
00343 
00344 template <class _Traits>
00345 inline basic_ostream<char, _Traits>&
00346 operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __s) {
00347   __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
00348   return __os;
00349 }
00350 #endif /* _STLP_NO_FUNCTION_TMPL_PARTIAL_ORDER */
00351 
00352 //----------------------------------------------------------------------
00353 // basic_ostream manipulators.
00354 
00355 template <class _CharT, class _Traits>
00356 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
00357 endl(basic_ostream<_CharT, _Traits>& __os) {
00358   __os.put(__os.widen('\n'));
00359   __os.flush();
00360   return __os;
00361 }
00362 
00363 template <class _CharT, class _Traits>
00364 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
00365 ends(basic_ostream<_CharT, _Traits>& __os) {
00366   __os.put(_STLP_DEFAULT_CONSTRUCTED(_CharT));
00367   return __os;
00368 }
00369 
00370 template <class _CharT, class _Traits>
00371 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
00372 flush(basic_ostream<_CharT, _Traits>& __os) {
00373   __os.flush();
00374   return __os;
00375 }
00376 
00377 _STLP_END_NAMESPACE
00378 
00379 #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
00380 #  include <stl/_ostream.c>
00381 #endif
00382 
00383 #endif /* _STLP_INTERNAL_OSTREAM_H */
00384 
00385 // Local Variables:
00386 // mode:C++
00387 // End:

Generated on Fri May 25 2012 04:27:53 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.