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

  1. /***
  2. *ostream.h - definitions/declarations for the ostream class
  3. *
  4. *       Copyright (c) 1991-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       This file defines the classes, values, macros, and functions
  8. *       used by the ostream 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_OSTREAM
  22. #define _INC_OSTREAM
  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. // C4514: "unreferenced inline function has been removed"
  53. #pragma warning(disable:4514) // disable C4514 warning
  54. // #pragma warning(default:4514)        // use this to reenable, if desired
  55. #endif  // _MSC_VER
  56.  
  57. typedef long streamoff, streampos;
  58.  
  59. class _CRTIMP ostream : virtual public ios {
  60.  
  61. public:
  62.         ostream(streambuf*);
  63.         virtual ~ostream();
  64.  
  65.         ostream& flush();
  66.         int  opfx();
  67.         void osfx();
  68.  
  69. inline  ostream& operator<<(ostream& (__cdecl * _f)(ostream&));
  70. inline  ostream& operator<<(ios& (__cdecl * _f)(ios&));
  71.         ostream& operator<<(const char *);
  72. inline  ostream& operator<<(const unsigned char *);
  73. inline  ostream& operator<<(const signed char *);
  74. inline  ostream& operator<<(char);
  75.         ostream& operator<<(unsigned char);
  76. inline  ostream& operator<<(signed char);
  77.         ostream& operator<<(short);
  78.         ostream& operator<<(unsigned short);
  79.         ostream& operator<<(int);
  80.         ostream& operator<<(unsigned int);
  81.         ostream& operator<<(long);
  82.         ostream& operator<<(unsigned long);
  83. inline  ostream& operator<<(float);
  84.         ostream& operator<<(double);
  85.         ostream& operator<<(long double);
  86.         ostream& operator<<(const void *);
  87.         ostream& operator<<(streambuf*);
  88. inline  ostream& put(char);
  89.         ostream& put(unsigned char);
  90. inline  ostream& put(signed char);
  91.         ostream& write(const char *,int);
  92. inline  ostream& write(const unsigned char *,int);
  93. inline  ostream& write(const signed char *,int);
  94.         ostream& seekp(streampos);
  95.         ostream& seekp(streamoff,ios::seek_dir);
  96.         streampos tellp();
  97.  
  98. protected:
  99.         ostream();
  100.         ostream(const ostream&);        // treat as private
  101.         ostream& operator=(streambuf*); // treat as private
  102.         ostream& operator=(const ostream& _os) {return operator=(_os.rdbuf()); }
  103.         int do_opfx(int);               // not used
  104.         void do_osfx();                 // not used
  105.  
  106. private:
  107.         ostream(ios&);
  108.         ostream& writepad(const char *, const char *);
  109.         int x_floatused;
  110. };
  111.  
  112. inline ostream& ostream::operator<<(ostream& (__cdecl * _f)(ostream&)) { (*_f)(*this); return *this; }
  113. inline ostream& ostream::operator<<(ios& (__cdecl * _f)(ios& )) { (*_f)(*this); return *this; }
  114.  
  115. inline  ostream& ostream::operator<<(char _c) { return operator<<((unsigned char) _c); }
  116. inline  ostream& ostream::operator<<(signed char _c) { return operator<<((unsigned char) _c); }
  117.  
  118. inline  ostream& ostream::operator<<(const unsigned char * _s) { return operator<<((const char *) _s); }
  119. inline  ostream& ostream::operator<<(const signed char * _s) { return operator<<((const char *) _s); }
  120.  
  121. inline  ostream& ostream::operator<<(float _f) { x_floatused = 1; return operator<<((double) _f); }
  122.  
  123. inline  ostream& ostream::put(char _c) { return put((unsigned char) _c); }
  124. inline  ostream& ostream::put(signed char _c) { return put((unsigned char) _c); }
  125.  
  126. inline  ostream& ostream::write(const unsigned char * _s, int _n) { return write((char *) _s, _n); }
  127. inline  ostream& ostream::write(const signed char * _s, int _n) { return write((char *) _s, _n); }
  128.  
  129.  
  130. class _CRTIMP ostream_withassign : public ostream {
  131.         public:
  132.                 ostream_withassign();
  133.                 ostream_withassign(streambuf* _is);
  134.                 ~ostream_withassign();
  135.     ostream& operator=(const ostream& _os) { return ostream::operator=(_os.rdbuf()); }
  136.     ostream& operator=(streambuf* _sb) { return ostream::operator=(_sb); }
  137. };
  138.  
  139. extern ostream_withassign _CRTIMP cout;
  140. extern ostream_withassign _CRTIMP cerr;
  141. extern ostream_withassign _CRTIMP clog;
  142.  
  143. inline _CRTIMP ostream& __cdecl flush(ostream& _outs) { return _outs.flush(); }
  144. inline _CRTIMP ostream& __cdecl endl(ostream& _outs) { return _outs << '\n' << flush; }
  145. inline _CRTIMP ostream& __cdecl ends(ostream& _outs) { return _outs << char('\0'); }
  146.  
  147. _CRTIMP ios&           __cdecl dec(ios&);
  148. _CRTIMP ios&           __cdecl hex(ios&);
  149. _CRTIMP ios&           __cdecl oct(ios&);
  150.  
  151. #ifdef  _MSC_VER
  152. // Restore default packing
  153. #pragma pack(pop)
  154. #endif  // _MSC_VER
  155.  
  156. #endif  // _INC_OSTREAM
  157.  
  158. #endif  /* __cplusplus */
  159.