home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / IOSTREAM.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  3.0 KB  |  130 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - iostream.cpp
  3.  * Class iostream member functions
  4.  *-----------------------------------------------------------------------*/
  5.  
  6. /*[]------------------------------------------------------------[]*/
  7. /*|                                                              |*/
  8. /*|     Turbo C++ Run Time Library - Version 1.0                 |*/
  9. /*|                                                              |*/
  10. /*|                                                              |*/
  11. /*|     Copyright (c) 1990 by Borland International              |*/
  12. /*|     All Rights Reserved.                                     |*/
  13. /*|                                                              |*/
  14. /*[]------------------------------------------------------------[]*/
  15.  
  16. #include "filesys.h"
  17. #include <fstream.h>
  18.  
  19. iostream::iostream(streambuf* s) :
  20.         istream(),
  21.         ostream()
  22. {
  23.     ios::init(s);
  24. }
  25.  
  26.  
  27. iostream::iostream() :
  28.         istream(),
  29.         ostream()
  30. {
  31. }
  32.  
  33.  
  34. iostream::~iostream()
  35. {
  36. }
  37.  
  38.  
  39. /*
  40.  * iostream with assign
  41.  */
  42.  
  43. // does no initialization
  44. iostream_withassign::iostream_withassign() :
  45.         iostream()
  46. {
  47. }
  48.  
  49.  
  50. iostream_withassign::~iostream_withassign() { }    // nothing to do
  51.  
  52.  
  53. // gets buffer from iostream and does entire initialization
  54. iostream_withassign& iostream_withassign::operator= (ios& s)
  55. {
  56.     ios::init(s.rdbuf());
  57.     return *this;
  58. }
  59.  
  60.  
  61. // associates streambuf with stream and does entire initialization
  62. iostream_withassign& iostream_withassign::operator= (streambuf* s)
  63. {
  64.     ios::init(s);
  65.     return *this;
  66. }
  67.  
  68.  
  69. /*
  70.  * one-time initializer for standard files
  71.  */
  72.  
  73. // this allows calling a constructor for an existing object
  74. inline void * operator new(size_t, void *p)
  75. {
  76.     return p;
  77. }
  78.  
  79. istream_withassign cin;
  80. ostream_withassign cout;
  81. ostream_withassign cerr;
  82. ostream_withassign clog;
  83.  
  84. static filebuf *stdin_filebuf;
  85. static filebuf *stdout_filebuf;
  86. static filebuf *stderr_filebuf;
  87.  
  88.  
  89. #pragma warn -use
  90. static void Iostream_init()
  91. {
  92. #pragma startup Iostream_init 16
  93.  
  94.     stdin_filebuf = new filebuf(F_stdin);
  95.     stdout_filebuf = new filebuf(F_stdout);
  96.     stderr_filebuf = new filebuf(F_stderr);
  97.  
  98.     // call constructors for standard streams
  99.     new (&cin) istream_withassign;
  100.     new (&cout) ostream_withassign;
  101.     new (&cerr) ostream_withassign;
  102.     new (&clog) ostream_withassign;
  103.     // attach the standard files to the standard streams
  104.     cin = stdin_filebuf;
  105.     cout = stdout_filebuf;
  106.     clog = stderr_filebuf;
  107.     cerr = stderr_filebuf;
  108.  
  109.     // tie cin, cerr, and clog to cout
  110.     cin.tie(&cout);
  111.     clog.tie(&cout);
  112.     cerr.tie(&cout);
  113.  
  114.     // unit-buffer cerr
  115.     cerr.setf(ios::unitbuf);
  116.  
  117.     // if cout is the screen, unit-buffer it too
  118.     if( isatty(1) )
  119.     cout.setf(ios::unitbuf);
  120. }
  121.  
  122. void Iostream_delete()
  123. {
  124. #pragma exit Iostream_delete 16
  125.  
  126.     delete stdin_filebuf;
  127.     delete stdout_filebuf;
  128.     delete stderr_filebuf;
  129. }
  130.