home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / ostream.h < prev    next >
C/C++ Source or Header  |  1998-06-17  |  6KB  |  181 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  /* _MSC_VER > 1000 */
  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  /* !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. // C4514: "unreferenced inline function has been removed"
  75. #pragma warning(disable:4514) // disable C4514 warning
  76. // #pragma warning(default:4514)        // use this to reenable, if desired
  77. #endif  /* _MSC_VER */
  78.  
  79. typedef long streamoff, streampos;
  80.  
  81. class _CRTIMP1 ostream : virtual public ios {
  82.  
  83. public:
  84.         ostream(streambuf*);
  85.         virtual ~ostream();
  86.  
  87.         ostream& flush();
  88.         int  opfx();
  89.         void osfx();
  90.  
  91. inline  ostream& operator<<(ostream& (__cdecl * _f)(ostream&));
  92. inline  ostream& operator<<(ios& (__cdecl * _f)(ios&));
  93.         ostream& operator<<(const char *);
  94. inline  ostream& operator<<(const unsigned char *);
  95. inline  ostream& operator<<(const signed char *);
  96. inline  ostream& operator<<(char);
  97.         ostream& operator<<(unsigned char);
  98. inline  ostream& operator<<(signed char);
  99.         ostream& operator<<(short);
  100.         ostream& operator<<(unsigned short);
  101.         ostream& operator<<(int);
  102.         ostream& operator<<(unsigned int);
  103.         ostream& operator<<(long);
  104.         ostream& operator<<(unsigned long);
  105. inline  ostream& operator<<(float);
  106.         ostream& operator<<(double);
  107.         ostream& operator<<(long double);
  108.         ostream& operator<<(const void *);
  109.         ostream& operator<<(streambuf*);
  110. inline  ostream& put(char);
  111.         ostream& put(unsigned char);
  112. inline  ostream& put(signed char);
  113.         ostream& write(const char *,int);
  114. inline  ostream& write(const unsigned char *,int);
  115. inline  ostream& write(const signed char *,int);
  116.         ostream& seekp(streampos);
  117.         ostream& seekp(streamoff,ios::seek_dir);
  118.         streampos tellp();
  119.  
  120. protected:
  121.         ostream();
  122.         ostream(const ostream&);        // treat as private
  123.         ostream& operator=(streambuf*); // treat as private
  124.         ostream& operator=(const ostream& _os) {return operator=(_os.rdbuf()); }
  125.         int do_opfx(int);               // not used
  126.         void do_osfx();                 // not used
  127.  
  128. private:
  129.         ostream(ios&);
  130.         ostream& writepad(const char *, const char *);
  131.         int x_floatused;
  132. };
  133.  
  134. inline ostream& ostream::operator<<(ostream& (__cdecl * _f)(ostream&)) { (*_f)(*this); return *this; }
  135. inline ostream& ostream::operator<<(ios& (__cdecl * _f)(ios& )) { (*_f)(*this); return *this; }
  136.  
  137. inline  ostream& ostream::operator<<(char _c) { return operator<<((unsigned char) _c); }
  138. inline  ostream& ostream::operator<<(signed char _c) { return operator<<((unsigned char) _c); }
  139.  
  140. inline  ostream& ostream::operator<<(const unsigned char * _s) { return operator<<((const char *) _s); }
  141. inline  ostream& ostream::operator<<(const signed char * _s) { return operator<<((const char *) _s); }
  142.  
  143. inline  ostream& ostream::operator<<(float _f) { x_floatused = 1; return operator<<((double) _f); }
  144.  
  145. inline  ostream& ostream::put(char _c) { return put((unsigned char) _c); }
  146. inline  ostream& ostream::put(signed char _c) { return put((unsigned char) _c); }
  147.  
  148. inline  ostream& ostream::write(const unsigned char * _s, int _n) { return write((char *) _s, _n); }
  149. inline  ostream& ostream::write(const signed char * _s, int _n) { return write((char *) _s, _n); }
  150.  
  151.  
  152. class _CRTIMP1 ostream_withassign : public ostream {
  153.         public:
  154.                 ostream_withassign();
  155.                 ostream_withassign(streambuf* _is);
  156.                 ~ostream_withassign();
  157.     ostream& operator=(const ostream& _os) { return ostream::operator=(_os.rdbuf()); }
  158.     ostream& operator=(streambuf* _sb) { return ostream::operator=(_sb); }
  159. };
  160.  
  161. extern ostream_withassign _CRTIMP1 cout;
  162. extern ostream_withassign _CRTIMP1 cerr;
  163. extern ostream_withassign _CRTIMP1 clog;
  164.  
  165. inline _CRTIMP1 ostream& __cdecl flush(ostream& _outs) { return _outs.flush(); }
  166. inline _CRTIMP1 ostream& __cdecl endl(ostream& _outs) { return _outs << '\n' << flush; }
  167. inline _CRTIMP1 ostream& __cdecl ends(ostream& _outs) { return _outs << char('\0'); }
  168.  
  169. _CRTIMP1 ios&           __cdecl dec(ios&);
  170. _CRTIMP1 ios&           __cdecl hex(ios&);
  171. _CRTIMP1 ios&           __cdecl oct(ios&);
  172.  
  173. #ifdef _MSC_VER
  174. // Restore default packing
  175. #pragma pack(pop)
  176. #endif  /* _MSC_VER */
  177.  
  178. #endif  /* _INC_OSTREAM */
  179.  
  180. #endif  /* __cplusplus */
  181.