epoc32/include/stdapis/stlport/stl/_ostream.h
branchSymbian3
changeset 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/stlport/stl/_ostream.h	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -0,0 +1,411 @@
     1.4 +/*
     1.5 + * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
     1.6 + *
     1.7 + * Copyright (c) 1999
     1.8 + * Silicon Graphics Computer Systems, Inc.
     1.9 + *
    1.10 + * Copyright (c) 1999 
    1.11 + * Boris Fomitchev
    1.12 + *
    1.13 + * This material is provided "as is", with absolutely no warranty expressed
    1.14 + * or implied. Any use is at your own risk.
    1.15 + *
    1.16 + * Permission to use or copy this software for any purpose is hereby granted 
    1.17 + * without fee, provided the above notices are retained on all copies.
    1.18 + * Permission to modify the code and to distribute modified code is granted,
    1.19 + * provided the above notices are retained, and a notice that the code was
    1.20 + * modified is included with the above copyright notice.
    1.21 + *
    1.22 + */ 
    1.23 +
    1.24 +
    1.25 +#ifndef _STLP_INTERNAL_OSTREAM_H
    1.26 +#define _STLP_INTERNAL_OSTREAM_H
    1.27 +
    1.28 +#ifndef _STLP_INTERNAL_IOS_H
    1.29 +# include <stl/_ios.h>                  // For basic_ios<>.  Includes <iosfwd>.
    1.30 +#endif
    1.31 +
    1.32 +#ifndef _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H
    1.33 +# include <stl/_ostreambuf_iterator.h>
    1.34 +#endif
    1.35 +
    1.36 +_STLP_BEGIN_NAMESPACE
    1.37 +
    1.38 +template <class _CharT, class _Traits, class _Number> 
    1.39 +basic_ostream<_CharT, _Traits>& _STLP_CALL
    1.40 +_M_put_num(basic_ostream<_CharT, _Traits>& __os, _Number __x);
    1.41 +
    1.42 +# if defined (_STLP_USE_TEMPLATE_EXPORT)
    1.43 +template <class _CharT, class _Traits>
    1.44 +class _Osentry;
    1.45 +# endif
    1.46 +
    1.47 +template <class _CharT, class _Traits>
    1.48 +bool
    1.49 +_M_init(basic_ostream<_CharT, _Traits>& __str);
    1.50 +
    1.51 +//----------------------------------------------------------------------
    1.52 +// class basic_ostream<>
    1.53 +
    1.54 +template <class _CharT, class _Traits>
    1.55 +class basic_ostream : virtual public basic_ios<_CharT, _Traits>
    1.56 +{
    1.57 +  typedef basic_ostream<_CharT, _Traits> _Self;
    1.58 +  
    1.59 +public:                         // Types
    1.60 +  typedef _CharT                     char_type;
    1.61 +  typedef typename _Traits::int_type int_type;
    1.62 +  typedef typename _Traits::pos_type pos_type;
    1.63 +  typedef typename _Traits::off_type off_type;
    1.64 +  typedef _Traits                    traits_type;
    1.65 +  typedef basic_ios<_CharT, _Traits> _Basic_ios;
    1.66 +
    1.67 +public:                         // Constructor and destructor.
    1.68 +  _STLP_DECLSPEC explicit basic_ostream(basic_streambuf<_CharT, _Traits>* __buf);
    1.69 +  _STLP_DECLSPEC ~basic_ostream();
    1.70 +
    1.71 +public:                         // Hooks for manipulators.
    1.72 +  typedef basic_ios<_CharT, _Traits>& (_STLP_CALL *__ios_fn)(basic_ios<_CharT, _Traits>&);
    1.73 +  typedef ios_base& (_STLP_CALL *__ios_base_fn)(ios_base&);
    1.74 +  typedef _Self& (_STLP_CALL *__ostream_fn)(_Self&);
    1.75 +  _Self& operator<< (__ostream_fn __f) { return __f(*this); }
    1.76 +  _Self & operator<< (__ios_base_fn __f) { __f(*this); return *this; }
    1.77 +  _Self& operator<< (__ios_fn __ff) { __ff(*this); return *this; }
    1.78 +
    1.79 +private:
    1.80 +  bool _M_copy_buffered(basic_streambuf<_CharT, _Traits>* __from,
    1.81 +                        basic_streambuf<_CharT, _Traits>* __to);
    1.82 +  bool _M_copy_unbuffered(basic_streambuf<_CharT, _Traits>* __from,
    1.83 +                          basic_streambuf<_CharT, _Traits>* __to);
    1.84 +
    1.85 +public:
    1.86 +  void _M_put_char(_CharT __c);
    1.87 +
    1.88 +  void _M_put_nowiden(const _CharT* __s);
    1.89 +  void _M_put_widen(const char* __s);
    1.90 +  bool _M_put_widen_aux(const char* __s, streamsize __n);
    1.91 +
    1.92 +public:                         // Unformatted output.
    1.93 +  _Self& put(char_type __c);
    1.94 +  _Self& write(const char_type* __s, streamsize __n);
    1.95 +
    1.96 +public:                         // Formatted output.
    1.97 +  // Formatted output from a streambuf.
    1.98 +  _Self& operator<<(basic_streambuf<_CharT, _Traits>* __buf);
    1.99 +# ifndef _STLP_NO_FUNCTION_TMPL_PARTIAL_ORDER
   1.100 +  // this is needed for compiling with option char = unsigned
   1.101 +  _Self& operator<<(unsigned char __x) { _M_put_char(__x); return *this; }
   1.102 +# endif
   1.103 +#ifdef __SYMBIAN32__
   1.104 +  _Self& operator<<(short __x) 
   1.105 +    { 
   1.106 +	ios_base::fmtflags __fmtf =
   1.107 +		ios_base::flags() & ios_base::basefield;
   1.108 +    long __ly = (__fmtf == ios_base::oct ||  __fmtf == ios_base::hex) ? 
   1.109 +                    (long)(unsigned short)(__x) : (long)__x;
   1.110 +    return _M_put_num(*this,  __ly); 
   1.111 +    }
   1.112 +  _Self& operator<<(int __x) 
   1.113 +  { 
   1.114 +	ios_base::fmtflags __fmtf =
   1.115 +		ios_base::flags() & ios_base::basefield;
   1.116 +    long __ly = (__fmtf == ios_base::oct ||  __fmtf == ios_base::hex) ? 
   1.117 +                    (long)(unsigned int)(__x) : (long)__x;
   1.118 +    return _M_put_num(*this,  __ly); 
   1.119 +  }
   1.120 +#else
   1.121 +  _Self& operator<<(short __x) { return _M_put_num(*this,  __x); }
   1.122 +  _Self& operator<<(int __x) { return _M_put_num(*this,  __x); }
   1.123 +#endif
   1.124 +  _Self& operator<<(unsigned int __x) { return _M_put_num(*this,  __STATIC_CAST(unsigned long,__x)); }
   1.125 +  _Self& operator<<(unsigned short __x) { return _M_put_num(*this,  __STATIC_CAST(unsigned long,__x)); }
   1.126 +  _Self& operator<<(long __x) { return _M_put_num(*this,  __x); }
   1.127 +  _Self& operator<<(unsigned long __x) { return _M_put_num(*this,  __x); }
   1.128 +#ifdef _STLP_LONG_LONG
   1.129 +  _Self& operator<< (_STLP_LONG_LONG __x)     { return _M_put_num(*this,  __x); }
   1.130 +  _Self& operator<< (unsigned _STLP_LONG_LONG __x) { return _M_put_num(*this,  __x); }
   1.131 +#endif 
   1.132 +  _Self& operator<<(float __x)
   1.133 +    { return _M_put_num(*this,  __STATIC_CAST(double,__x)); }
   1.134 +  _Self& operator<<(double __x) { return _M_put_num(*this,  __x); }
   1.135 +# ifndef _STLP_NO_LONG_DOUBLE
   1.136 +  _Self& operator<<(long double __x) { return _M_put_num(*this,  __x); }
   1.137 +# endif
   1.138 +  _Self& operator<<(const void* __x) { return _M_put_num(*this,  __x); }
   1.139 +# ifndef _STLP_NO_BOOL
   1.140 +  _Self& operator<<(bool __x) { return _M_put_num(*this,  __x); }
   1.141 +# endif
   1.142 +
   1.143 +public:                         // Buffer positioning and manipulation.
   1.144 +  _Self& flush() {
   1.145 +    if (this->rdbuf())
   1.146 +      if (this->rdbuf()->pubsync() == -1)
   1.147 +        this->setstate(ios_base::badbit);
   1.148 +    return *this;
   1.149 +  }
   1.150 +
   1.151 +  pos_type tellp() {
   1.152 +    return this->rdbuf() && !this->fail()
   1.153 +      ? this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out)
   1.154 +      : pos_type(-1);
   1.155 +  }
   1.156 +
   1.157 +  _Self& seekp(pos_type __pos) {
   1.158 +    if (this->rdbuf() && !this->fail())
   1.159 +      if( pos_type(off_type(-1)) == this->rdbuf()->pubseekpos(__pos, ios_base::out))
   1.160 +        this->setstate(ios_base::failbit);
   1.161 +    return *this;
   1.162 +  }
   1.163 +
   1.164 +  _Self& seekp(off_type __off, ios_base::seekdir __dir) {
   1.165 +    if (this->rdbuf() && !this->fail())
   1.166 +      if( pos_type(off_type(-1)) == this->rdbuf()->pubseekoff(__off, __dir, ios_base::out))
   1.167 +        this->setstate(ios_base::failbit);
   1.168 +    return *this;
   1.169 +  }
   1.170 +
   1.171 +#if defined (_STLP_USE_TEMPLATE_EXPORT)
   1.172 +  // If we are using DLL specs, we have not to use inner classes
   1.173 +  // end class declaration here
   1.174 +  typedef _Osentry<_CharT, _Traits>  sentry;
   1.175 +};
   1.176 +#  define sentry _Osentry
   1.177 +  template <class _CharT, class _Traits>
   1.178 +  class _Osentry {
   1.179 +    typedef _Osentry<_CharT, _Traits> _Self;
   1.180 +# else
   1.181 +    class sentry {
   1.182 +      typedef sentry _Self;
   1.183 +# endif
   1.184 +    private:
   1.185 +      basic_ostream<_CharT, _Traits>& _M_str;
   1.186 +      //      basic_streambuf<_CharT, _Traits>* _M_buf;
   1.187 +      bool _M_ok;
   1.188 +    public:
   1.189 +      explicit sentry(basic_ostream<_CharT, _Traits>& __str)
   1.190 +        : _M_str(__str), /* _M_buf(__str.rdbuf()), */ _M_ok(_M_init(__str))
   1.191 +      {
   1.192 +      }
   1.193 +      
   1.194 +      ~sentry() {
   1.195 +        if (_M_str.flags() & ios_base::unitbuf)
   1.196 +# ifndef _STLP_INCOMPLETE_EXCEPTION_HEADER 
   1.197 +          if (!_STLP_VENDOR_EXCEPT_STD::uncaught_exception())
   1.198 +# endif
   1.199 +            _M_str.flush();
   1.200 +      }
   1.201 +
   1.202 +      operator bool() const { return _M_ok; }
   1.203 +    private:                        // Disable assignment and copy constructor.
   1.204 +      sentry(const _Self& __s) : _M_str (__s._M_str) {};
   1.205 +      void operator=(const _Self&) {};
   1.206 +    };
   1.207 +# if defined (_STLP_USE_TEMPLATE_EXPORT)
   1.208 +#  undef sentry
   1.209 +# else
   1.210 +  // close basic_ostream class definition here    
   1.211 +};
   1.212 +# endif
   1.213 +  
   1.214 +# if defined (_STLP_USE_TEMPLATE_EXPORT)
   1.215 +_STLP_EXPORT_TEMPLATE_CLASS basic_ostream<char, char_traits<char> >;
   1.216 +_STLP_EXPORT_TEMPLATE_CLASS _Osentry<char, char_traits<char> >;
   1.217 +#  if !defined (_STLP_NO_WCHAR_T)
   1.218 +_STLP_EXPORT_TEMPLATE_CLASS basic_ostream<wchar_t, char_traits<wchar_t> >;
   1.219 +_STLP_EXPORT_TEMPLATE_CLASS _Osentry<wchar_t, char_traits<wchar_t> >;
   1.220 +#  endif
   1.221 +# endif /* _STLP_USE_TEMPLATE_EXPORT */
   1.222 +
   1.223 +template <class _CharT, class _Traits>
   1.224 +inline basic_streambuf<_CharT, _Traits>* _STLP_CALL 
   1.225 +_M_get_ostreambuf(basic_ostream<_CharT, _Traits>& __St) 
   1.226 +{
   1.227 +  return __St.rdbuf();
   1.228 +}
   1.229 +
   1.230 +// Non-member functions.
   1.231 +
   1.232 +template <class _CharT, class _Traits>
   1.233 +inline basic_ostream<_CharT, _Traits>& _STLP_CALL
   1.234 +operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c) {
   1.235 +  __os._M_put_char(__c);
   1.236 +  return __os;
   1.237 +}
   1.238 +
   1.239 +template <class _CharT, class _Traits>
   1.240 +inline basic_ostream<_CharT, _Traits>& _STLP_CALL
   1.241 +operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __s) {
   1.242 +#ifdef __SYMBIAN32__
   1.243 +  !__s ? __os.setstate(ios_base::badbit):__os._M_put_nowiden(__s);
   1.244 +#else
   1.245 +  __os._M_put_nowiden(__s);
   1.246 +#endif
   1.247 +  return __os;
   1.248 +}
   1.249 +
   1.250 +# ifdef _STLP_NO_FUNCTION_TMPL_PARTIAL_ORDER
   1.251 +// some specializations
   1.252 +
   1.253 +inline basic_ostream<char, char_traits<char> >& _STLP_CALL
   1.254 +operator<<(basic_ostream<char, char_traits<char> >& __os, char __c) {
   1.255 +  __os._M_put_char(__c);
   1.256 +  return __os;
   1.257 +}
   1.258 +
   1.259 +inline basic_ostream<char, char_traits<char> >& _STLP_CALL
   1.260 +operator<<(basic_ostream<char, char_traits<char> >& __os, signed char __c) {
   1.261 +  __os._M_put_char(__c);
   1.262 +  return __os;
   1.263 +}
   1.264 +
   1.265 +inline basic_ostream<char, char_traits<char> >& _STLP_CALL
   1.266 +operator<<(basic_ostream<char, char_traits<char> >& __os, unsigned char __c) {
   1.267 +  __os._M_put_char(__c);
   1.268 +  return __os;
   1.269 +}
   1.270 +
   1.271 +inline basic_ostream<char, char_traits<char> >& _STLP_CALL
   1.272 +operator<<(basic_ostream<char, char_traits<char> >& __os, const char* __s) {
   1.273 +#ifdef __SYMBIAN32__
   1.274 +  !__s ? __os.setstate(ios_base::badbit):__os._M_put_nowiden(__s);
   1.275 +#else
   1.276 +  __os._M_put_nowiden(__s);
   1.277 +#endif
   1.278 +  return __os;
   1.279 +}
   1.280 +
   1.281 +inline basic_ostream<char, char_traits<char> >& _STLP_CALL
   1.282 +operator<<(basic_ostream<char, char_traits<char> >& __os, const signed char* __s) {
   1.283 +#ifdef __SYMBIAN32__
   1.284 +   !__s ? __os.setstate(ios_base::badbit):__os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
   1.285 +#else
   1.286 +   __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
   1.287 +#endif
   1.288 +  return __os;
   1.289 +}
   1.290 +
   1.291 +inline basic_ostream<char, char_traits<char> >&
   1.292 +operator<<(basic_ostream<char, char_traits<char> >& __os, const unsigned char* __s) {
   1.293 +#ifdef __SYMBIAN32__
   1.294 +  !__s ? __os.setstate(ios_base::badbit):__os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
   1.295 +#else
   1.296 +  __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
   1.297 +#endif
   1.298 +  return __os;
   1.299 +}
   1.300 +
   1.301 +# else
   1.302 +
   1.303 +// also for compilers who might use that
   1.304 +template <class _CharT, class _Traits>
   1.305 +inline basic_ostream<_CharT, _Traits>& _STLP_CALL
   1.306 +operator<<(basic_ostream<_CharT, _Traits>& __os, char __c) {
   1.307 +  __os._M_put_char(__os.widen(__c));
   1.308 +  return __os;
   1.309 +}
   1.310 +
   1.311 +template <class _Traits>
   1.312 +inline basic_ostream<char, _Traits>& _STLP_CALL
   1.313 +operator<<(basic_ostream<char, _Traits>& __os, char __c) {
   1.314 +  __os._M_put_char(__c);
   1.315 +  return __os;
   1.316 +}
   1.317 +
   1.318 +template <class _Traits>
   1.319 +inline basic_ostream<char, _Traits>& _STLP_CALL
   1.320 +operator<<(basic_ostream<char, _Traits>& __os, signed char __c) {
   1.321 +  __os._M_put_char(__c);
   1.322 +  return __os;
   1.323 +}
   1.324 +
   1.325 +template <class _Traits>
   1.326 +inline basic_ostream<char, _Traits>& _STLP_CALL
   1.327 +operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c) {
   1.328 +  __os._M_put_char(__c);
   1.329 +  return __os;
   1.330 +}
   1.331 +
   1.332 +template <class _CharT, class _Traits>
   1.333 +inline basic_ostream<_CharT, _Traits>& _STLP_CALL
   1.334 +operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __s) {
   1.335 +#ifdef __SYMBIAN32__
   1.336 +  !__s ? __os.setstate(ios_base::badbit):__os._M_put_widen(__s);
   1.337 +#else
   1.338 +  __os._M_put_widen(__s);
   1.339 +#endif
   1.340 +  return __os;
   1.341 +}
   1.342 +
   1.343 +template <class _Traits>
   1.344 +inline basic_ostream<char, _Traits>& _STLP_CALL
   1.345 +operator<<(basic_ostream<char, _Traits>& __os, const char* __s) {
   1.346 +#ifdef __SYMBIAN32__
   1.347 +  !__s ? __os.setstate(ios_base::badbit):__os._M_put_nowiden(__s);
   1.348 +#else
   1.349 +  __os._M_put_nowiden(__s);
   1.350 +#endif
   1.351 +  return __os;
   1.352 +}
   1.353 +
   1.354 +template <class _Traits>
   1.355 +inline basic_ostream<char, _Traits>& _STLP_CALL
   1.356 +operator<<(basic_ostream<char, _Traits>& __os, const signed char* __s) {
   1.357 +#ifdef __SYMBIAN32__
   1.358 +  !__s ? __os.setstate(ios_base::badbit):__os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
   1.359 +#else
   1.360 +  __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
   1.361 +#endif
   1.362 +  return __os;
   1.363 +}
   1.364 +
   1.365 +template <class _Traits>
   1.366 +inline basic_ostream<char, _Traits>&
   1.367 +operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __s) {
   1.368 +#ifdef __SYMBIAN32__
   1.369 +  !__s ? __os.setstate(ios_base::badbit):__os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
   1.370 +#else
   1.371 +  __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
   1.372 +#endif
   1.373 +  return __os;
   1.374 +}
   1.375 +# endif /* _STLP_NO_FUNCTION_TMPL_PARTIAL_ORDER */
   1.376 +
   1.377 +//----------------------------------------------------------------------
   1.378 +// basic_ostream manipulators.
   1.379 +
   1.380 +template <class _CharT, class _Traits>
   1.381 +inline basic_ostream<_CharT, _Traits>& _STLP_CALL
   1.382 +endl(basic_ostream<_CharT, _Traits>& __os) {
   1.383 +  __os.put(__os.widen('\n'));
   1.384 +  __os.flush();
   1.385 +  return __os;
   1.386 +}
   1.387 +
   1.388 +template <class _CharT, class _Traits>
   1.389 +inline basic_ostream<_CharT, _Traits>& _STLP_CALL
   1.390 +ends(basic_ostream<_CharT, _Traits>& __os) {
   1.391 +  __os.put(_STLP_DEFAULT_CONSTRUCTED(_CharT));
   1.392 +  return __os;
   1.393 +}
   1.394 +
   1.395 +template <class _CharT, class _Traits>
   1.396 +inline basic_ostream<_CharT, _Traits>& _STLP_CALL
   1.397 +flush(basic_ostream<_CharT, _Traits>& __os) {
   1.398 +  __os.flush();
   1.399 +  return __os;
   1.400 +}
   1.401 +
   1.402 +_STLP_END_NAMESPACE
   1.403 +
   1.404 +#  undef _STLP_MANIP_INLINE
   1.405 +
   1.406 +#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
   1.407 +#  include <stl/_ostream.c>
   1.408 +# endif
   1.409 +
   1.410 +#endif /* _STLP_INTERNAL_OSTREAM_H */
   1.411 +
   1.412 +// Local Variables:
   1.413 +// mode:C++
   1.414 +// End: