00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef IOmanip_H
00034 #define IOmanip_H
00035
00036 #include "Istream.H"
00037 #include "Ostream.H"
00038
00039
00040
00041 namespace Foam
00042 {
00043
00044
00045
00046 template<class T> class Smanip;
00047 template<class T> class Imanip;
00048 template<class T> class Omanip;
00049
00050 template<class T>
00051 inline Istream& operator>>(Istream& is, const Smanip<T>& m);
00052
00053 template<class T>
00054 inline Ostream& operator<<(Ostream& os, const Smanip<T>& m);
00055
00056 template<class T>
00057 inline Istream& operator>>(Istream& is, const Imanip<T>& m);
00058
00059 template<class T>
00060 inline Ostream& operator<<(Ostream& os, const Omanip<T>& m);
00061
00062
00063
00064
00065
00066
00067 template<class T>
00068 class Smanip
00069 {
00070 T (IOstream::*_fPtr)(const T);
00071 T _i;
00072
00073 public:
00074
00075 Smanip(T (IOstream::*fPtr)(const T), const T i)
00076 :
00077 _fPtr(fPtr),
00078 _i(i)
00079 {}
00080
00081 friend Istream& operator>> <T>(Istream& is, const Smanip<T>& m);
00082 friend Ostream& operator<< <T>(Ostream& os, const Smanip<T>& m);
00083 };
00084
00085
00086 template<class T>
00087 inline Istream& operator>>(Istream& is, const Smanip<T>& m)
00088 {
00089 (is.*m._fPtr)(m._i);
00090 return is;
00091 }
00092
00093
00094 template<class T>
00095 inline Ostream& operator<<(Ostream& os, const Smanip<T>& m)
00096 {
00097 (os.*m._fPtr)(m._i);
00098 return os;
00099 }
00100
00101
00102
00103
00104
00105
00106 template<class T>
00107 class Imanip
00108 {
00109 T (Istream::*_fPtr)(const T);
00110 T _i;
00111
00112 public:
00113
00114 Imanip(T (Istream::*fPtr)(const T), const T i)
00115 :
00116 _fPtr(fPtr),
00117 _i(i)
00118 {}
00119
00120 friend Istream& operator>> <T>(Istream& is, const Imanip<T>& m);
00121 };
00122
00123
00124 template<class T>
00125 inline Istream& operator>>(Istream& is, const Imanip<T>& m)
00126 {
00127 (is.*m._fPtr)(m._i);
00128 return is;
00129 }
00130
00131
00132
00133
00134
00135
00136 template<class T>
00137 class Omanip
00138 {
00139 T (Ostream::*_fPtr)(const T);
00140 T _i;
00141
00142 public:
00143
00144 Omanip(T (Ostream::*fPtr)(const T), const T i)
00145 :
00146 _fPtr(fPtr),
00147 _i(i)
00148 {}
00149
00150 friend Ostream& operator<< <T>(Ostream& os, const Omanip<T>& m);
00151 };
00152
00153
00154 template<class T>
00155 inline Ostream& operator<<(Ostream& os, const Omanip<T>& m)
00156 {
00157 (os.*m._fPtr)(m._i);
00158 return os;
00159 }
00160
00161
00162
00163
00164 inline Smanip<ios_base::fmtflags> setf
00165 (
00166 const ios_base::fmtflags flags
00167 )
00168 {
00169 return Smanip<ios_base::fmtflags>(&IOstream::setf, flags);
00170 }
00171
00172
00173 inline Omanip<int> setw(const int i)
00174 {
00175 return Omanip<int>(&Ostream::width, i);
00176 }
00177
00178
00179 inline Omanip<int> setprecision(const int i)
00180 {
00181 return Omanip<int>(&Ostream::precision, i);
00182 }
00183
00184
00185
00186
00187 }
00188
00189
00190
00191 #endif
00192
00193