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