home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Headers / g++ / iomanip.h < prev    next >
C/C++ Source or Header  |  1993-06-29  |  5KB  |  151 lines

  1. //    -*- C++ -*-
  2. //    This is part of the iostream library, providing parametrized manipulators
  3. //    Written by Heinz G. Seidl, Copyright (C) 1992 Cygnus Support
  4. //
  5. //    This library is free software; you can redistribute it and/or
  6. //    modify it under the terms of the GNU Library General Public
  7. //    License as published by the Free Software Foundation; either
  8. //    version 2 of the License, or (at your option) 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 GNU
  13. //    Library General Public License for more details.
  14. //
  15. //    You should have received a copy of the GNU Library General Public
  16. //    License along with this library; if not, write to the Free
  17. //    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #ifndef _IOMANIP_H
  20. //
  21. // Not specifying `pragma interface' causes the compiler to emit the 
  22. // template definitions in the files, where they are used.
  23. //
  24. //#ifdef __GNUG__
  25. //#pragma interface
  26. //#endif
  27. #define _IOMANIP_H
  28.  
  29. #include <_G_config.h>
  30.  
  31. #ifndef _G_NO_TEMPLATES
  32.  
  33. #include <iostream.h>
  34.  
  35. //-----------------------------------------------------------------------------
  36. //    Parametrized Manipulators as specified by ANSI draft
  37. //-----------------------------------------------------------------------------
  38.  
  39. //-----------------------------------------------------------------------------
  40. //    Stream Manipulators
  41. //-----------------------------------------------------------------------------
  42. //
  43. template<class TP> class smanip; // TP = Type Param
  44.  
  45. template<class TP> class sapp {
  46.     ios& (*_f)(ios&, TP);
  47. public: 
  48.     sapp(ios& (*f)(ios&, TP)) : _f(f) {}
  49.     //
  50.     smanip<TP> operator()(TP a) 
  51.       { return smanip<TP>(_f, a); }
  52. };
  53.  
  54. template <class TP> class smanip {
  55.     ios& (*_f)(ios&, TP);
  56.     TP _a;
  57. public:
  58.     smanip(ios& (*f)(ios&, TP), TP a) : _f(f), _a(a) {}
  59.     //
  60.     friend 
  61.       istream& operator>>(istream& i, const smanip<TP>& m);
  62.     friend
  63.       ostream& operator<<(ostream& o, const smanip<TP>& m);
  64. };
  65.  
  66. template<class TP>
  67. inline istream& operator>>(istream& i, const smanip<TP>& m)
  68.     { m._f(i, m._a); return i; }
  69.  
  70. template<class TP>
  71. inline ostream& operator<<(ostream& o, const smanip<TP>& m)
  72.     { m._f(o, m._a); return o;}
  73.  
  74. //-----------------------------------------------------------------------------
  75. //    Input-Stream Manipulators
  76. //-----------------------------------------------------------------------------
  77. //
  78. template<class TP> class imanip; 
  79.  
  80. template<class TP> class iapp {
  81.     istream& (*_f)(istream&, TP);
  82. public: 
  83.     iapp(ostream& (*f)(istream&,TP)) : _f(f) {}
  84.     //
  85.     imanip<TP> operator()(TP a)
  86.        { return imanip<TP>(_f, a); }
  87. };
  88.  
  89. template <class TP> class imanip {
  90.     istream& (*_f)(istream&, TP);
  91.     TP _a;
  92. public:
  93.     imanip(istream& (*f)(istream&, TP), TP a) : _f(f), _a(a) {}
  94.     //
  95.     friend 
  96.       istream& operator>>(istream& i, const imanip<TP>& m)
  97.     { return m._f( i, m._a); }
  98. };
  99.  
  100.  
  101. //-----------------------------------------------------------------------------
  102. //    Output-Stream Manipulators
  103. //-----------------------------------------------------------------------------
  104. //
  105. template<class TP> class omanip; 
  106.  
  107. template<class TP> class oapp {
  108.     ostream& (*_f)(ostream&, TP);
  109. public: 
  110.     oapp(ostream& (*f)(ostream&,TP)) : _f(f) {}
  111.     //
  112.     omanip<TP> operator()(TP a)
  113.       { return omanip<TP>(_f, a); }
  114. };
  115.  
  116. template <class TP> class omanip {
  117.     ostream& (*_f)(ostream&, TP);
  118.     TP _a;
  119. public:
  120.     omanip(ostream& (*f)(ostream&, TP), TP a) : _f(f), _a(a) {}
  121.     //
  122.     friend
  123.       ostream& operator>>(ostream& i, imanip<TP>& m)
  124.     { return (ostream&) m._f( i, m._a); }
  125. };
  126.  
  127.  
  128. //-----------------------------------------------------------------------------
  129. //    Available Manipulators
  130. //-----------------------------------------------------------------------------
  131.  
  132. //
  133. // Macro to define an iomanip function, with one argument
  134. // The underlying function is `__iomanip_<name>' 
  135. //
  136. #define __DEFINE_IOMANIP_FN1(type,param,function)         \
  137.     extern ios& __iomanip_##function (ios&, param); \
  138.     inline type<param> function (param n)           \
  139.                 { return type<param> (__iomanip_##function, n); }
  140.  
  141. __DEFINE_IOMANIP_FN1( smanip, int, setbase)
  142. __DEFINE_IOMANIP_FN1( smanip, int, setfill)
  143. __DEFINE_IOMANIP_FN1( smanip, int, setprecision)
  144. __DEFINE_IOMANIP_FN1( smanip, int, setw)
  145.  
  146. __DEFINE_IOMANIP_FN1( smanip, ios::fmtflags, resetiosflags)
  147. __DEFINE_IOMANIP_FN1( smanip, ios::fmtflags, setiosflags)
  148.  
  149. #endif /*!_G_NO_TEMPLATES*/
  150. #endif /*!_IOMANIP_H*/
  151.