home *** CD-ROM | disk | FTP | other *** search
/ ftp.uni-stuttgart.de/pub/systems/acorn/ / Acorn.tar / Acorn / acornet / dev / c / gcc / g++lib.spk / h / iomanip < prev    next >
Text File  |  1993-12-07  |  5KB  |  155 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. #include "iostream.h"
  32.  
  33.  
  34. #ifndef _G_NO_TEMPLATES
  35.  
  36.  
  37. //-----------------------------------------------------------------------------
  38. //      Parametrized Manipulators as specified by ANSI draft
  39. //-----------------------------------------------------------------------------
  40.  
  41. //-----------------------------------------------------------------------------
  42. //      Stream Manipulators
  43. //-----------------------------------------------------------------------------
  44. //
  45. template<class TP> class smanip; // TP = Type Param
  46.  
  47. template<class TP> class sapp {
  48.     ios& (*_f)(ios&, TP);
  49. public: 
  50.     sapp(ios& (*f)(ios&, TP)) : _f(f) {}
  51.     //
  52.     smanip<TP> operator()(TP a) 
  53.       { return smanip<TP>(_f, a); }
  54. };
  55.  
  56.  
  57. template<class TP> class smanip {
  58.     ios& (*_f)(ios&, TP);
  59.     TP _a;
  60. public:
  61.     smanip(ios& (*f)(ios&, TP), TP a) : _f(f), _a(a) {}
  62.     //
  63.     friend 
  64.       istream& operator>>(istream& i, const smanip<TP>& m);
  65.     friend
  66.       ostream& operator<<(ostream& o, const smanip<TP>& m);
  67. };
  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.  
  78. //-----------------------------------------------------------------------------
  79. //      Input-Stream Manipulators
  80. //-----------------------------------------------------------------------------
  81. //
  82. template<class TP> class imanip; 
  83.  
  84. template<class TP> class iapp {
  85.     istream& (*_f)(istream&, TP);
  86. public: 
  87.     iapp(ostream& (*f)(istream&,TP)) : _f(f) {}
  88.     //
  89.     imanip<TP> operator()(TP a)
  90.        { return imanip<TP>(_f, a); }
  91. };
  92.  
  93. template<class TP> class imanip {
  94.     istream& (*_f)(istream&, TP);
  95.     TP _a;
  96. public:
  97.     imanip(istream& (*f)(istream&, TP), TP a) : _f(f), _a(a) {}
  98.     //
  99.     friend 
  100.       istream& operator>>(istream& i, const imanip<TP>& m)
  101.         { return m._f( i, m._a); }
  102. };
  103.  
  104.  
  105. //-----------------------------------------------------------------------------
  106. //      Output-Stream Manipulators
  107. //-----------------------------------------------------------------------------
  108. //
  109. template<class TP> class omanip; 
  110.  
  111. template<class TP> class oapp {
  112.     ostream& (*_f)(ostream&, TP);
  113. public: 
  114.     oapp(ostream& (*f)(ostream&,TP)) : _f(f) {}
  115.     //
  116.     omanip<TP> operator()(TP a)
  117.       { return omanip<TP>(_f, a); }
  118. };
  119.  
  120. template<class TP> class omanip {
  121.     ostream& (*_f)(ostream&, TP);
  122.     TP _a;
  123. public:
  124.     omanip(ostream& (*f)(ostream&, TP), TP a) : _f(f), _a(a) {}
  125.     //
  126.     friend
  127.       ostream& operator<<(ostream& i, omanip<TP>& m)
  128.         { return m._f( i, m._a); }
  129. };
  130.  
  131.  
  132. //-----------------------------------------------------------------------------
  133. //      Available Manipulators
  134. //-----------------------------------------------------------------------------
  135.  
  136. //
  137. // Macro to define an iomanip function, with one argument
  138. // The underlying function is `__iomanip_<name>' 
  139. //
  140. #define __DEFINE_IOMANIP_FN1(type,param,function)         \
  141.         extern ios& __iomanip_##function (ios&, param); \
  142.         inline type<param> function (param n)           \
  143.                         { return type<param> (__iomanip_##function, n); }
  144.  
  145. __DEFINE_IOMANIP_FN1( smanip, int, setbase)
  146. __DEFINE_IOMANIP_FN1( smanip, int, setfill)
  147. __DEFINE_IOMANIP_FN1( smanip, int, setprecision)
  148. __DEFINE_IOMANIP_FN1( smanip, int, setw)
  149.  
  150. __DEFINE_IOMANIP_FN1( smanip, ios::fmtflags, resetiosflags)
  151. __DEFINE_IOMANIP_FN1( smanip, ios::fmtflags, setiosflags)
  152.  
  153. #endif /*!_G_NO_TEMPLATES*/
  154. #endif /*!_IOMANIP_H*/
  155.