home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / borhead.zip / CONSTREA.H < prev    next >
C/C++ Source or Header  |  1994-11-09  |  6KB  |  314 lines

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