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