home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / lib / g++-include / iomanip.h < prev    next >
C/C++ Source or Header  |  1994-12-22  |  5KB  |  160 lines

  1. /* This is part of libio/iostream, providing -*- C++ -*- input/output.
  2. Copyright (C) 1993 Free Software Foundation
  3.  
  4. This file is part of the GNU IO Library.  This library is free
  5. software; you can redistribute it and/or modify it under the
  6. terms of the GNU General Public License as published by the
  7. Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with GNU CC; see the file COPYING.  If not, write to
  17. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. As a special exception, if you link this library with files
  20. compiled with a GNU compiler to produce an executable, this does not cause
  21. the resulting executable to be covered by the GNU General Public License.
  22. This exception does not however invalidate any other reasons why
  23. the executable file might be covered by the GNU General Public License. */
  24.  
  25. #ifndef _IOMANIP_H
  26. #ifdef __GNUG__
  27. #pragma interface
  28. #endif
  29. #define _IOMANIP_H
  30.  
  31. #include <iostream.h>
  32.  
  33. //-----------------------------------------------------------------------------
  34. //    Parametrized Manipulators as specified by ANSI draft
  35. //-----------------------------------------------------------------------------
  36.  
  37. //-----------------------------------------------------------------------------
  38. //    Stream Manipulators
  39. //-----------------------------------------------------------------------------
  40. //
  41. template<class TP> class smanip; // TP = Type Param
  42.  
  43. template<class TP> class sapp {
  44.     ios& (*_f)(ios&, TP);
  45. public: 
  46.     sapp(ios& (*f)(ios&, TP)) : _f(f) {}
  47.     //
  48.     smanip<TP> operator()(TP a) 
  49.       { return smanip<TP>(_f, a); }
  50. };
  51.  
  52. template <class TP> class smanip {
  53.     ios& (*_f)(ios&, TP);
  54.     TP _a;
  55. public:
  56.     smanip(ios& (*f)(ios&, TP), TP a) : _f(f), _a(a) {}
  57.     //
  58.     friend 
  59.       istream& operator>>(istream& i, const smanip<TP>& m);
  60.     friend
  61.       ostream& operator<<(ostream& o, const smanip<TP>& m);
  62. };
  63.  
  64. #ifdef __GNUG__
  65. extern template class smanip<int>;
  66. extern template class smanip<ios::fmtflags>;
  67. #endif
  68.  
  69. template<class TP>
  70. inline istream& operator>>(istream& i, const smanip<TP>& m)
  71.     { (*m._f)(i, m._a); return i; }
  72.  
  73. template<class TP>
  74. inline ostream& operator<<(ostream& o, const smanip<TP>& m)
  75.     { (*m._f)(o, m._a); return o;}
  76.  
  77. #ifdef __GNUG__
  78. extern template istream& operator>>(istream&, const smanip<int>&);
  79. extern template istream& operator>>(istream&, const smanip<ios::fmtflags>&);
  80. extern template ostream& operator<<(ostream&, const smanip<int>&);
  81. extern template ostream& operator<<(ostream&, const smanip<ios::fmtflags>&);
  82. #endif
  83.  
  84. //-----------------------------------------------------------------------------
  85. //    Input-Stream Manipulators
  86. //-----------------------------------------------------------------------------
  87. //
  88. template<class TP> class imanip; 
  89.  
  90. template<class TP> class iapp {
  91.     istream& (*_f)(istream&, TP);
  92. public: 
  93.     iapp(istream& (*f)(istream&,TP)) : _f(f) {}
  94.     //
  95.     imanip<TP> operator()(TP a)
  96.        { return imanip<TP>(_f, a); }
  97. };
  98.  
  99. template <class TP> class imanip {
  100.     istream& (*_f)(istream&, TP);
  101.     TP _a;
  102. public:
  103.     imanip(istream& (*f)(istream&, TP), TP a) : _f(f), _a(a) {}
  104.     //
  105.     friend 
  106.       istream& operator>>(istream& i, const imanip<TP>& m)
  107.     { return (*m._f)( i, m._a); }
  108. };
  109.  
  110.  
  111. //-----------------------------------------------------------------------------
  112. //    Output-Stream Manipulators
  113. //-----------------------------------------------------------------------------
  114. //
  115. template<class TP> class omanip; 
  116.  
  117. template<class TP> class oapp {
  118.     ostream& (*_f)(ostream&, TP);
  119. public: 
  120.     oapp(ostream& (*f)(ostream&,TP)) : _f(f) {}
  121.     //
  122.     omanip<TP> operator()(TP a)
  123.       { return omanip<TP>(_f, a); }
  124. };
  125.  
  126. template <class TP> class omanip {
  127.     ostream& (*_f)(ostream&, TP);
  128.     TP _a;
  129. public:
  130.     omanip(ostream& (*f)(ostream&, TP), TP a) : _f(f), _a(a) {}
  131.     //
  132.     friend
  133.       ostream& operator<<(ostream& o, const omanip<TP>& m)
  134.     { return (*m._f)(o, m._a); }
  135. };
  136.  
  137.  
  138. //-----------------------------------------------------------------------------
  139. //    Available Manipulators
  140. //-----------------------------------------------------------------------------
  141.  
  142. //
  143. // Macro to define an iomanip function, with one argument
  144. // The underlying function is `__iomanip_<name>' 
  145. //
  146. #define __DEFINE_IOMANIP_FN1(type,param,function)         \
  147.     extern ios& __iomanip_##function (ios&, param); \
  148.     inline type<param> function (param n)           \
  149.                 { return type<param> (__iomanip_##function, n); }
  150.  
  151. __DEFINE_IOMANIP_FN1( smanip, int, setbase)
  152. __DEFINE_IOMANIP_FN1( smanip, int, setfill)
  153. __DEFINE_IOMANIP_FN1( smanip, int, setprecision)
  154. __DEFINE_IOMANIP_FN1( smanip, int, setw)
  155.  
  156. __DEFINE_IOMANIP_FN1( smanip, ios::fmtflags, resetiosflags)
  157. __DEFINE_IOMANIP_FN1( smanip, ios::fmtflags, setiosflags)
  158.  
  159. #endif /*!_IOMANIP_H*/
  160.