home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / INCLUDE.ZIP / CONSTREA.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  4.7 KB  |  266 lines

  1. /*  constrea.h
  2.  
  3.     Defines the class constream, which writes output to the screen
  4.     using the iostream interface.
  5.  
  6.     Copyright (c) 1991, 1992 by Borland International
  7.     All Rights Reserved.
  8. */
  9.  
  10. #if !defined(__CONSTREA_H)
  11. #define __CONSTREA_H
  12.  
  13. #if defined( _Windows )
  14. #error constream not available for Windows
  15. #endif
  16.  
  17. #if !defined(__IOSTREAM_H)
  18. #include <iostream.h>
  19. #endif  // __IOSTREAM_H
  20.  
  21. #if !defined(__IOMANIP_H)
  22. #include <iomanip.h>
  23. #endif  // __IOMANIP_H
  24.  
  25. #if !defined(__CONIO_H)
  26. #include <conio.h>
  27. #endif  // __CONIO_H
  28.  
  29. class conbuf : public streambuf
  30. {
  31.  
  32. public:
  33.  
  34.     conbuf();
  35.     ~conbuf();
  36.     virtual int _Cdecl overflow( int = EOF );
  37.  
  38.     void _Cdecl clreol();
  39.  
  40.     void _Cdecl setcursortype( int );
  41.  
  42.     void _Cdecl highvideo();
  43.     void _Cdecl lowvideo();
  44.     void _Cdecl normvideo();
  45.  
  46.     void _Cdecl textattr( int );
  47.     void _Cdecl textbackground( int );
  48.     void _Cdecl textcolor( int );
  49.  
  50.     void _Cdecl gotoxy( int, int );
  51.     int  _Cdecl wherex();
  52.     int  _Cdecl wherey();
  53.  
  54.     void _Cdecl delline();
  55.     void _Cdecl insline();
  56.  
  57.     void _Cdecl clrscr();
  58.     void _Cdecl window( int, int, int, int );
  59.  
  60.     static void _Cdecl textmode( int );
  61.  
  62.     void activate();
  63.     void deactivate();
  64.  
  65. private:
  66.  
  67.     virtual void makeActive();
  68.     virtual void makeInactive();
  69.     virtual void swap();
  70.  
  71.     text_info data;
  72.     int cursortype;
  73.     static conbuf *current;
  74.  
  75. };
  76.  
  77. inline conbuf::~conbuf()
  78. {
  79.     current = 0;
  80. }
  81.  
  82. inline void conbuf::clreol()
  83. {
  84.     activate();
  85.     ::clreol();
  86. }
  87.  
  88. inline void conbuf::setcursortype( int t )
  89. {
  90.     activate();
  91.     cursortype = t;
  92.     ::_setcursortype( t );
  93. }
  94.  
  95. inline void _Cdecl conbuf::highvideo()
  96. {
  97.     activate();
  98.     ::highvideo();
  99. }
  100.  
  101. inline void _Cdecl conbuf::lowvideo()
  102. {
  103.     activate();
  104.     ::lowvideo();
  105. }
  106.  
  107. inline void _Cdecl conbuf::normvideo()
  108. {
  109.     activate();
  110.     ::normvideo();
  111. }
  112.  
  113. inline void conbuf::gotoxy( int x, int y )
  114. {
  115.     activate();
  116.     ::gotoxy( x, y );
  117. }
  118.  
  119. inline int _Cdecl conbuf::wherex()
  120. {
  121.     activate();
  122.     return ::wherex();
  123. }
  124.  
  125. inline int _Cdecl conbuf::wherey()
  126. {
  127.     activate();
  128.     return ::wherey();
  129. }
  130.  
  131. inline void conbuf::textattr( int a )
  132. {
  133.     activate();
  134.     ::textattr( a );
  135. }
  136.  
  137. inline void _Cdecl conbuf::textbackground(int newcolor)
  138. {
  139.     activate();
  140.     ::textbackground( newcolor );
  141. }
  142.  
  143. inline void _Cdecl conbuf::textcolor(int newcolor)
  144. {
  145.     activate();
  146.     ::textcolor( newcolor );
  147. }
  148.  
  149. inline void _Cdecl conbuf::delline()
  150. {
  151.     activate();
  152.     ::delline();
  153. }
  154.  
  155. inline void _Cdecl conbuf::insline()
  156. {
  157.     activate();
  158.     ::insline();
  159. }
  160.  
  161. inline void conbuf::clrscr()
  162. {
  163.     activate();
  164.     ::clrscr();
  165. }
  166.  
  167. inline void conbuf::window(int left, int top, int right, int bottom)
  168. {
  169.     activate();
  170.     ::window( left, top, right, bottom );
  171. }
  172.  
  173. inline void _Cdecl conbuf::textmode( int mode )
  174. {
  175.     ::textmode( mode );
  176. }
  177.  
  178. inline void conbuf::activate()
  179. {
  180.     if( current != this )
  181.         swap();
  182. }
  183.  
  184. inline void conbuf::deactivate()
  185. {
  186.     makeInactive();
  187. }
  188.  
  189. class constream : public ostream
  190. {
  191.  
  192. public:
  193.  
  194.     constream();
  195.  
  196.     conbuf* _Cdecl rdbuf();     // get the assigned conbuf
  197.  
  198.     void    _Cdecl clrscr();
  199.     void    _Cdecl window( int, int, int, int );
  200.     void    _Cdecl textmode( int );
  201.  
  202.     static int _Cdecl isCon( ostream& );
  203.  
  204. private:
  205.  
  206.     static long isCon_;
  207.     conbuf buf;
  208.  
  209. };
  210.  
  211. inline conbuf* _Cdecl constream::rdbuf()
  212. {
  213.     return (conbuf *)ostream::rdbuf();
  214. }
  215.  
  216. inline void _Cdecl constream::clrscr()
  217. {
  218.     rdbuf()->clrscr();
  219. }
  220.  
  221. inline void _Cdecl constream::window( int l, int t, int r, int b )
  222. {
  223.     rdbuf()->window( l, t, r, b );
  224. }
  225.  
  226. inline void _Cdecl constream::textmode( int m )
  227. {
  228.     rdbuf()->textmode( m );
  229. }
  230.  
  231. inline int _Cdecl constream::isCon( ostream& o )
  232. {
  233.     return (o.flags() & isCon_) != 0;
  234. }
  235.  
  236. class omanip_int_int
  237. {
  238.  
  239. public:
  240.     omanip_int_int(ostream& (*_f)(ostream&, int, int ), int _z1, int _z2 ) :
  241.         _fn(_f), _ag1(_z1), _ag2(_z2) { }
  242.     friend ostream& _Cdecl operator<<(ostream& _s, omanip_int_int& _f)
  243.         { return(*_f._fn)(_s, _f._ag1, _f._ag2); }
  244.  
  245. private:
  246.     ostream& _Cdecl (*_fn)(ostream&, int, int);
  247.     int _ag1;
  248.     int _ag2;
  249. };
  250.  
  251. ostream& _Cdecl clreol( ostream& );
  252. ostream& _Cdecl highvideo( ostream& );
  253. ostream& _Cdecl lowvideo( ostream& );
  254. ostream& _Cdecl normvideo( ostream& );
  255. ostream& _Cdecl delline( ostream& );
  256. ostream& _Cdecl insline( ostream& );
  257.  
  258. omanip_int cdecl setcrsrtype( int );
  259. omanip_int cdecl setattr( int );
  260. omanip_int cdecl setbk( int );
  261. omanip_int cdecl setclr( int );
  262. omanip_int_int cdecl setxy( int, int );
  263.  
  264. #endif  // __CONSTREA_H
  265.  
  266.