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