epoc32/include/tools/stlport/stl/_istream.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.
williamr@4
     1
/*
williamr@4
     2
 * Copyright (c) 1999
williamr@4
     3
 * Silicon Graphics Computer Systems, Inc.
williamr@4
     4
 *
williamr@4
     5
 * Copyright (c) 1999
williamr@4
     6
 * Boris Fomitchev
williamr@4
     7
 *
williamr@4
     8
 * This material is provided "as is", with absolutely no warranty expressed
williamr@4
     9
 * or implied. Any use is at your own risk.
williamr@4
    10
 *
williamr@4
    11
 * Permission to use or copy this software for any purpose is hereby granted
williamr@4
    12
 * without fee, provided the above notices are retained on all copies.
williamr@4
    13
 * Permission to modify the code and to distribute modified code is granted,
williamr@4
    14
 * provided the above notices are retained, and a notice that the code was
williamr@4
    15
 * modified is included with the above copyright notice.
williamr@4
    16
 *
williamr@4
    17
 */
williamr@4
    18
#ifndef _STLP_INTERNAL_ISTREAM
williamr@4
    19
#define _STLP_INTERNAL_ISTREAM
williamr@4
    20
williamr@4
    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@4
    23
#  include <stl/_cwchar.h>
williamr@4
    24
#endif
williamr@4
    25
williamr@4
    26
#ifndef _STLP_INTERNAL_IOS_H
williamr@4
    27
#  include <stl/_ios.h>                  // For basic_ios<>.  Includes <iosfwd>.
williamr@4
    28
#endif
williamr@4
    29
williamr@4
    30
#ifndef _STLP_INTERNAL_OSTREAM_H
williamr@4
    31
#  include <stl/_ostream.h>              // Needed as a base class of basic_iostream.
williamr@4
    32
#endif
williamr@4
    33
williamr@4
    34
#ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
williamr@4
    35
#  include <stl/_istreambuf_iterator.h>
williamr@4
    36
#endif
williamr@4
    37
williamr@4
    38
#include <stl/_ctraits_fns.h>    // Helper functions that allow char traits
williamr@4
    39
                                // to be used as function objects.
williamr@4
    40
_STLP_BEGIN_NAMESPACE
williamr@4
    41
williamr@4
    42
#if defined (_STLP_USE_TEMPLATE_EXPORT)
williamr@4
    43
template <class _CharT, class _Traits>
williamr@4
    44
class _Isentry;
williamr@4
    45
#endif
williamr@4
    46
williamr@4
    47
struct _No_Skip_WS {};        // Dummy class used by sentry.
williamr@4
    48
williamr@4
    49
template <class _CharT, class _Traits>
williamr@4
    50
bool _M_init_skip(basic_istream<_CharT, _Traits>& __istr);
williamr@4
    51
template <class _CharT, class _Traits>
williamr@4
    52
bool _M_init_noskip(basic_istream<_CharT, _Traits>& __istr);
williamr@4
    53
williamr@4
    54
//----------------------------------------------------------------------
williamr@4
    55
// Class basic_istream, a class that performs formatted input through
williamr@4
    56
// a stream buffer.
williamr@4
    57
williamr@4
    58
// The second template parameter, _Traits, defaults to char_traits<_CharT>.
williamr@4
    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@4
    61
williamr@4
    62
template <class _CharT, class _Traits>
williamr@4
    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@4
    72
public:
williamr@4
    73
                         // Types
williamr@4
    74
  typedef _CharT                     char_type;
williamr@4
    75
  typedef typename _Traits::int_type int_type;
williamr@4
    76
  typedef typename _Traits::pos_type pos_type;
williamr@4
    77
  typedef typename _Traits::off_type off_type;
williamr@4
    78
  typedef _Traits                    traits_type;
williamr@4
    79
  typedef basic_ios<_CharT, _Traits>     _Basic_ios;
williamr@4
    80
williamr@4
    81
  typedef basic_ios<_CharT, _Traits>& (_STLP_CALL *__ios_fn)(basic_ios<_CharT, _Traits>&);
williamr@4
    82
  typedef ios_base& (_STLP_CALL *__ios_base_fn)(ios_base&);
williamr@4
    83
  typedef _Self& (_STLP_CALL *__istream_fn)(_Self&);
williamr@4
    84
williamr@4
    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@4
    91
williamr@4
    92
public:                         // Nested sentry class.
williamr@4
    93
williamr@4
    94
public:                         // Hooks for manipulators.  The arguments are
williamr@4
    95
                                // function pointers.
williamr@4
    96
  _Self& operator>> (__istream_fn __f) { return __f(*this); }
williamr@4
    97
  _Self& operator>> (__ios_fn __f) {  __f(*this); return *this; }
williamr@4
    98
  _Self& operator>> (__ios_base_fn __f) { __f(*this); return *this; }
williamr@4
    99
williamr@4
   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@4
   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@4
   113
# ifndef _STLP_NO_LONG_DOUBLE
williamr@4
   114
  _Self& operator>> (long double& __val);
williamr@4
   115
# endif
williamr@4
   116
# ifndef _STLP_NO_BOOL
williamr@4
   117
  _Self& operator>> (bool& __val);
williamr@4
   118
# endif
williamr@4
   119
  _Self& operator>> (void*& __val);
williamr@4
   120
williamr@4
   121
public:                         // Copying characters into a streambuf.
williamr@4
   122
  _Self& operator>>(basic_streambuf<_CharT, _Traits>*);
williamr@4
   123
williamr@4
   124
public:                         // Unformatted input.
williamr@4
   125
  streamsize gcount() const { return _M_gcount; }
williamr@4
   126
  int_type peek();
williamr@4
   127
williamr@4
   128
public:                         // get() for single characters
williamr@4
   129
  int_type get();
williamr@4
   130
  _Self& get(char_type& __c);
williamr@4
   131
williamr@4
   132
public:                         // get() for character arrays.
williamr@4
   133
  _Self& get(char_type* __s, streamsize __n, char_type __delim);
williamr@4
   134
  _Self& get(char_type* __s, streamsize __n)
williamr@4
   135
    { return get(__s, __n, this->widen('\n')); }
williamr@4
   136
williamr@4
   137
public:                         // get() for streambufs
williamr@4
   138
  _Self& get(basic_streambuf<_CharT, _Traits>& __buf,
williamr@4
   139
                     char_type __delim);
williamr@4
   140
  _Self& get(basic_streambuf<_CharT, _Traits>& __buf)
williamr@4
   141
    { return get(__buf, this->widen('\n')); }
williamr@4
   142
williamr@4
   143
public:                         // getline()
williamr@4
   144
  _Self& getline(char_type* __s, streamsize __n, char_type delim);
williamr@4
   145
  _Self& getline(char_type* __s, streamsize __n)
williamr@4
   146
    { return getline(__s, __n, this->widen('\n')); }
williamr@4
   147
williamr@4
   148
public:                         // read(), readsome(), ignore()
williamr@4
   149
  _Self& ignore();
williamr@4
   150
  _Self& ignore(streamsize __n);
williamr@4
   151
#if (defined (_STLP_MSVC) && _STLP_MSVC < 1200)
williamr@4
   152
  inline
williamr@4
   153
#endif
williamr@4
   154
  _Self& ignore(streamsize __n, int_type __delim);
williamr@4
   155
williamr@4
   156
  _Self& read(char_type* __s, streamsize __n);
williamr@4
   157
  streamsize readsome(char_type* __s, streamsize __n);
williamr@4
   158
williamr@4
   159
public:                         // putback
williamr@4
   160
  _Self& putback(char_type __c);
williamr@4
   161
  _Self& unget();
williamr@4
   162
williamr@4
   163
public:                         // Positioning and buffer control.
williamr@4
   164
  int sync();
williamr@4
   165
williamr@4
   166
  pos_type tellg();
williamr@4
   167
  _Self& seekg(pos_type __pos);
williamr@4
   168
  _Self& seekg(off_type, ios_base::seekdir);
williamr@4
   169
williamr@4
   170
public:                         // Helper functions for non-member extractors.
williamr@4
   171
  void _M_formatted_get(_CharT& __c);
williamr@4
   172
  void _M_formatted_get(_CharT* __s);
williamr@4
   173
  void _M_skip_whitespace(bool __set_failbit);
williamr@4
   174
williamr@4
   175
private:                        // Number of characters extracted by the
williamr@4
   176
  streamsize _M_gcount;         // most recent unformatted input function.
williamr@4
   177
williamr@4
   178
public:
williamr@4
   179
williamr@4
   180
#if defined (_STLP_USE_TEMPLATE_EXPORT)
williamr@4
   181
  // If we are using DLL specs, we have not to use inner classes
williamr@4
   182
  // end class declaration here
williamr@4
   183
  typedef _Isentry<_CharT, _Traits>      sentry;
williamr@4
   184
};
williamr@4
   185
#  define sentry _Isentry
williamr@4
   186
template <class _CharT, class _Traits>
williamr@4
   187
class _Isentry {
williamr@4
   188
  typedef _Isentry<_CharT, _Traits> _Self;
williamr@4
   189
# else
williamr@4
   190
  class sentry {
williamr@4
   191
    typedef sentry _Self;
williamr@4
   192
#endif
williamr@4
   193
williamr@4
   194
  private:
williamr@4
   195
    const bool _M_ok;
williamr@4
   196
    //    basic_streambuf<_CharT, _Traits>* _M_buf;
williamr@4
   197
williamr@4
   198
  public:
williamr@4
   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@4
   205
      {}
williamr@4
   206
williamr@4
   207
    // Calling this constructor is the same as calling the previous one with
williamr@4
   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@4
   212
    ~sentry() {}
williamr@4
   213
williamr@4
   214
    operator bool() const { return _M_ok; }
williamr@4
   215
williamr@4
   216
  private:                        // Disable assignment and copy constructor.
williamr@4
   217
    //Implementation is here only to avoid warning with some compilers.
williamr@4
   218
    sentry(const _Self&) : _M_ok(false) {}
williamr@4
   219
    _Self& operator=(const _Self&) { return *this; }
williamr@4
   220
  };
williamr@4
   221
williamr@4
   222
# if defined (_STLP_USE_TEMPLATE_EXPORT)
williamr@4
   223
#  undef sentry
williamr@4
   224
# else
williamr@4
   225
  // close basic_istream class definition here
williamr@4
   226
};
williamr@4
   227
# endif
williamr@4
   228
williamr@4
   229
# if defined (_STLP_USE_TEMPLATE_EXPORT)
williamr@4
   230
_STLP_EXPORT_TEMPLATE_CLASS _Isentry<char, char_traits<char> >;
williamr@4
   231
_STLP_EXPORT_TEMPLATE_CLASS basic_istream<char, char_traits<char> >;
williamr@4
   232
#  if ! defined (_STLP_NO_WCHAR_T)
williamr@4
   233
_STLP_EXPORT_TEMPLATE_CLASS _Isentry<wchar_t, char_traits<wchar_t> >;
williamr@4
   234
_STLP_EXPORT_TEMPLATE_CLASS basic_istream<wchar_t, char_traits<wchar_t> >;
williamr@4
   235
#  endif
williamr@4
   236
# endif /* _STLP_USE_TEMPLATE_EXPORT */
williamr@4
   237
williamr@4
   238
// Non-member character and string extractor functions.
williamr@4
   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@4
   244
}
williamr@4
   245
williamr@4
   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@4
   251
}
williamr@4
   252
williamr@4
   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@4
   258
}
williamr@4
   259
williamr@4
   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@4
   265
}
williamr@4
   266
williamr@4
   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@4
   272
}
williamr@4
   273
williamr@4
   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@4
   279
}
williamr@4
   280
williamr@4
   281
//----------------------------------------------------------------------
williamr@4
   282
// istream manipulator.
williamr@4
   283
template <class _CharT, class _Traits>
williamr@4
   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@4
   325
williamr@4
   326
//----------------------------------------------------------------------
williamr@4
   327
// Class iostream.
williamr@4
   328
template <class _CharT, class _Traits>
williamr@4
   329
class basic_iostream
williamr@4
   330
  : public basic_istream<_CharT, _Traits>,
williamr@4
   331
    public basic_ostream<_CharT, _Traits>
williamr@4
   332
{
williamr@4
   333
public:
williamr@4
   334
  typedef basic_ios<_CharT, _Traits> _Basic_ios;
williamr@4
   335
williamr@4
   336
  explicit basic_iostream(basic_streambuf<_CharT, _Traits>* __buf);
williamr@4
   337
  virtual ~basic_iostream();
williamr@4
   338
};
williamr@4
   339
williamr@4
   340
# if defined (_STLP_USE_TEMPLATE_EXPORT)
williamr@4
   341
_STLP_EXPORT_TEMPLATE_CLASS basic_iostream<char, char_traits<char> >;
williamr@4
   342
williamr@4
   343
#  if ! defined (_STLP_NO_WCHAR_T)
williamr@4
   344
_STLP_EXPORT_TEMPLATE_CLASS basic_iostream<wchar_t, char_traits<wchar_t> >;
williamr@4
   345
#  endif
williamr@4
   346
# endif /* _STLP_USE_TEMPLATE_EXPORT */
williamr@4
   347
williamr@4
   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@4
   351
williamr@4
   352
_STLP_END_NAMESPACE
williamr@4
   353
williamr@4
   354
#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
williamr@4
   355
#  include <stl/_istream.c>
williamr@4
   356
#endif
williamr@4
   357
williamr@4
   358
#endif /* _STLP_INTERNAL_ISTREAM */
williamr@4
   359
williamr@4
   360
// Local Variables:
williamr@4
   361
// mode:C++
williamr@4
   362
// End: