home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / istream.h < prev    next >
C/C++ Source or Header  |  1998-06-16  |  6KB  |  189 lines

  1. /***
  2. *istream.h - definitions/declarations for the istream class
  3. *
  4. *       Copyright (c) 1990-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       This file defines the classes, values, macros, and functions
  8. *       used by the istream class.
  9. *       [AT&T C++]
  10. *
  11. *       [Public]
  12. *
  13. ****/
  14.  
  15. #if     _MSC_VER > 1000
  16. #pragma once
  17. #endif
  18.  
  19. #ifdef  __cplusplus
  20.  
  21. #ifndef _INC_ISTREAM
  22. #define _INC_ISTREAM
  23.  
  24. #if     !defined(_WIN32) && !defined(_MAC)
  25. #error ERROR: Only Mac or Win32 targets supported!
  26. #endif
  27.  
  28.  
  29. #ifdef  _MSC_VER
  30. // Currently, all MS C compilers for Win32 platforms default to 8 byte
  31. // alignment.
  32. #pragma pack(push,8)
  33.  
  34. #include <useoldio.h>
  35.  
  36. #endif  // _MSC_VER
  37.  
  38. /* Define _CRTIMP */
  39.  
  40. #ifndef _CRTIMP
  41. #ifdef  _DLL
  42. #define _CRTIMP __declspec(dllimport)
  43. #else   /* ndef _DLL */
  44. #define _CRTIMP
  45. #endif  /* _DLL */
  46. #endif  /* _CRTIMP */
  47.  
  48.  
  49. #include <ios.h>
  50.  
  51. #ifdef  _MSC_VER
  52. // C4069: "long double != double"
  53. #pragma warning(disable:4069)   // disable C4069 warning
  54. // #pragma warning(default:4069)    // use this to reenable, if desired
  55.  
  56. // C4514: "unreferenced inline function has been removed"
  57. #pragma warning(disable:4514) // disable C4514 warning
  58. // #pragma warning(default:4514)    // use this to reenable, if desired
  59. #endif  // _MSC_VER
  60.  
  61.  
  62. typedef long streamoff, streampos;
  63.  
  64. class _CRTIMP istream : virtual public ios {
  65.  
  66. public:
  67.     istream(streambuf*);
  68.     virtual ~istream();
  69.  
  70.     int  ipfx(int =0);
  71.     void isfx() { unlockbuf(); unlock(); }
  72.  
  73.     inline istream& operator>>(istream& (__cdecl * _f)(istream&));
  74.     inline istream& operator>>(ios& (__cdecl * _f)(ios&));
  75.     istream& operator>>(char *);
  76.     inline istream& operator>>(unsigned char *);
  77.     inline istream& operator>>(signed char *);
  78.     istream& operator>>(char &);
  79.     inline istream& operator>>(unsigned char &);
  80.     inline istream& operator>>(signed char &);
  81.     istream& operator>>(short &);
  82.     istream& operator>>(unsigned short &);
  83.     istream& operator>>(int &);
  84.     istream& operator>>(unsigned int &);
  85.     istream& operator>>(long &);
  86.     istream& operator>>(unsigned long &);
  87.     istream& operator>>(float &);
  88.     istream& operator>>(double &);
  89.     istream& operator>>(long double &);
  90.     istream& operator>>(streambuf*);
  91.  
  92.     int get();
  93.  
  94.     inline istream& get(         char *,int,char ='\n');
  95.     inline istream& get(unsigned char *,int,char ='\n');
  96.     inline istream& get(  signed char *,int,char ='\n');
  97.  
  98.     istream& get(char &);
  99.     inline istream& get(unsigned char &);
  100.     inline istream& get(  signed char &);
  101.  
  102.     istream& get(streambuf&,char ='\n');
  103.     inline istream& getline(         char *,int,char ='\n');
  104.     inline istream& getline(unsigned char *,int,char ='\n');
  105.     inline istream& getline(  signed char *,int,char ='\n');
  106.  
  107.     inline istream& ignore(int =1,int =EOF);
  108.     istream& read(char *,int);
  109.     inline istream& read(unsigned char *,int);
  110.     inline istream& read(signed char *,int);
  111.  
  112.     int gcount() const { return x_gcount; }
  113.     int peek();
  114.     istream& putback(char);
  115.     int sync();
  116.  
  117.     istream& seekg(streampos);
  118.     istream& seekg(streamoff,ios::seek_dir);
  119.     streampos tellg();
  120.  
  121.     void eatwhite();
  122.  
  123. protected:
  124.     istream();
  125.     istream(const istream&);    // treat as private
  126.     istream& operator=(streambuf* _isb); // treat as private
  127.     istream& operator=(const istream& _is) { return operator=(_is.rdbuf()); }
  128.     istream& get(char *, int, int);
  129.      int do_ipfx(int);
  130.  
  131. private:
  132.     istream(ios&);
  133.     int getint(char *);
  134.     int getdouble(char *, int);
  135.     int _fGline;
  136.     int x_gcount;
  137. };
  138.  
  139.     inline istream& istream::operator>>(istream& (__cdecl * _f)(istream&)) { (*_f)(*this); return *this; }
  140.     inline istream& istream::operator>>(ios& (__cdecl * _f)(ios&)) { (*_f)(*this); return *this; }
  141.  
  142.     inline istream& istream::operator>>(unsigned char * _s) { return operator>>((char *)_s); }
  143.     inline istream& istream::operator>>(  signed char * _s) { return operator>>((char *)_s); }
  144.  
  145.     inline istream& istream::operator>>(unsigned char & _c) { return operator>>((char &) _c); }
  146.     inline istream& istream::operator>>(  signed char & _c) { return operator>>((char &) _c); }
  147.  
  148.     inline istream& istream::get(         char * _b, int _lim, char _delim) { return get(        _b, _lim, (int)(unsigned char)_delim); }
  149.     inline istream& istream::get(unsigned char * _b, int _lim, char _delim) { return get((char *)_b, _lim, (int)(unsigned char)_delim); }
  150.     inline istream& istream::get(signed   char * _b, int _lim, char _delim) { return get((char *)_b, _lim, (int)(unsigned char)_delim); }
  151.  
  152.     inline istream& istream::get(unsigned char & _c) { return get((char &)_c); }
  153.     inline istream& istream::get(  signed char & _c) { return get((char &)_c); }
  154.  
  155.     inline istream& istream::getline(         char * _b,int _lim,char _delim) { lock(); _fGline++; get(        _b, _lim, (int)(unsigned char)_delim); unlock(); return *this; }
  156.     inline istream& istream::getline(unsigned char * _b,int _lim,char _delim) { lock(); _fGline++; get((char *)_b, _lim, (int)(unsigned char)_delim); unlock(); return *this; }
  157.     inline istream& istream::getline(  signed char * _b,int _lim,char _delim) { lock(); _fGline++; get((char *)_b, _lim, (int)(unsigned char)_delim); unlock(); return *this; }
  158.  
  159.     inline istream& istream::ignore(int _n,int _delim) { lock(); _fGline++; get((char *)0, _n+1, _delim); unlock(); return *this; }
  160.  
  161.     inline istream& istream::read(unsigned char * _ptr, int _n) { return read((char *) _ptr, _n); }
  162.     inline istream& istream::read(  signed char * _ptr, int _n) { return read((char *) _ptr, _n); }
  163.  
  164. class _CRTIMP istream_withassign : public istream {
  165.         public:
  166.             istream_withassign();
  167.             istream_withassign(streambuf*);
  168.             ~istream_withassign();
  169.     istream& operator=(const istream& _is) { return istream::operator=(_is); }
  170.     istream& operator=(streambuf* _isb) { return istream::operator=(_isb); }
  171. };
  172.  
  173. extern _CRTIMP istream_withassign cin;
  174.  
  175. inline _CRTIMP istream& __cdecl ws(istream& _ins) { _ins.eatwhite(); return _ins; }
  176.  
  177. _CRTIMP ios&        __cdecl dec(ios&);
  178. _CRTIMP ios&        __cdecl hex(ios&);
  179. _CRTIMP ios&        __cdecl oct(ios&);
  180.  
  181. #ifdef  _MSC_VER
  182. // Restore default packing
  183. #pragma pack(pop)
  184. #endif  // _MSC_VER
  185.  
  186. #endif  // _INC_ISTREAM
  187.  
  188. #endif  /* __cplusplus */
  189.