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