home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / istream.h < prev    next >
C/C++ Source or Header  |  1998-06-17  |  7KB  |  214 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  /* _MSC_VER > 1000 */
  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  /* !defined (_WIN32) && !defined (_MAC) */
  27.  
  28. #ifndef _CRTBLD
  29. /* This version of the header files is NOT for user programs.
  30.  * It is intended for use when building the C runtimes ONLY.
  31.  * The version intended for public use will not have this message.
  32.  */
  33. #error ERROR: Use of C runtime library internal header file.
  34. #endif  /* _CRTBLD */
  35.  
  36. #ifdef _MSC_VER
  37. // Currently, all MS C compilers for Win32 platforms default to 8 byte
  38. // alignment.
  39. #pragma pack(push,8)
  40.  
  41. #include <useoldio.h>
  42.  
  43. #endif  /* _MSC_VER */
  44.  
  45. /* Define _CRTIMP */
  46.  
  47. #ifndef _CRTIMP
  48. #ifdef CRTDLL
  49. #define _CRTIMP __declspec(dllexport)
  50. #else  /* CRTDLL */
  51. #ifdef _DLL
  52. #define _CRTIMP __declspec(dllimport)
  53. #else  /* _DLL */
  54. #define _CRTIMP
  55. #endif  /* _DLL */
  56. #endif  /* CRTDLL */
  57. #endif  /* _CRTIMP */
  58.  
  59. #ifndef _INTERNAL_IFSTRIP_
  60. /* Define _CRTIMP1 */
  61.  
  62. #ifndef _CRTIMP1
  63. #ifdef CRTDLL1
  64. #define _CRTIMP1 __declspec(dllexport)
  65. #else  /* CRTDLL1 */
  66. #define _CRTIMP1 _CRTIMP
  67. #endif  /* CRTDLL1 */
  68. #endif  /* _CRTIMP1 */
  69. #endif  /* _INTERNAL_IFSTRIP_ */
  70.  
  71. #include <ios.h>
  72.  
  73. #ifdef _MSC_VER
  74. // C4069: "long double != double"
  75. #pragma warning(disable:4069)   // disable C4069 warning
  76. // #pragma warning(default:4069)    // use this to reenable, if desired
  77.  
  78. // C4514: "unreferenced inline function has been removed"
  79. #pragma warning(disable:4514) // disable C4514 warning
  80. // #pragma warning(default:4514)    // use this to reenable, if desired
  81. #endif  /* _MSC_VER */
  82.  
  83. #ifndef _INTERNAL_IFSTRIP_
  84. #define MAXLONGSIZ  16
  85. #endif  /* _INTERNAL_IFSTRIP_ */
  86.  
  87. typedef long streamoff, streampos;
  88.  
  89. class _CRTIMP1 istream : virtual public ios {
  90.  
  91. public:
  92.     istream(streambuf*);
  93.     virtual ~istream();
  94.  
  95.     int  ipfx(int =0);
  96.     void isfx() { unlockbuf(); unlock(); }
  97.  
  98.     inline istream& operator>>(istream& (__cdecl * _f)(istream&));
  99.     inline istream& operator>>(ios& (__cdecl * _f)(ios&));
  100.     istream& operator>>(char *);
  101.     inline istream& operator>>(unsigned char *);
  102.     inline istream& operator>>(signed char *);
  103.     istream& operator>>(char &);
  104.     inline istream& operator>>(unsigned char &);
  105.     inline istream& operator>>(signed char &);
  106.     istream& operator>>(short &);
  107.     istream& operator>>(unsigned short &);
  108.     istream& operator>>(int &);
  109.     istream& operator>>(unsigned int &);
  110.     istream& operator>>(long &);
  111.     istream& operator>>(unsigned long &);
  112.     istream& operator>>(float &);
  113.     istream& operator>>(double &);
  114.     istream& operator>>(long double &);
  115.     istream& operator>>(streambuf*);
  116.  
  117.     int get();
  118.  
  119.     inline istream& get(         char *,int,char ='\n');
  120.     inline istream& get(unsigned char *,int,char ='\n');
  121.     inline istream& get(  signed char *,int,char ='\n');
  122.  
  123.     istream& get(char &);
  124.     inline istream& get(unsigned char &);
  125.     inline istream& get(  signed char &);
  126.  
  127.     istream& get(streambuf&,char ='\n');
  128.     inline istream& getline(         char *,int,char ='\n');
  129.     inline istream& getline(unsigned char *,int,char ='\n');
  130.     inline istream& getline(  signed char *,int,char ='\n');
  131.  
  132.     inline istream& ignore(int =1,int =EOF);
  133.     istream& read(char *,int);
  134.     inline istream& read(unsigned char *,int);
  135.     inline istream& read(signed char *,int);
  136.  
  137.     int gcount() const { return x_gcount; }
  138.     int peek();
  139.     istream& putback(char);
  140.     int sync();
  141.  
  142.     istream& seekg(streampos);
  143.     istream& seekg(streamoff,ios::seek_dir);
  144.     streampos tellg();
  145.  
  146.     void eatwhite();
  147.  
  148. protected:
  149.     istream();
  150.     istream(const istream&);    // treat as private
  151.     istream& operator=(streambuf* _isb); // treat as private
  152.     istream& operator=(const istream& _is) { return operator=(_is.rdbuf()); }
  153.     istream& get(char *, int, int);
  154.      int do_ipfx(int);
  155.  
  156. private:
  157.     istream(ios&);
  158.     int getint(char *);
  159.     int getdouble(char *, int);
  160.     int _fGline;
  161.     int x_gcount;
  162. };
  163.  
  164.     inline istream& istream::operator>>(istream& (__cdecl * _f)(istream&)) { (*_f)(*this); return *this; }
  165.     inline istream& istream::operator>>(ios& (__cdecl * _f)(ios&)) { (*_f)(*this); return *this; }
  166.  
  167.     inline istream& istream::operator>>(unsigned char * _s) { return operator>>((char *)_s); }
  168.     inline istream& istream::operator>>(  signed char * _s) { return operator>>((char *)_s); }
  169.  
  170.     inline istream& istream::operator>>(unsigned char & _c) { return operator>>((char &) _c); }
  171.     inline istream& istream::operator>>(  signed char & _c) { return operator>>((char &) _c); }
  172.  
  173.     inline istream& istream::get(         char * _b, int _lim, char _delim) { return get(        _b, _lim, (int)(unsigned char)_delim); }
  174.     inline istream& istream::get(unsigned char * _b, int _lim, char _delim) { return get((char *)_b, _lim, (int)(unsigned char)_delim); }
  175.     inline istream& istream::get(signed   char * _b, int _lim, char _delim) { return get((char *)_b, _lim, (int)(unsigned char)_delim); }
  176.  
  177.     inline istream& istream::get(unsigned char & _c) { return get((char &)_c); }
  178.     inline istream& istream::get(  signed char & _c) { return get((char &)_c); }
  179.  
  180.     inline istream& istream::getline(         char * _b,int _lim,char _delim) { lock(); _fGline++; get(        _b, _lim, (int)(unsigned char)_delim); unlock(); return *this; }
  181.     inline istream& istream::getline(unsigned char * _b,int _lim,char _delim) { lock(); _fGline++; get((char *)_b, _lim, (int)(unsigned char)_delim); unlock(); return *this; }
  182.     inline istream& istream::getline(  signed char * _b,int _lim,char _delim) { lock(); _fGline++; get((char *)_b, _lim, (int)(unsigned char)_delim); unlock(); return *this; }
  183.  
  184.     inline istream& istream::ignore(int _n,int _delim) { lock(); _fGline++; get((char *)0, _n+1, _delim); unlock(); return *this; }
  185.  
  186.     inline istream& istream::read(unsigned char * _ptr, int _n) { return read((char *) _ptr, _n); }
  187.     inline istream& istream::read(  signed char * _ptr, int _n) { return read((char *) _ptr, _n); }
  188.  
  189. class _CRTIMP1 istream_withassign : public istream {
  190.         public:
  191.             istream_withassign();
  192.             istream_withassign(streambuf*);
  193.             ~istream_withassign();
  194.     istream& operator=(const istream& _is) { return istream::operator=(_is); }
  195.     istream& operator=(streambuf* _isb) { return istream::operator=(_isb); }
  196. };
  197.  
  198. extern _CRTIMP1 istream_withassign cin;
  199.  
  200. inline _CRTIMP1 istream& __cdecl ws(istream& _ins) { _ins.eatwhite(); return _ins; }
  201.  
  202. _CRTIMP1 ios&        __cdecl dec(ios&);
  203. _CRTIMP1 ios&        __cdecl hex(ios&);
  204. _CRTIMP1 ios&        __cdecl oct(ios&);
  205.  
  206. #ifdef _MSC_VER
  207. // Restore default packing
  208. #pragma pack(pop)
  209. #endif  /* _MSC_VER */
  210.  
  211. #endif  /* _INC_ISTREAM */
  212.  
  213. #endif  /* __cplusplus */
  214.