epoc32/include/stdapis/stlportv5/stl/_istream.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100 (2010-03-31)
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
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.
williamr@2
     1
/*
williamr@2
     2
 * Copyright (c) 1999
williamr@2
     3
 * Silicon Graphics Computer Systems, Inc.
williamr@2
     4
 *
williamr@4
     5
 * Copyright (c) 1999
williamr@2
     6
 * Boris Fomitchev
williamr@2
     7
 *
williamr@2
     8
 * This material is provided "as is", with absolutely no warranty expressed
williamr@2
     9
 * or implied. Any use is at your own risk.
williamr@2
    10
 *
williamr@4
    11
 * Permission to use or copy this software for any purpose is hereby granted
williamr@2
    12
 * without fee, provided the above notices are retained on all copies.
williamr@2
    13
 * Permission to modify the code and to distribute modified code is granted,
williamr@2
    14
 * provided the above notices are retained, and a notice that the code was
williamr@2
    15
 * modified is included with the above copyright notice.
williamr@2
    16
 *
williamr@4
    17
 */
williamr@4
    18
#ifndef _STLP_INTERNAL_ISTREAM
williamr@4
    19
#define _STLP_INTERNAL_ISTREAM
williamr@2
    20
williamr@2
    21
// this block is included by _ostream.h, we include it here to lower #include level
williamr@4
    22
#if defined (_STLP_HAS_WCHAR_T) && !defined (_STLP_INTERNAL_CWCHAR)
williamr@2
    23
#  include <stl/_cwchar.h>
williamr@4
    24
#endif
williamr@2
    25
williamr@4
    26
#ifndef _STLP_INTERNAL_IOS_H
williamr@2
    27
#  include <stl/_ios.h>                  // For basic_ios<>.  Includes <iosfwd>.
williamr@4
    28
#endif
williamr@2
    29
williamr@2
    30
#ifndef _STLP_INTERNAL_OSTREAM_H
williamr@4
    31
#  include <stl/_ostream.h>              // Needed as a base class of basic_iostream.
williamr@2
    32
#endif
williamr@2
    33
williamr@2
    34
#ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
williamr@4
    35
#  include <stl/_istreambuf_iterator.h>
williamr@2
    36
#endif
williamr@2
    37
williamr@2
    38
#include <stl/_ctraits_fns.h>    // Helper functions that allow char traits
williamr@2
    39
                                // to be used as function objects.
williamr@2
    40
_STLP_BEGIN_NAMESPACE
williamr@2
    41
williamr@2
    42
#if defined (_STLP_USE_TEMPLATE_EXPORT)
williamr@2
    43
template <class _CharT, class _Traits>
williamr@2
    44
class _Isentry;
williamr@2
    45
#endif
williamr@2
    46
williamr@2
    47
struct _No_Skip_WS {};        // Dummy class used by sentry.
williamr@2
    48
williamr@2
    49
template <class _CharT, class _Traits>
williamr@4
    50
bool _M_init_skip(basic_istream<_CharT, _Traits>& __istr);
williamr@2
    51
template <class _CharT, class _Traits>
williamr@4
    52
bool _M_init_noskip(basic_istream<_CharT, _Traits>& __istr);
williamr@2
    53
williamr@2
    54
//----------------------------------------------------------------------
williamr@2
    55
// Class basic_istream, a class that performs formatted input through
williamr@2
    56
// a stream buffer.
williamr@2
    57
williamr@2
    58
// The second template parameter, _Traits, defaults to char_traits<_CharT>.
williamr@2
    59
// The default is declared in header <iosfwd>, and it isn't declared here
williamr@4
    60
// because C++ language rules do not allow it to be declared twice.
williamr@2
    61
williamr@2
    62
template <class _CharT, class _Traits>
williamr@2
    63
class basic_istream : virtual public basic_ios<_CharT, _Traits> {
williamr@4
    64
  typedef basic_istream<_CharT, _Traits> _Self;
williamr@4
    65
williamr@4
    66
#if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310)
williamr@4
    67
  //explicitely defined as private to avoid warnings:
williamr@4
    68
  basic_istream(_Self const&);
williamr@4
    69
  _Self& operator = (_Self const&);
williamr@4
    70
#endif
williamr@4
    71
williamr@2
    72
public:
williamr@2
    73
                         // Types
williamr@2
    74
  typedef _CharT                     char_type;
williamr@2
    75
  typedef typename _Traits::int_type int_type;
williamr@2
    76
  typedef typename _Traits::pos_type pos_type;
williamr@2
    77
  typedef typename _Traits::off_type off_type;
williamr@2
    78
  typedef _Traits                    traits_type;
williamr@2
    79
  typedef basic_ios<_CharT, _Traits>     _Basic_ios;
williamr@2
    80
williamr@2
    81
  typedef basic_ios<_CharT, _Traits>& (_STLP_CALL *__ios_fn)(basic_ios<_CharT, _Traits>&);
williamr@2
    82
  typedef ios_base& (_STLP_CALL *__ios_base_fn)(ios_base&);
williamr@2
    83
  typedef _Self& (_STLP_CALL *__istream_fn)(_Self&);
williamr@2
    84
williamr@2
    85
public:                         // Constructor and destructor.
williamr@4
    86
  explicit basic_istream(basic_streambuf<_CharT, _Traits>* __buf) :
williamr@4
    87
    basic_ios<_CharT, _Traits>(), _M_gcount(0) {
williamr@4
    88
    this->init(__buf);
williamr@4
    89
  }
williamr@4
    90
  ~basic_istream() {};
williamr@2
    91
williamr@2
    92
public:                         // Nested sentry class.
williamr@2
    93
williamr@2
    94
public:                         // Hooks for manipulators.  The arguments are
williamr@2
    95
                                // function pointers.
williamr@2
    96
  _Self& operator>> (__istream_fn __f) { return __f(*this); }
williamr@2
    97
  _Self& operator>> (__ios_fn __f) {  __f(*this); return *this; }
williamr@2
    98
  _Self& operator>> (__ios_base_fn __f) { __f(*this); return *this; }
williamr@2
    99
williamr@2
   100
public:                         // Formatted input of numbers.
williamr@4
   101
  _Self& operator>> (short& __val);
williamr@4
   102
  _Self& operator>> (int& __val);
williamr@4
   103
  _Self& operator>> (unsigned short& __val);
williamr@4
   104
  _Self& operator>> (unsigned int& __val);
williamr@4
   105
  _Self& operator>> (long& __val);
williamr@4
   106
  _Self& operator>> (unsigned long& __val);
williamr@2
   107
#ifdef _STLP_LONG_LONG
williamr@4
   108
  _Self& operator>> (_STLP_LONG_LONG& __val);
williamr@4
   109
  _Self& operator>> (unsigned _STLP_LONG_LONG& __val);
williamr@4
   110
#endif
williamr@4
   111
  _Self& operator>> (float& __val);
williamr@4
   112
  _Self& operator>> (double& __val);
williamr@2
   113
# ifndef _STLP_NO_LONG_DOUBLE
williamr@4
   114
  _Self& operator>> (long double& __val);
williamr@2
   115
# endif
williamr@2
   116
# ifndef _STLP_NO_BOOL
williamr@4
   117
  _Self& operator>> (bool& __val);
williamr@2
   118
# endif
williamr@4
   119
  _Self& operator>> (void*& __val);
williamr@2
   120
williamr@2
   121
public:                         // Copying characters into a streambuf.
williamr@2
   122
  _Self& operator>>(basic_streambuf<_CharT, _Traits>*);
williamr@2
   123
williamr@2
   124
public:                         // Unformatted input.
williamr@2
   125
  streamsize gcount() const { return _M_gcount; }
williamr@2
   126
  int_type peek();
williamr@2
   127
williamr@2
   128
public:                         // get() for single characters
williamr@2
   129
  int_type get();
williamr@2
   130
  _Self& get(char_type& __c);
williamr@2
   131
williamr@2
   132
public:                         // get() for character arrays.
williamr@2
   133
  _Self& get(char_type* __s, streamsize __n, char_type __delim);
williamr@2
   134
  _Self& get(char_type* __s, streamsize __n)
williamr@2
   135
    { return get(__s, __n, this->widen('\n')); }
williamr@2
   136
williamr@2
   137
public:                         // get() for streambufs
williamr@2
   138
  _Self& get(basic_streambuf<_CharT, _Traits>& __buf,
williamr@2
   139
                     char_type __delim);
williamr@2
   140
  _Self& get(basic_streambuf<_CharT, _Traits>& __buf)
williamr@2
   141
    { return get(__buf, this->widen('\n')); }
williamr@2
   142
williamr@2
   143
public:                         // getline()
williamr@2
   144
  _Self& getline(char_type* __s, streamsize __n, char_type delim);
williamr@2
   145
  _Self& getline(char_type* __s, streamsize __n)
williamr@2
   146
    { return getline(__s, __n, this->widen('\n')); }
williamr@2
   147
williamr@2
   148
public:                         // read(), readsome(), ignore()
williamr@2
   149
  _Self& ignore();
williamr@2
   150
  _Self& ignore(streamsize __n);
williamr@2
   151
#if (defined (_STLP_MSVC) && _STLP_MSVC < 1200)
williamr@2
   152
  inline
williamr@2
   153
#endif
williamr@2
   154
  _Self& ignore(streamsize __n, int_type __delim);
williamr@2
   155
williamr@2
   156
  _Self& read(char_type* __s, streamsize __n);
williamr@2
   157
  streamsize readsome(char_type* __s, streamsize __n);
williamr@2
   158
williamr@2
   159
public:                         // putback
williamr@2
   160
  _Self& putback(char_type __c);
williamr@2
   161
  _Self& unget();
williamr@2
   162
williamr@2
   163
public:                         // Positioning and buffer control.
williamr@2
   164
  int sync();
williamr@2
   165
williamr@2
   166
  pos_type tellg();
williamr@2
   167
  _Self& seekg(pos_type __pos);
williamr@2
   168
  _Self& seekg(off_type, ios_base::seekdir);
williamr@2
   169
williamr@2
   170
public:                         // Helper functions for non-member extractors.
williamr@2
   171
  void _M_formatted_get(_CharT& __c);
williamr@2
   172
  void _M_formatted_get(_CharT* __s);
williamr@2
   173
  void _M_skip_whitespace(bool __set_failbit);
williamr@2
   174
williamr@2
   175
private:                        // Number of characters extracted by the
williamr@2
   176
  streamsize _M_gcount;         // most recent unformatted input function.
williamr@2
   177
williamr@2
   178
public:
williamr@2
   179
williamr@2
   180
#if defined (_STLP_USE_TEMPLATE_EXPORT)
williamr@2
   181
  // If we are using DLL specs, we have not to use inner classes
williamr@2
   182
  // end class declaration here
williamr@2
   183
  typedef _Isentry<_CharT, _Traits>      sentry;
williamr@2
   184
};
williamr@2
   185
#  define sentry _Isentry
williamr@2
   186
template <class _CharT, class _Traits>
williamr@2
   187
class _Isentry {
williamr@2
   188
  typedef _Isentry<_CharT, _Traits> _Self;
williamr@2
   189
# else
williamr@2
   190
  class sentry {
williamr@2
   191
    typedef sentry _Self;
williamr@2
   192
#endif
williamr@4
   193
williamr@2
   194
  private:
williamr@2
   195
    const bool _M_ok;
williamr@2
   196
    //    basic_streambuf<_CharT, _Traits>* _M_buf;
williamr@4
   197
williamr@2
   198
  public:
williamr@2
   199
    typedef _Traits traits_type;
williamr@4
   200
williamr@4
   201
    explicit sentry(basic_istream<_CharT, _Traits>& __istr,
williamr@4
   202
                    bool __noskipws = false) :
williamr@4
   203
      _M_ok((__noskipws || !(__istr.flags() & ios_base::skipws)) ? _M_init_noskip(__istr) : _M_init_skip(__istr) )
williamr@4
   204
      /* , _M_buf(__istr.rdbuf()) */
williamr@2
   205
      {}
williamr@4
   206
williamr@4
   207
    // Calling this constructor is the same as calling the previous one with
williamr@2
   208
    // __noskipws = true, except that it doesn't require a runtime test.
williamr@4
   209
    sentry(basic_istream<_CharT, _Traits>& __istr, _No_Skip_WS) : /* _M_buf(__istr.rdbuf()), */
williamr@4
   210
      _M_ok(_M_init_noskip(__istr)) {}
williamr@4
   211
williamr@2
   212
    ~sentry() {}
williamr@4
   213
williamr@2
   214
    operator bool() const { return _M_ok; }
williamr@4
   215
williamr@2
   216
  private:                        // Disable assignment and copy constructor.
williamr@4
   217
    //Implementation is here only to avoid warning with some compilers.
williamr@2
   218
    sentry(const _Self&) : _M_ok(false) {}
williamr@4
   219
    _Self& operator=(const _Self&) { return *this; }
williamr@2
   220
  };
williamr@4
   221
williamr@2
   222
# if defined (_STLP_USE_TEMPLATE_EXPORT)
williamr@2
   223
#  undef sentry
williamr@2
   224
# else
williamr@2
   225
  // close basic_istream class definition here
williamr@2
   226
};
williamr@2
   227
# endif
williamr@2
   228
williamr@2
   229
# if defined (_STLP_USE_TEMPLATE_EXPORT)
williamr@2
   230
_STLP_EXPORT_TEMPLATE_CLASS _Isentry<char, char_traits<char> >;
williamr@2
   231
_STLP_EXPORT_TEMPLATE_CLASS basic_istream<char, char_traits<char> >;
williamr@2
   232
#  if ! defined (_STLP_NO_WCHAR_T)
williamr@2
   233
_STLP_EXPORT_TEMPLATE_CLASS _Isentry<wchar_t, char_traits<wchar_t> >;
williamr@2
   234
_STLP_EXPORT_TEMPLATE_CLASS basic_istream<wchar_t, char_traits<wchar_t> >;
williamr@2
   235
#  endif
williamr@2
   236
# endif /* _STLP_USE_TEMPLATE_EXPORT */
williamr@2
   237
williamr@2
   238
// Non-member character and string extractor functions.
williamr@2
   239
template <class _CharT, class _Traits>
williamr@4
   240
inline basic_istream<_CharT, _Traits>& _STLP_CALL
williamr@4
   241
operator>>(basic_istream<_CharT, _Traits>& __in_str, _CharT& __c) {
williamr@4
   242
  __in_str._M_formatted_get(__c);
williamr@4
   243
  return __in_str;
williamr@2
   244
}
williamr@2
   245
williamr@2
   246
template <class _Traits>
williamr@4
   247
inline basic_istream<char, _Traits>& _STLP_CALL
williamr@4
   248
operator>>(basic_istream<char, _Traits>& __in_str, unsigned char& __c) {
williamr@4
   249
  __in_str._M_formatted_get(__REINTERPRET_CAST(char&,__c));
williamr@4
   250
  return __in_str;
williamr@2
   251
}
williamr@2
   252
williamr@2
   253
template <class _Traits>
williamr@4
   254
inline basic_istream<char, _Traits>& _STLP_CALL
williamr@4
   255
operator>>(basic_istream<char, _Traits>& __in_str, signed char& __c) {
williamr@4
   256
  __in_str._M_formatted_get(__REINTERPRET_CAST(char&,__c));
williamr@4
   257
  return __in_str;
williamr@2
   258
}
williamr@2
   259
williamr@2
   260
template <class _CharT, class _Traits>
williamr@4
   261
inline basic_istream<_CharT, _Traits>& _STLP_CALL
williamr@4
   262
operator>>(basic_istream<_CharT, _Traits>& __in_str, _CharT* __s) {
williamr@4
   263
  __in_str._M_formatted_get(__s);
williamr@4
   264
  return __in_str;
williamr@2
   265
}
williamr@2
   266
williamr@2
   267
template <class _Traits>
williamr@4
   268
inline basic_istream<char, _Traits>& _STLP_CALL
williamr@4
   269
operator>>(basic_istream<char, _Traits>& __in_str, unsigned char* __s) {
williamr@4
   270
  __in_str._M_formatted_get(__REINTERPRET_CAST(char*,__s));
williamr@4
   271
  return __in_str;
williamr@2
   272
}
williamr@2
   273
williamr@2
   274
template <class _Traits>
williamr@4
   275
inline basic_istream<char, _Traits>& _STLP_CALL
williamr@4
   276
operator>>(basic_istream<char, _Traits>& __in_str, signed char* __s) {
williamr@4
   277
  __in_str._M_formatted_get(__REINTERPRET_CAST(char*,__s));
williamr@4
   278
  return __in_str;
williamr@2
   279
}
williamr@2
   280
williamr@2
   281
//----------------------------------------------------------------------
williamr@2
   282
// istream manipulator.
williamr@2
   283
template <class _CharT, class _Traits>
williamr@2
   284
basic_istream<_CharT, _Traits>& _STLP_CALL
williamr@4
   285
ws(basic_istream<_CharT, _Traits>& __istr) {
williamr@4
   286
  if (!__istr.eof()) {
williamr@4
   287
    typedef typename basic_istream<_CharT, _Traits>::sentry      _Sentry;
williamr@4
   288
    _Sentry __sentry(__istr, _No_Skip_WS()); // Don't skip whitespace.
williamr@4
   289
    if (__sentry)
williamr@4
   290
      __istr._M_skip_whitespace(false);
williamr@4
   291
  }
williamr@4
   292
  return __istr;
williamr@4
   293
}
williamr@4
   294
williamr@4
   295
// Helper functions for istream<>::sentry constructor.
williamr@4
   296
template <class _CharT, class _Traits>
williamr@4
   297
inline bool _M_init_skip(basic_istream<_CharT, _Traits>& __istr) {
williamr@4
   298
  if (__istr.good()) {
williamr@4
   299
    if (__istr.tie())
williamr@4
   300
      __istr.tie()->flush();
williamr@4
   301
williamr@4
   302
    __istr._M_skip_whitespace(true);
williamr@4
   303
  }
williamr@4
   304
williamr@4
   305
  if (!__istr.good()) {
williamr@4
   306
    __istr.setstate(ios_base::failbit);
williamr@4
   307
    return false;
williamr@4
   308
  } else
williamr@4
   309
    return true;
williamr@4
   310
}
williamr@4
   311
williamr@4
   312
template <class _CharT, class _Traits>
williamr@4
   313
inline bool _M_init_noskip(basic_istream<_CharT, _Traits>& __istr) {
williamr@4
   314
  if (__istr.good()) {
williamr@4
   315
    if (__istr.tie())
williamr@4
   316
      __istr.tie()->flush();
williamr@4
   317
williamr@4
   318
    if (!__istr.rdbuf())
williamr@4
   319
      __istr.setstate(ios_base::badbit);
williamr@4
   320
  }
williamr@4
   321
  else
williamr@4
   322
    __istr.setstate(ios_base::failbit);
williamr@4
   323
  return __istr.good();
williamr@4
   324
}
williamr@2
   325
williamr@2
   326
//----------------------------------------------------------------------
williamr@2
   327
// Class iostream.
williamr@2
   328
template <class _CharT, class _Traits>
williamr@2
   329
class basic_iostream
williamr@2
   330
  : public basic_istream<_CharT, _Traits>,
williamr@2
   331
    public basic_ostream<_CharT, _Traits>
williamr@2
   332
{
williamr@2
   333
public:
williamr@2
   334
  typedef basic_ios<_CharT, _Traits> _Basic_ios;
williamr@2
   335
williamr@4
   336
  explicit basic_iostream(basic_streambuf<_CharT, _Traits>* __buf);
williamr@4
   337
  virtual ~basic_iostream();
williamr@2
   338
};
williamr@2
   339
williamr@2
   340
# if defined (_STLP_USE_TEMPLATE_EXPORT)
williamr@2
   341
_STLP_EXPORT_TEMPLATE_CLASS basic_iostream<char, char_traits<char> >;
williamr@4
   342
williamr@2
   343
#  if ! defined (_STLP_NO_WCHAR_T)
williamr@2
   344
_STLP_EXPORT_TEMPLATE_CLASS basic_iostream<wchar_t, char_traits<wchar_t> >;
williamr@2
   345
#  endif
williamr@2
   346
# endif /* _STLP_USE_TEMPLATE_EXPORT */
williamr@2
   347
williamr@2
   348
template <class _CharT, class _Traits>
williamr@4
   349
basic_streambuf<_CharT, _Traits>* _STLP_CALL _M_get_istreambuf(basic_istream<_CharT, _Traits>& __istr)
williamr@4
   350
{ return __istr.rdbuf(); }
williamr@2
   351
williamr@2
   352
_STLP_END_NAMESPACE
williamr@2
   353
williamr@4
   354
#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
williamr@2
   355
#  include <stl/_istream.c>
williamr@4
   356
#endif
williamr@2
   357
williamr@4
   358
#endif /* _STLP_INTERNAL_ISTREAM */
williamr@2
   359
williamr@2
   360
// Local Variables:
williamr@2
   361
// mode:C++
williamr@2
   362
// End: