ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

_istream.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */
00018 #ifndef _STLP_INTERNAL_ISTREAM
00019 #define _STLP_INTERNAL_ISTREAM
00020 
00021 // this block is included by _ostream.h, we include it here to lower #include level
00022 #if defined (_STLP_HAS_WCHAR_T) && !defined (_STLP_INTERNAL_CWCHAR)
00023 #  include <stl/_cwchar.h>
00024 #endif
00025 
00026 #ifndef _STLP_INTERNAL_IOS_H
00027 #  include <stl/_ios.h>                  // For basic_ios<>.  Includes <iosfwd>.
00028 #endif
00029 
00030 #ifndef _STLP_INTERNAL_OSTREAM_H
00031 #  include <stl/_ostream.h>              // Needed as a base class of basic_iostream.
00032 #endif
00033 
00034 #ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
00035 #  include <stl/_istreambuf_iterator.h>
00036 #endif
00037 
00038 #include <stl/_ctraits_fns.h>    // Helper functions that allow char traits
00039                                 // to be used as function objects.
00040 _STLP_BEGIN_NAMESPACE
00041 
00042 #if defined (_STLP_USE_TEMPLATE_EXPORT)
00043 template <class _CharT, class _Traits>
00044 class _Isentry;
00045 #endif
00046 
00047 struct _No_Skip_WS {};        // Dummy class used by sentry.
00048 
00049 template <class _CharT, class _Traits>
00050 bool _M_init_skip(basic_istream<_CharT, _Traits>& __istr);
00051 template <class _CharT, class _Traits>
00052 bool _M_init_noskip(basic_istream<_CharT, _Traits>& __istr);
00053 
00054 //----------------------------------------------------------------------
00055 // Class basic_istream, a class that performs formatted input through
00056 // a stream buffer.
00057 
00058 // The second template parameter, _Traits, defaults to char_traits<_CharT>.
00059 // The default is declared in header <iosfwd>, and it isn't declared here
00060 // because C++ language rules do not allow it to be declared twice.
00061 
00062 template <class _CharT, class _Traits>
00063 class basic_istream : virtual public basic_ios<_CharT, _Traits> {
00064   typedef basic_istream<_CharT, _Traits> _Self;
00065 
00066 #if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310)
00067   //explicitely defined as private to avoid warnings:
00068   basic_istream(_Self const&);
00069   _Self& operator = (_Self const&);
00070 #endif
00071 
00072 public:
00073                          // Types
00074   typedef _CharT                     char_type;
00075   typedef typename _Traits::int_type int_type;
00076   typedef typename _Traits::pos_type pos_type;
00077   typedef typename _Traits::off_type off_type;
00078   typedef _Traits                    traits_type;
00079   typedef basic_ios<_CharT, _Traits>     _Basic_ios;
00080 
00081   typedef basic_ios<_CharT, _Traits>& (_STLP_CALL *__ios_fn)(basic_ios<_CharT, _Traits>&);
00082   typedef ios_base& (_STLP_CALL *__ios_base_fn)(ios_base&);
00083   typedef _Self& (_STLP_CALL *__istream_fn)(_Self&);
00084 
00085 public:                         // Constructor and destructor.
00086   explicit basic_istream(basic_streambuf<_CharT, _Traits>* __buf) :
00087     basic_ios<_CharT, _Traits>(), _M_gcount(0) {
00088     this->init(__buf);
00089   }
00090   ~basic_istream() {};
00091 
00092 public:                         // Nested sentry class.
00093 
00094 public:                         // Hooks for manipulators.  The arguments are
00095                                 // function pointers.
00096   _Self& operator>> (__istream_fn __f) { return __f(*this); }
00097   _Self& operator>> (__ios_fn __f) {  __f(*this); return *this; }
00098   _Self& operator>> (__ios_base_fn __f) { __f(*this); return *this; }
00099 
00100 public:                         // Formatted input of numbers.
00101   _Self& operator>> (short& __val);
00102   _Self& operator>> (int& __val);
00103   _Self& operator>> (unsigned short& __val);
00104   _Self& operator>> (unsigned int& __val);
00105   _Self& operator>> (long& __val);
00106   _Self& operator>> (unsigned long& __val);
00107 #ifdef _STLP_LONG_LONG
00108   _Self& operator>> (_STLP_LONG_LONG& __val);
00109   _Self& operator>> (unsigned _STLP_LONG_LONG& __val);
00110 #endif
00111   _Self& operator>> (float& __val);
00112   _Self& operator>> (double& __val);
00113 # ifndef _STLP_NO_LONG_DOUBLE
00114   _Self& operator>> (long double& __val);
00115 # endif
00116 # ifndef _STLP_NO_BOOL
00117   _Self& operator>> (bool& __val);
00118 # endif
00119   _Self& operator>> (void*& __val);
00120 
00121 public:                         // Copying characters into a streambuf.
00122   _Self& operator>>(basic_streambuf<_CharT, _Traits>*);
00123 
00124 public:                         // Unformatted input.
00125   streamsize gcount() const { return _M_gcount; }
00126   int_type peek();
00127 
00128 public:                         // get() for single characters
00129   int_type get();
00130   _Self& get(char_type& __c);
00131 
00132 public:                         // get() for character arrays.
00133   _Self& get(char_type* __s, streamsize __n, char_type __delim);
00134   _Self& get(char_type* __s, streamsize __n)
00135     { return get(__s, __n, this->widen('\n')); }
00136 
00137 public:                         // get() for streambufs
00138   _Self& get(basic_streambuf<_CharT, _Traits>& __buf,
00139                      char_type __delim);
00140   _Self& get(basic_streambuf<_CharT, _Traits>& __buf)
00141     { return get(__buf, this->widen('\n')); }
00142 
00143 public:                         // getline()
00144   _Self& getline(char_type* __s, streamsize __n, char_type delim);
00145   _Self& getline(char_type* __s, streamsize __n)
00146     { return getline(__s, __n, this->widen('\n')); }
00147 
00148 public:                         // read(), readsome(), ignore()
00149   _Self& ignore();
00150   _Self& ignore(streamsize __n);
00151   _Self& ignore(streamsize __n, int_type __delim);
00152 
00153   _Self& read(char_type* __s, streamsize __n);
00154   streamsize readsome(char_type* __s, streamsize __n);
00155 
00156 public:                         // putback
00157   _Self& putback(char_type __c);
00158   _Self& unget();
00159 
00160 public:                         // Positioning and buffer control.
00161   int sync();
00162 
00163   pos_type tellg();
00164   _Self& seekg(pos_type __pos);
00165   _Self& seekg(off_type, ios_base::seekdir);
00166 
00167 public:                         // Helper functions for non-member extractors.
00168   void _M_formatted_get(_CharT& __c);
00169   void _M_formatted_get(_CharT* __s);
00170   void _M_skip_whitespace(bool __set_failbit);
00171 
00172 private:                        // Number of characters extracted by the
00173   streamsize _M_gcount;         // most recent unformatted input function.
00174 
00175 public:
00176 
00177 #if defined (_STLP_USE_TEMPLATE_EXPORT)
00178   // If we are using DLL specs, we have not to use inner classes
00179   // end class declaration here
00180   typedef _Isentry<_CharT, _Traits>      sentry;
00181 };
00182 #  define sentry _Isentry
00183 template <class _CharT, class _Traits>
00184 class _Isentry {
00185   typedef _Isentry<_CharT, _Traits> _Self;
00186 # else
00187   class sentry {
00188     typedef sentry _Self;
00189 #endif
00190 
00191   private:
00192     const bool _M_ok;
00193     //    basic_streambuf<_CharT, _Traits>* _M_buf;
00194 
00195   public:
00196     typedef _Traits traits_type;
00197 
00198     explicit sentry(basic_istream<_CharT, _Traits>& __istr,
00199                     bool __noskipws = false) :
00200       _M_ok((__noskipws || !(__istr.flags() & ios_base::skipws)) ? _M_init_noskip(__istr) : _M_init_skip(__istr) )
00201       /* , _M_buf(__istr.rdbuf()) */
00202       {}
00203 
00204     // Calling this constructor is the same as calling the previous one with
00205     // __noskipws = true, except that it doesn't require a runtime test.
00206     sentry(basic_istream<_CharT, _Traits>& __istr, _No_Skip_WS) : /* _M_buf(__istr.rdbuf()), */
00207       _M_ok(_M_init_noskip(__istr)) {}
00208 
00209     ~sentry() {}
00210 
00211     operator bool() const { return _M_ok; }
00212 
00213   private:                        // Disable assignment and copy constructor.
00214     //Implementation is here only to avoid warning with some compilers.
00215     sentry(const _Self&) : _M_ok(false) {}
00216     _Self& operator=(const _Self&) { return *this; }
00217   };
00218 
00219 # if defined (_STLP_USE_TEMPLATE_EXPORT)
00220 #  undef sentry
00221 # else
00222   // close basic_istream class definition here
00223 };
00224 # endif
00225 
00226 # if defined (_STLP_USE_TEMPLATE_EXPORT)
00227 _STLP_EXPORT_TEMPLATE_CLASS _Isentry<char, char_traits<char> >;
00228 _STLP_EXPORT_TEMPLATE_CLASS basic_istream<char, char_traits<char> >;
00229 #  if ! defined (_STLP_NO_WCHAR_T)
00230 _STLP_EXPORT_TEMPLATE_CLASS _Isentry<wchar_t, char_traits<wchar_t> >;
00231 _STLP_EXPORT_TEMPLATE_CLASS basic_istream<wchar_t, char_traits<wchar_t> >;
00232 #  endif
00233 # endif /* _STLP_USE_TEMPLATE_EXPORT */
00234 
00235 // Non-member character and string extractor functions.
00236 template <class _CharT, class _Traits>
00237 inline basic_istream<_CharT, _Traits>& _STLP_CALL
00238 operator>>(basic_istream<_CharT, _Traits>& __in_str, _CharT& __c) {
00239   __in_str._M_formatted_get(__c);
00240   return __in_str;
00241 }
00242 
00243 template <class _Traits>
00244 inline basic_istream<char, _Traits>& _STLP_CALL
00245 operator>>(basic_istream<char, _Traits>& __in_str, unsigned char& __c) {
00246   __in_str._M_formatted_get(__REINTERPRET_CAST(char&,__c));
00247   return __in_str;
00248 }
00249 
00250 template <class _Traits>
00251 inline basic_istream<char, _Traits>& _STLP_CALL
00252 operator>>(basic_istream<char, _Traits>& __in_str, signed char& __c) {
00253   __in_str._M_formatted_get(__REINTERPRET_CAST(char&,__c));
00254   return __in_str;
00255 }
00256 
00257 template <class _CharT, class _Traits>
00258 inline basic_istream<_CharT, _Traits>& _STLP_CALL
00259 operator>>(basic_istream<_CharT, _Traits>& __in_str, _CharT* __s) {
00260   __in_str._M_formatted_get(__s);
00261   return __in_str;
00262 }
00263 
00264 template <class _Traits>
00265 inline basic_istream<char, _Traits>& _STLP_CALL
00266 operator>>(basic_istream<char, _Traits>& __in_str, unsigned char* __s) {
00267   __in_str._M_formatted_get(__REINTERPRET_CAST(char*,__s));
00268   return __in_str;
00269 }
00270 
00271 template <class _Traits>
00272 inline basic_istream<char, _Traits>& _STLP_CALL
00273 operator>>(basic_istream<char, _Traits>& __in_str, signed char* __s) {
00274   __in_str._M_formatted_get(__REINTERPRET_CAST(char*,__s));
00275   return __in_str;
00276 }
00277 
00278 //----------------------------------------------------------------------
00279 // istream manipulator.
00280 template <class _CharT, class _Traits>
00281 basic_istream<_CharT, _Traits>& _STLP_CALL
00282 ws(basic_istream<_CharT, _Traits>& __istr) {
00283   if (!__istr.eof()) {
00284     typedef typename basic_istream<_CharT, _Traits>::sentry      _Sentry;
00285     _Sentry __sentry(__istr, _No_Skip_WS()); // Don't skip whitespace.
00286     if (__sentry)
00287       __istr._M_skip_whitespace(false);
00288   }
00289   return __istr;
00290 }
00291 
00292 // Helper functions for istream<>::sentry constructor.
00293 template <class _CharT, class _Traits>
00294 inline bool _M_init_skip(basic_istream<_CharT, _Traits>& __istr) {
00295   if (__istr.good()) {
00296     if (__istr.tie())
00297       __istr.tie()->flush();
00298 
00299     __istr._M_skip_whitespace(true);
00300   }
00301 
00302   if (!__istr.good()) {
00303     __istr.setstate(ios_base::failbit);
00304     return false;
00305   } else
00306     return true;
00307 }
00308 
00309 template <class _CharT, class _Traits>
00310 inline bool _M_init_noskip(basic_istream<_CharT, _Traits>& __istr) {
00311   if (__istr.good()) {
00312     if (__istr.tie())
00313       __istr.tie()->flush();
00314 
00315     if (!__istr.rdbuf())
00316       __istr.setstate(ios_base::badbit);
00317   }
00318   else
00319     __istr.setstate(ios_base::failbit);
00320   return __istr.good();
00321 }
00322 
00323 //----------------------------------------------------------------------
00324 // Class iostream.
00325 template <class _CharT, class _Traits>
00326 class basic_iostream
00327   : public basic_istream<_CharT, _Traits>,
00328     public basic_ostream<_CharT, _Traits>
00329 {
00330 public:
00331   typedef basic_ios<_CharT, _Traits> _Basic_ios;
00332 
00333   explicit basic_iostream(basic_streambuf<_CharT, _Traits>* __buf);
00334   virtual ~basic_iostream();
00335 };
00336 
00337 # if defined (_STLP_USE_TEMPLATE_EXPORT)
00338 _STLP_EXPORT_TEMPLATE_CLASS basic_iostream<char, char_traits<char> >;
00339 
00340 #  if ! defined (_STLP_NO_WCHAR_T)
00341 _STLP_EXPORT_TEMPLATE_CLASS basic_iostream<wchar_t, char_traits<wchar_t> >;
00342 #  endif
00343 # endif /* _STLP_USE_TEMPLATE_EXPORT */
00344 
00345 template <class _CharT, class _Traits>
00346 basic_streambuf<_CharT, _Traits>* _STLP_CALL _M_get_istreambuf(basic_istream<_CharT, _Traits>& __istr)
00347 { return __istr.rdbuf(); }
00348 
00349 _STLP_END_NAMESPACE
00350 
00351 #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
00352 #  include <stl/_istream.c>
00353 #endif
00354 
00355 #endif /* _STLP_INTERNAL_ISTREAM */
00356 
00357 // Local Variables:
00358 // mode:C++
00359 // End:

Generated on Sun May 27 2012 04:29:09 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.