epoc32/include/stdapis/stlport/stl/_ostream.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 /*
     2  * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
     3  *
     4  * Copyright (c) 1999
     5  * Silicon Graphics Computer Systems, Inc.
     6  *
     7  * Copyright (c) 1999 
     8  * Boris Fomitchev
     9  *
    10  * This material is provided "as is", with absolutely no warranty expressed
    11  * or implied. Any use is at your own risk.
    12  *
    13  * Permission to use or copy this software for any purpose is hereby granted 
    14  * without fee, provided the above notices are retained on all copies.
    15  * Permission to modify the code and to distribute modified code is granted,
    16  * provided the above notices are retained, and a notice that the code was
    17  * modified is included with the above copyright notice.
    18  *
    19  */ 
    20 
    21 
    22 #ifndef _STLP_INTERNAL_OSTREAM_H
    23 #define _STLP_INTERNAL_OSTREAM_H
    24 
    25 #ifndef _STLP_INTERNAL_IOS_H
    26 # include <stl/_ios.h>                  // For basic_ios<>.  Includes <iosfwd>.
    27 #endif
    28 
    29 #ifndef _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H
    30 # include <stl/_ostreambuf_iterator.h>
    31 #endif
    32 
    33 _STLP_BEGIN_NAMESPACE
    34 
    35 template <class _CharT, class _Traits, class _Number> 
    36 basic_ostream<_CharT, _Traits>& _STLP_CALL
    37 _M_put_num(basic_ostream<_CharT, _Traits>& __os, _Number __x);
    38 
    39 # if defined (_STLP_USE_TEMPLATE_EXPORT)
    40 template <class _CharT, class _Traits>
    41 class _Osentry;
    42 # endif
    43 
    44 template <class _CharT, class _Traits>
    45 bool
    46 _M_init(basic_ostream<_CharT, _Traits>& __str);
    47 
    48 //----------------------------------------------------------------------
    49 // class basic_ostream<>
    50 
    51 template <class _CharT, class _Traits>
    52 class basic_ostream : virtual public basic_ios<_CharT, _Traits>
    53 {
    54   typedef basic_ostream<_CharT, _Traits> _Self;
    55   
    56 public:                         // Types
    57   typedef _CharT                     char_type;
    58   typedef typename _Traits::int_type int_type;
    59   typedef typename _Traits::pos_type pos_type;
    60   typedef typename _Traits::off_type off_type;
    61   typedef _Traits                    traits_type;
    62   typedef basic_ios<_CharT, _Traits> _Basic_ios;
    63 
    64 public:                         // Constructor and destructor.
    65   _STLP_DECLSPEC explicit basic_ostream(basic_streambuf<_CharT, _Traits>* __buf);
    66   _STLP_DECLSPEC ~basic_ostream();
    67 
    68 public:                         // Hooks for manipulators.
    69   typedef basic_ios<_CharT, _Traits>& (_STLP_CALL *__ios_fn)(basic_ios<_CharT, _Traits>&);
    70   typedef ios_base& (_STLP_CALL *__ios_base_fn)(ios_base&);
    71   typedef _Self& (_STLP_CALL *__ostream_fn)(_Self&);
    72   _Self& operator<< (__ostream_fn __f) { return __f(*this); }
    73   _Self & operator<< (__ios_base_fn __f) { __f(*this); return *this; }
    74   _Self& operator<< (__ios_fn __ff) { __ff(*this); return *this; }
    75 
    76 private:
    77   bool _M_copy_buffered(basic_streambuf<_CharT, _Traits>* __from,
    78                         basic_streambuf<_CharT, _Traits>* __to);
    79   bool _M_copy_unbuffered(basic_streambuf<_CharT, _Traits>* __from,
    80                           basic_streambuf<_CharT, _Traits>* __to);
    81 
    82 public:
    83   void _M_put_char(_CharT __c);
    84 
    85   void _M_put_nowiden(const _CharT* __s);
    86   void _M_put_widen(const char* __s);
    87   bool _M_put_widen_aux(const char* __s, streamsize __n);
    88 
    89 public:                         // Unformatted output.
    90   _Self& put(char_type __c);
    91   _Self& write(const char_type* __s, streamsize __n);
    92 
    93 public:                         // Formatted output.
    94   // Formatted output from a streambuf.
    95   _Self& operator<<(basic_streambuf<_CharT, _Traits>* __buf);
    96 # ifndef _STLP_NO_FUNCTION_TMPL_PARTIAL_ORDER
    97   // this is needed for compiling with option char = unsigned
    98   _Self& operator<<(unsigned char __x) { _M_put_char(__x); return *this; }
    99 # endif
   100 #ifdef __SYMBIAN32__
   101   _Self& operator<<(short __x) 
   102     { 
   103 	ios_base::fmtflags __fmtf =
   104 		ios_base::flags() & ios_base::basefield;
   105     long __ly = (__fmtf == ios_base::oct ||  __fmtf == ios_base::hex) ? 
   106                     (long)(unsigned short)(__x) : (long)__x;
   107     return _M_put_num(*this,  __ly); 
   108     }
   109   _Self& operator<<(int __x) 
   110   { 
   111 	ios_base::fmtflags __fmtf =
   112 		ios_base::flags() & ios_base::basefield;
   113     long __ly = (__fmtf == ios_base::oct ||  __fmtf == ios_base::hex) ? 
   114                     (long)(unsigned int)(__x) : (long)__x;
   115     return _M_put_num(*this,  __ly); 
   116   }
   117 #else
   118   _Self& operator<<(short __x) { return _M_put_num(*this,  __x); }
   119   _Self& operator<<(int __x) { return _M_put_num(*this,  __x); }
   120 #endif
   121   _Self& operator<<(unsigned int __x) { return _M_put_num(*this,  __STATIC_CAST(unsigned long,__x)); }
   122   _Self& operator<<(unsigned short __x) { return _M_put_num(*this,  __STATIC_CAST(unsigned long,__x)); }
   123   _Self& operator<<(long __x) { return _M_put_num(*this,  __x); }
   124   _Self& operator<<(unsigned long __x) { return _M_put_num(*this,  __x); }
   125 #ifdef _STLP_LONG_LONG
   126   _Self& operator<< (_STLP_LONG_LONG __x)     { return _M_put_num(*this,  __x); }
   127   _Self& operator<< (unsigned _STLP_LONG_LONG __x) { return _M_put_num(*this,  __x); }
   128 #endif 
   129   _Self& operator<<(float __x)
   130     { return _M_put_num(*this,  __STATIC_CAST(double,__x)); }
   131   _Self& operator<<(double __x) { return _M_put_num(*this,  __x); }
   132 # ifndef _STLP_NO_LONG_DOUBLE
   133   _Self& operator<<(long double __x) { return _M_put_num(*this,  __x); }
   134 # endif
   135   _Self& operator<<(const void* __x) { return _M_put_num(*this,  __x); }
   136 # ifndef _STLP_NO_BOOL
   137   _Self& operator<<(bool __x) { return _M_put_num(*this,  __x); }
   138 # endif
   139 
   140 public:                         // Buffer positioning and manipulation.
   141   _Self& flush() {
   142     if (this->rdbuf())
   143       if (this->rdbuf()->pubsync() == -1)
   144         this->setstate(ios_base::badbit);
   145     return *this;
   146   }
   147 
   148   pos_type tellp() {
   149     return this->rdbuf() && !this->fail()
   150       ? this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out)
   151       : pos_type(-1);
   152   }
   153 
   154   _Self& seekp(pos_type __pos) {
   155     if (this->rdbuf() && !this->fail())
   156       if( pos_type(off_type(-1)) == this->rdbuf()->pubseekpos(__pos, ios_base::out))
   157         this->setstate(ios_base::failbit);
   158     return *this;
   159   }
   160 
   161   _Self& seekp(off_type __off, ios_base::seekdir __dir) {
   162     if (this->rdbuf() && !this->fail())
   163       if( pos_type(off_type(-1)) == this->rdbuf()->pubseekoff(__off, __dir, ios_base::out))
   164         this->setstate(ios_base::failbit);
   165     return *this;
   166   }
   167 
   168 #if defined (_STLP_USE_TEMPLATE_EXPORT)
   169   // If we are using DLL specs, we have not to use inner classes
   170   // end class declaration here
   171   typedef _Osentry<_CharT, _Traits>  sentry;
   172 };
   173 #  define sentry _Osentry
   174   template <class _CharT, class _Traits>
   175   class _Osentry {
   176     typedef _Osentry<_CharT, _Traits> _Self;
   177 # else
   178     class sentry {
   179       typedef sentry _Self;
   180 # endif
   181     private:
   182       basic_ostream<_CharT, _Traits>& _M_str;
   183       //      basic_streambuf<_CharT, _Traits>* _M_buf;
   184       bool _M_ok;
   185     public:
   186       explicit sentry(basic_ostream<_CharT, _Traits>& __str)
   187         : _M_str(__str), /* _M_buf(__str.rdbuf()), */ _M_ok(_M_init(__str))
   188       {
   189       }
   190       
   191       ~sentry() {
   192         if (_M_str.flags() & ios_base::unitbuf)
   193 # ifndef _STLP_INCOMPLETE_EXCEPTION_HEADER 
   194           if (!_STLP_VENDOR_EXCEPT_STD::uncaught_exception())
   195 # endif
   196             _M_str.flush();
   197       }
   198 
   199       operator bool() const { return _M_ok; }
   200     private:                        // Disable assignment and copy constructor.
   201       sentry(const _Self& __s) : _M_str (__s._M_str) {};
   202       void operator=(const _Self&) {};
   203     };
   204 # if defined (_STLP_USE_TEMPLATE_EXPORT)
   205 #  undef sentry
   206 # else
   207   // close basic_ostream class definition here    
   208 };
   209 # endif
   210   
   211 # if defined (_STLP_USE_TEMPLATE_EXPORT)
   212 _STLP_EXPORT_TEMPLATE_CLASS basic_ostream<char, char_traits<char> >;
   213 _STLP_EXPORT_TEMPLATE_CLASS _Osentry<char, char_traits<char> >;
   214 #  if !defined (_STLP_NO_WCHAR_T)
   215 _STLP_EXPORT_TEMPLATE_CLASS basic_ostream<wchar_t, char_traits<wchar_t> >;
   216 _STLP_EXPORT_TEMPLATE_CLASS _Osentry<wchar_t, char_traits<wchar_t> >;
   217 #  endif
   218 # endif /* _STLP_USE_TEMPLATE_EXPORT */
   219 
   220 template <class _CharT, class _Traits>
   221 inline basic_streambuf<_CharT, _Traits>* _STLP_CALL 
   222 _M_get_ostreambuf(basic_ostream<_CharT, _Traits>& __St) 
   223 {
   224   return __St.rdbuf();
   225 }
   226 
   227 // Non-member functions.
   228 
   229 template <class _CharT, class _Traits>
   230 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
   231 operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c) {
   232   __os._M_put_char(__c);
   233   return __os;
   234 }
   235 
   236 template <class _CharT, class _Traits>
   237 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
   238 operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __s) {
   239 #ifdef __SYMBIAN32__
   240   !__s ? __os.setstate(ios_base::badbit):__os._M_put_nowiden(__s);
   241 #else
   242   __os._M_put_nowiden(__s);
   243 #endif
   244   return __os;
   245 }
   246 
   247 # ifdef _STLP_NO_FUNCTION_TMPL_PARTIAL_ORDER
   248 // some specializations
   249 
   250 inline basic_ostream<char, char_traits<char> >& _STLP_CALL
   251 operator<<(basic_ostream<char, char_traits<char> >& __os, char __c) {
   252   __os._M_put_char(__c);
   253   return __os;
   254 }
   255 
   256 inline basic_ostream<char, char_traits<char> >& _STLP_CALL
   257 operator<<(basic_ostream<char, char_traits<char> >& __os, signed char __c) {
   258   __os._M_put_char(__c);
   259   return __os;
   260 }
   261 
   262 inline basic_ostream<char, char_traits<char> >& _STLP_CALL
   263 operator<<(basic_ostream<char, char_traits<char> >& __os, unsigned char __c) {
   264   __os._M_put_char(__c);
   265   return __os;
   266 }
   267 
   268 inline basic_ostream<char, char_traits<char> >& _STLP_CALL
   269 operator<<(basic_ostream<char, char_traits<char> >& __os, const char* __s) {
   270 #ifdef __SYMBIAN32__
   271   !__s ? __os.setstate(ios_base::badbit):__os._M_put_nowiden(__s);
   272 #else
   273   __os._M_put_nowiden(__s);
   274 #endif
   275   return __os;
   276 }
   277 
   278 inline basic_ostream<char, char_traits<char> >& _STLP_CALL
   279 operator<<(basic_ostream<char, char_traits<char> >& __os, const signed char* __s) {
   280 #ifdef __SYMBIAN32__
   281    !__s ? __os.setstate(ios_base::badbit):__os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
   282 #else
   283    __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
   284 #endif
   285   return __os;
   286 }
   287 
   288 inline basic_ostream<char, char_traits<char> >&
   289 operator<<(basic_ostream<char, char_traits<char> >& __os, const unsigned char* __s) {
   290 #ifdef __SYMBIAN32__
   291   !__s ? __os.setstate(ios_base::badbit):__os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
   292 #else
   293   __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
   294 #endif
   295   return __os;
   296 }
   297 
   298 # else
   299 
   300 // also for compilers who might use that
   301 template <class _CharT, class _Traits>
   302 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
   303 operator<<(basic_ostream<_CharT, _Traits>& __os, char __c) {
   304   __os._M_put_char(__os.widen(__c));
   305   return __os;
   306 }
   307 
   308 template <class _Traits>
   309 inline basic_ostream<char, _Traits>& _STLP_CALL
   310 operator<<(basic_ostream<char, _Traits>& __os, char __c) {
   311   __os._M_put_char(__c);
   312   return __os;
   313 }
   314 
   315 template <class _Traits>
   316 inline basic_ostream<char, _Traits>& _STLP_CALL
   317 operator<<(basic_ostream<char, _Traits>& __os, signed char __c) {
   318   __os._M_put_char(__c);
   319   return __os;
   320 }
   321 
   322 template <class _Traits>
   323 inline basic_ostream<char, _Traits>& _STLP_CALL
   324 operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c) {
   325   __os._M_put_char(__c);
   326   return __os;
   327 }
   328 
   329 template <class _CharT, class _Traits>
   330 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
   331 operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __s) {
   332 #ifdef __SYMBIAN32__
   333   !__s ? __os.setstate(ios_base::badbit):__os._M_put_widen(__s);
   334 #else
   335   __os._M_put_widen(__s);
   336 #endif
   337   return __os;
   338 }
   339 
   340 template <class _Traits>
   341 inline basic_ostream<char, _Traits>& _STLP_CALL
   342 operator<<(basic_ostream<char, _Traits>& __os, const char* __s) {
   343 #ifdef __SYMBIAN32__
   344   !__s ? __os.setstate(ios_base::badbit):__os._M_put_nowiden(__s);
   345 #else
   346   __os._M_put_nowiden(__s);
   347 #endif
   348   return __os;
   349 }
   350 
   351 template <class _Traits>
   352 inline basic_ostream<char, _Traits>& _STLP_CALL
   353 operator<<(basic_ostream<char, _Traits>& __os, const signed char* __s) {
   354 #ifdef __SYMBIAN32__
   355   !__s ? __os.setstate(ios_base::badbit):__os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
   356 #else
   357   __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
   358 #endif
   359   return __os;
   360 }
   361 
   362 template <class _Traits>
   363 inline basic_ostream<char, _Traits>&
   364 operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __s) {
   365 #ifdef __SYMBIAN32__
   366   !__s ? __os.setstate(ios_base::badbit):__os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
   367 #else
   368   __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
   369 #endif
   370   return __os;
   371 }
   372 # endif /* _STLP_NO_FUNCTION_TMPL_PARTIAL_ORDER */
   373 
   374 //----------------------------------------------------------------------
   375 // basic_ostream manipulators.
   376 
   377 template <class _CharT, class _Traits>
   378 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
   379 endl(basic_ostream<_CharT, _Traits>& __os) {
   380   __os.put(__os.widen('\n'));
   381   __os.flush();
   382   return __os;
   383 }
   384 
   385 template <class _CharT, class _Traits>
   386 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
   387 ends(basic_ostream<_CharT, _Traits>& __os) {
   388   __os.put(_STLP_DEFAULT_CONSTRUCTED(_CharT));
   389   return __os;
   390 }
   391 
   392 template <class _CharT, class _Traits>
   393 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
   394 flush(basic_ostream<_CharT, _Traits>& __os) {
   395   __os.flush();
   396   return __os;
   397 }
   398 
   399 _STLP_END_NAMESPACE
   400 
   401 #  undef _STLP_MANIP_INLINE
   402 
   403 #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
   404 #  include <stl/_ostream.c>
   405 # endif
   406 
   407 #endif /* _STLP_INTERNAL_OSTREAM_H */
   408 
   409 // Local Variables:
   410 // mode:C++
   411 // End: