Annotation of GNUtools/libg++/libio/iomanip.h, revision 1.1.1.1

1.1       root        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: //
                     27: // Not specifying `pragma interface' causes the compiler to emit the 
                     28: // template definitions in the files, where they are used.
                     29: //
                     30: //#ifdef __GNUG__
                     31: //#pragma interface
                     32: //#endif
                     33: #pragma cplusplus
                     34: 
                     35: #define _IOMANIP_H
                     36: 
                     37: #include <iostream.h>
                     38: 
                     39: //-----------------------------------------------------------------------------
                     40: //     Parametrized Manipulators as specified by ANSI draft
                     41: //-----------------------------------------------------------------------------
                     42: 
                     43: //-----------------------------------------------------------------------------
                     44: //     Stream Manipulators
                     45: //-----------------------------------------------------------------------------
                     46: //
                     47: template<class TP> class smanip; // TP = Type Param
                     48: 
                     49: template<class TP> class sapp {
                     50:     ios& (*_f)(ios&, TP);
                     51: public: 
                     52:     sapp(ios& (*f)(ios&, TP)) : _f(f) {}
                     53:     //
                     54:     smanip<TP> operator()(TP a) 
                     55:       { return smanip<TP>(_f, a); }
                     56: };
                     57: 
                     58: template <class TP> class smanip {
                     59:     ios& (*_f)(ios&, TP);
                     60:     TP _a;
                     61: public:
                     62:     smanip(ios& (*f)(ios&, TP), TP a) : _f(f), _a(a) {}
                     63:     //
                     64:     friend 
                     65:       istream& operator>>(istream& i, const smanip<TP>& m);
                     66:     friend
                     67:       ostream& operator<<(ostream& o, const smanip<TP>& m);
                     68: };
                     69: 
                     70: template<class TP>
                     71: inline istream& operator>>(istream& i, const smanip<TP>& m)
                     72:        { (*m._f)(i, m._a); return i; }
                     73: 
                     74: template<class TP>
                     75: inline ostream& operator<<(ostream& o, const smanip<TP>& m)
                     76:        { (*m._f)(o, m._a); return o;}
                     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& o, omanip<TP>& m)
                    128:        { return (*m._f)(o, 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 /*!_IOMANIP_H*/

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.