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