epoc32/include/stdapis/stlportv5/stl/_istream.h
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
     1.1 --- a/epoc32/include/stdapis/stlportv5/stl/_istream.h	Wed Mar 31 12:27:01 2010 +0100
     1.2 +++ b/epoc32/include/stdapis/stlportv5/stl/_istream.h	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -1,49 +1,44 @@
     1.4  /*
     1.5 - * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
     1.6   * Copyright (c) 1999
     1.7   * Silicon Graphics Computer Systems, Inc.
     1.8   *
     1.9 - * Copyright (c) 1999 
    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 + * 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 -#ifndef _STLP_INTERNAL_ISTREAM_H
    1.25 -#define _STLP_INTERNAL_ISTREAM_H
    1.26 + */
    1.27 +#ifndef _STLP_INTERNAL_ISTREAM
    1.28 +#define _STLP_INTERNAL_ISTREAM
    1.29  
    1.30  // this block is included by _ostream.h, we include it here to lower #include level
    1.31 -# if defined (_STLP_HAS_WCHAR_T) && !defined (_STLP_CWCHAR_H)
    1.32 +#if defined (_STLP_HAS_WCHAR_T) && !defined (_STLP_INTERNAL_CWCHAR)
    1.33  #  include <stl/_cwchar.h>
    1.34 -# endif
    1.35 +#endif
    1.36  
    1.37 -# ifndef _STLP_INTERNAL_IOS_H
    1.38 +#ifndef _STLP_INTERNAL_IOS_H
    1.39  #  include <stl/_ios.h>                  // For basic_ios<>.  Includes <iosfwd>.
    1.40 -# endif
    1.41 +#endif
    1.42  
    1.43  #ifndef _STLP_INTERNAL_OSTREAM_H
    1.44 -# include <stl/_ostream.h>              // Needed as a base class of basic_iostream.
    1.45 +#  include <stl/_ostream.h>              // Needed as a base class of basic_iostream.
    1.46  #endif
    1.47  
    1.48  #ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
    1.49 -# include <stl/_istreambuf_iterator.h>
    1.50 +#  include <stl/_istreambuf_iterator.h>
    1.51  #endif
    1.52  
    1.53  #include <stl/_ctraits_fns.h>    // Helper functions that allow char traits
    1.54                                  // to be used as function objects.
    1.55  _STLP_BEGIN_NAMESPACE
    1.56  
    1.57 -template <class _CharT, class _Traits, class _Number> 
    1.58 -ios_base::iostate _STLP_CALL
    1.59 -_M_get_num(basic_istream<_CharT, _Traits>& __that, _Number& __val);
    1.60 -
    1.61  #if defined (_STLP_USE_TEMPLATE_EXPORT)
    1.62  template <class _CharT, class _Traits>
    1.63  class _Isentry;
    1.64 @@ -52,9 +47,9 @@
    1.65  struct _No_Skip_WS {};        // Dummy class used by sentry.
    1.66  
    1.67  template <class _CharT, class _Traits>
    1.68 -bool _M_init_skip(basic_istream<_CharT, _Traits>& __is);
    1.69 +bool _M_init_skip(basic_istream<_CharT, _Traits>& __istr);
    1.70  template <class _CharT, class _Traits>
    1.71 -bool _M_init_noskip(basic_istream<_CharT, _Traits>& __is);
    1.72 +bool _M_init_noskip(basic_istream<_CharT, _Traits>& __istr);
    1.73  
    1.74  //----------------------------------------------------------------------
    1.75  // Class basic_istream, a class that performs formatted input through
    1.76 @@ -62,10 +57,18 @@
    1.77  
    1.78  // The second template parameter, _Traits, defaults to char_traits<_CharT>.
    1.79  // The default is declared in header <iosfwd>, and it isn't declared here
    1.80 -// because C++ language rules do not allow it to be declared twice. 
    1.81 +// because C++ language rules do not allow it to be declared twice.
    1.82  
    1.83  template <class _CharT, class _Traits>
    1.84  class basic_istream : virtual public basic_ios<_CharT, _Traits> {
    1.85 +  typedef basic_istream<_CharT, _Traits> _Self;
    1.86 +
    1.87 +#if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310)
    1.88 +  //explicitely defined as private to avoid warnings:
    1.89 +  basic_istream(_Self const&);
    1.90 +  _Self& operator = (_Self const&);
    1.91 +#endif
    1.92 +
    1.93  public:
    1.94                           // Types
    1.95    typedef _CharT                     char_type;
    1.96 @@ -74,15 +77,17 @@
    1.97    typedef typename _Traits::off_type off_type;
    1.98    typedef _Traits                    traits_type;
    1.99    typedef basic_ios<_CharT, _Traits>     _Basic_ios;
   1.100 -  typedef basic_istream<_CharT, _Traits> _Self;
   1.101  
   1.102    typedef basic_ios<_CharT, _Traits>& (_STLP_CALL *__ios_fn)(basic_ios<_CharT, _Traits>&);
   1.103    typedef ios_base& (_STLP_CALL *__ios_base_fn)(ios_base&);
   1.104    typedef _Self& (_STLP_CALL *__istream_fn)(_Self&);
   1.105  
   1.106  public:                         // Constructor and destructor.
   1.107 -  _STLP_DECLSPEC explicit basic_istream(basic_streambuf<_CharT, _Traits>* __buf);
   1.108 -  _STLP_DECLSPEC ~basic_istream();
   1.109 +  explicit basic_istream(basic_streambuf<_CharT, _Traits>* __buf) :
   1.110 +    basic_ios<_CharT, _Traits>(), _M_gcount(0) {
   1.111 +    this->init(__buf);
   1.112 +  }
   1.113 +  ~basic_istream() {};
   1.114  
   1.115  public:                         // Nested sentry class.
   1.116  
   1.117 @@ -93,47 +98,25 @@
   1.118    _Self& operator>> (__ios_base_fn __f) { __f(*this); return *this; }
   1.119  
   1.120  public:                         // Formatted input of numbers.
   1.121 -  _Self& operator>> (short& __val) {
   1.122 -    long __lval = __val;
   1.123 -    unsigned short __uval;
   1.124 -   _M_get_num(*this, __lval);
   1.125 -    __val = __STATIC_CAST(short, __lval);
   1.126 -    __uval = __lval;
   1.127 -    // check if we lose digits
   1.128 -    //    if ((__val != __lval) && ((unsigned short)__val != __lval))
   1.129 -    if ((__val != __lval) && ((long)__uval != __lval))
   1.130 -      this->setstate(ios_base::failbit); 
   1.131 -    return *this; 
   1.132 -  }
   1.133 -  _Self& operator>> (int& __val) { 
   1.134 -    long __lval = __val;
   1.135 -    unsigned int __uval;
   1.136 -    _M_get_num(*this, __lval);
   1.137 -    __val = __lval;
   1.138 -    __uval = __lval;
   1.139 -    // check if we lose digits
   1.140 -    //    if ((__val != __lval) && ((unsigned int)__val != __lval))
   1.141 -    if ((__val != __lval) && ((long)__uval != __lval))
   1.142 -      this->setstate(ios_base::failbit); 
   1.143 -    return *this;
   1.144 -  }
   1.145 -  _Self& operator>> (unsigned short& __val) { _M_get_num(*this, __val); return *this; }
   1.146 -  _Self& operator>> (unsigned int& __val) { _M_get_num(*this, __val); return *this; }
   1.147 -  _Self& operator>> (long& __val) { _M_get_num(*this, __val); return *this; }
   1.148 -  _Self& operator>> (unsigned long& __val) { _M_get_num(*this, __val); return *this; }
   1.149 +  _Self& operator>> (short& __val);
   1.150 +  _Self& operator>> (int& __val);
   1.151 +  _Self& operator>> (unsigned short& __val);
   1.152 +  _Self& operator>> (unsigned int& __val);
   1.153 +  _Self& operator>> (long& __val);
   1.154 +  _Self& operator>> (unsigned long& __val);
   1.155  #ifdef _STLP_LONG_LONG
   1.156 -  _Self& operator>> (_STLP_LONG_LONG& __val) { _M_get_num(*this, __val); return *this; }
   1.157 -  _Self& operator>> (unsigned _STLP_LONG_LONG& __val) { _M_get_num(*this, __val); return *this; }
   1.158 -#endif 
   1.159 -  _Self& operator>> (float& __val)  { _M_get_num(*this, __val); return *this; }
   1.160 -  _Self& operator>> (double& __val) { _M_get_num(*this, __val); return *this; }
   1.161 +  _Self& operator>> (_STLP_LONG_LONG& __val);
   1.162 +  _Self& operator>> (unsigned _STLP_LONG_LONG& __val);
   1.163 +#endif
   1.164 +  _Self& operator>> (float& __val);
   1.165 +  _Self& operator>> (double& __val);
   1.166  # ifndef _STLP_NO_LONG_DOUBLE
   1.167 -  _Self& operator>> (long double& __val) { _M_get_num(*this, __val); return *this; }
   1.168 +  _Self& operator>> (long double& __val);
   1.169  # endif
   1.170  # ifndef _STLP_NO_BOOL
   1.171 -  _Self& operator>> (bool& __val) { _M_get_num(*this, __val); return *this; }
   1.172 +  _Self& operator>> (bool& __val);
   1.173  # endif
   1.174 -  _Self& operator>> (void*& __val) { _M_get_num(*this, __val); return *this; }
   1.175 +  _Self& operator>> (void*& __val);
   1.176  
   1.177  public:                         // Copying characters into a streambuf.
   1.178    _Self& operator>>(basic_streambuf<_CharT, _Traits>*);
   1.179 @@ -207,34 +190,35 @@
   1.180    class sentry {
   1.181      typedef sentry _Self;
   1.182  #endif
   1.183 -    
   1.184 +
   1.185    private:
   1.186      const bool _M_ok;
   1.187      //    basic_streambuf<_CharT, _Traits>* _M_buf;
   1.188 -        
   1.189 +
   1.190    public:
   1.191      typedef _Traits traits_type;
   1.192 -    
   1.193 -    explicit sentry(basic_istream<_CharT, _Traits>& __is,
   1.194 -                    bool __noskipws = false) : 
   1.195 -      _M_ok((__noskipws || !(__is.flags() & ios_base::skipws)) ? _M_init_noskip(__is) :  _M_init_skip(__is) )
   1.196 -      /* , _M_buf(__is.rdbuf()) */
   1.197 +
   1.198 +    explicit sentry(basic_istream<_CharT, _Traits>& __istr,
   1.199 +                    bool __noskipws = false) :
   1.200 +      _M_ok((__noskipws || !(__istr.flags() & ios_base::skipws)) ? _M_init_noskip(__istr) : _M_init_skip(__istr) )
   1.201 +      /* , _M_buf(__istr.rdbuf()) */
   1.202        {}
   1.203 -    
   1.204 -    // Calling this constructor is the same as calling the previous one with 
   1.205 +
   1.206 +    // Calling this constructor is the same as calling the previous one with
   1.207      // __noskipws = true, except that it doesn't require a runtime test.
   1.208 -    sentry(basic_istream<_CharT, _Traits>& __is, _No_Skip_WS) : /* _M_buf(__is.rdbuf()), */
   1.209 -      _M_ok(_M_init_noskip(__is)) {}
   1.210 -    
   1.211 +    sentry(basic_istream<_CharT, _Traits>& __istr, _No_Skip_WS) : /* _M_buf(__istr.rdbuf()), */
   1.212 +      _M_ok(_M_init_noskip(__istr)) {}
   1.213 +
   1.214      ~sentry() {}
   1.215 -    
   1.216 +
   1.217      operator bool() const { return _M_ok; }
   1.218 -    
   1.219 +
   1.220    private:                        // Disable assignment and copy constructor.
   1.221 +    //Implementation is here only to avoid warning with some compilers.
   1.222      sentry(const _Self&) : _M_ok(false) {}
   1.223 -    void operator=(const _Self&) {}
   1.224 +    _Self& operator=(const _Self&) { return *this; }
   1.225    };
   1.226 -  
   1.227 +
   1.228  # if defined (_STLP_USE_TEMPLATE_EXPORT)
   1.229  #  undef sentry
   1.230  # else
   1.231 @@ -252,58 +236,95 @@
   1.232  # endif /* _STLP_USE_TEMPLATE_EXPORT */
   1.233  
   1.234  // Non-member character and string extractor functions.
   1.235 -
   1.236  template <class _CharT, class _Traits>
   1.237 -inline basic_istream<_CharT, _Traits>& _STLP_CALL  
   1.238 -operator>>(basic_istream<_CharT, _Traits>& __stl_in, _CharT& __c) {
   1.239 -  __stl_in._M_formatted_get(__c);
   1.240 -  return __stl_in;
   1.241 +inline basic_istream<_CharT, _Traits>& _STLP_CALL
   1.242 +operator>>(basic_istream<_CharT, _Traits>& __in_str, _CharT& __c) {
   1.243 +  __in_str._M_formatted_get(__c);
   1.244 +  return __in_str;
   1.245  }
   1.246  
   1.247  template <class _Traits>
   1.248 -inline basic_istream<char, _Traits>& _STLP_CALL  
   1.249 -operator>>(basic_istream<char, _Traits>& __stl_in, unsigned char& __c) {
   1.250 -  __stl_in._M_formatted_get(__REINTERPRET_CAST(char&,__c));
   1.251 -  return __stl_in;
   1.252 +inline basic_istream<char, _Traits>& _STLP_CALL
   1.253 +operator>>(basic_istream<char, _Traits>& __in_str, unsigned char& __c) {
   1.254 +  __in_str._M_formatted_get(__REINTERPRET_CAST(char&,__c));
   1.255 +  return __in_str;
   1.256  }
   1.257  
   1.258  template <class _Traits>
   1.259 -inline basic_istream<char, _Traits>& _STLP_CALL 
   1.260 -operator>>(basic_istream<char, _Traits>& __stl_in, signed char& __c) {
   1.261 -  __stl_in._M_formatted_get(__REINTERPRET_CAST(char&,__c));
   1.262 -  return __stl_in;
   1.263 +inline basic_istream<char, _Traits>& _STLP_CALL
   1.264 +operator>>(basic_istream<char, _Traits>& __in_str, signed char& __c) {
   1.265 +  __in_str._M_formatted_get(__REINTERPRET_CAST(char&,__c));
   1.266 +  return __in_str;
   1.267  }
   1.268  
   1.269  template <class _CharT, class _Traits>
   1.270 -inline basic_istream<_CharT, _Traits>& _STLP_CALL 
   1.271 -operator>>(basic_istream<_CharT, _Traits>& __stl_in, _CharT* __s) {
   1.272 -  __stl_in._M_formatted_get(__s);
   1.273 -  return __stl_in;
   1.274 +inline basic_istream<_CharT, _Traits>& _STLP_CALL
   1.275 +operator>>(basic_istream<_CharT, _Traits>& __in_str, _CharT* __s) {
   1.276 +  __in_str._M_formatted_get(__s);
   1.277 +  return __in_str;
   1.278  }
   1.279  
   1.280  template <class _Traits>
   1.281 -inline basic_istream<char, _Traits>& _STLP_CALL 
   1.282 -operator>>(basic_istream<char, _Traits>& __stl_in, unsigned char* __s) {
   1.283 -  __stl_in._M_formatted_get(__REINTERPRET_CAST(char*,__s));
   1.284 -  return __stl_in;
   1.285 +inline basic_istream<char, _Traits>& _STLP_CALL
   1.286 +operator>>(basic_istream<char, _Traits>& __in_str, unsigned char* __s) {
   1.287 +  __in_str._M_formatted_get(__REINTERPRET_CAST(char*,__s));
   1.288 +  return __in_str;
   1.289  }
   1.290  
   1.291  template <class _Traits>
   1.292 -inline basic_istream<char, _Traits>& _STLP_CALL 
   1.293 -operator>>(basic_istream<char, _Traits>& __stl_in, signed char* __s) {
   1.294 -  __stl_in._M_formatted_get(__REINTERPRET_CAST(char*,__s));
   1.295 -  return __stl_in;
   1.296 +inline basic_istream<char, _Traits>& _STLP_CALL
   1.297 +operator>>(basic_istream<char, _Traits>& __in_str, signed char* __s) {
   1.298 +  __in_str._M_formatted_get(__REINTERPRET_CAST(char*,__s));
   1.299 +  return __in_str;
   1.300  }
   1.301  
   1.302  //----------------------------------------------------------------------
   1.303  // istream manipulator.
   1.304  template <class _CharT, class _Traits>
   1.305  basic_istream<_CharT, _Traits>& _STLP_CALL
   1.306 -ws(basic_istream<_CharT, _Traits>& __is);
   1.307 +ws(basic_istream<_CharT, _Traits>& __istr) {
   1.308 +  if (!__istr.eof()) {
   1.309 +    typedef typename basic_istream<_CharT, _Traits>::sentry      _Sentry;
   1.310 +    _Sentry __sentry(__istr, _No_Skip_WS()); // Don't skip whitespace.
   1.311 +    if (__sentry)
   1.312 +      __istr._M_skip_whitespace(false);
   1.313 +  }
   1.314 +  return __istr;
   1.315 +}
   1.316 +
   1.317 +// Helper functions for istream<>::sentry constructor.
   1.318 +template <class _CharT, class _Traits>
   1.319 +inline bool _M_init_skip(basic_istream<_CharT, _Traits>& __istr) {
   1.320 +  if (__istr.good()) {
   1.321 +    if (__istr.tie())
   1.322 +      __istr.tie()->flush();
   1.323 +
   1.324 +    __istr._M_skip_whitespace(true);
   1.325 +  }
   1.326 +
   1.327 +  if (!__istr.good()) {
   1.328 +    __istr.setstate(ios_base::failbit);
   1.329 +    return false;
   1.330 +  } else
   1.331 +    return true;
   1.332 +}
   1.333 +
   1.334 +template <class _CharT, class _Traits>
   1.335 +inline bool _M_init_noskip(basic_istream<_CharT, _Traits>& __istr) {
   1.336 +  if (__istr.good()) {
   1.337 +    if (__istr.tie())
   1.338 +      __istr.tie()->flush();
   1.339 +
   1.340 +    if (!__istr.rdbuf())
   1.341 +      __istr.setstate(ios_base::badbit);
   1.342 +  }
   1.343 +  else
   1.344 +    __istr.setstate(ios_base::failbit);
   1.345 +  return __istr.good();
   1.346 +}
   1.347  
   1.348  //----------------------------------------------------------------------
   1.349  // Class iostream.
   1.350 -
   1.351  template <class _CharT, class _Traits>
   1.352  class basic_iostream
   1.353    : public basic_istream<_CharT, _Traits>,
   1.354 @@ -312,30 +333,29 @@
   1.355  public:
   1.356    typedef basic_ios<_CharT, _Traits> _Basic_ios;
   1.357  
   1.358 -  _STLP_DECLSPEC explicit basic_iostream(basic_streambuf<_CharT, _Traits>* __buf);
   1.359 -  _STLP_DECLSPEC virtual ~basic_iostream();
   1.360 +  explicit basic_iostream(basic_streambuf<_CharT, _Traits>* __buf);
   1.361 +  virtual ~basic_iostream();
   1.362  };
   1.363  
   1.364  # if defined (_STLP_USE_TEMPLATE_EXPORT)
   1.365  _STLP_EXPORT_TEMPLATE_CLASS basic_iostream<char, char_traits<char> >;
   1.366 +
   1.367  #  if ! defined (_STLP_NO_WCHAR_T)
   1.368  _STLP_EXPORT_TEMPLATE_CLASS basic_iostream<wchar_t, char_traits<wchar_t> >;
   1.369  #  endif
   1.370  # endif /* _STLP_USE_TEMPLATE_EXPORT */
   1.371  
   1.372  template <class _CharT, class _Traits>
   1.373 -basic_streambuf<_CharT, _Traits>* _STLP_CALL _M_get_istreambuf(basic_istream<_CharT, _Traits>& __is) 
   1.374 -{
   1.375 -  return __is.rdbuf();
   1.376 -}
   1.377 +basic_streambuf<_CharT, _Traits>* _STLP_CALL _M_get_istreambuf(basic_istream<_CharT, _Traits>& __istr)
   1.378 +{ return __istr.rdbuf(); }
   1.379  
   1.380  _STLP_END_NAMESPACE
   1.381  
   1.382 -# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
   1.383 +#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
   1.384  #  include <stl/_istream.c>
   1.385 -# endif
   1.386 +#endif
   1.387  
   1.388 -#endif /* _STLP_INTERNAL_ISTREAM_H */
   1.389 +#endif /* _STLP_INTERNAL_ISTREAM */
   1.390  
   1.391  // Local Variables:
   1.392  // mode:C++