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