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