00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef INFORM_H
00012 #define INFORM_H
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifdef IPPL_USE_STANDARD_HEADERS
00036 #include <iostream>
00037 #include <iomanip>
00038 using namespace std;
00039 #else
00040 #include <iostream.h>
00041 #include <iomanip.h>
00042 #endif
00043
00044 #ifdef IPPL_NO_STRINGSTREAM
00045 #include <sstream>
00046
00047 using namespace std;
00048 #else
00049 #include <strstream.h>
00050 #endif
00051
00052 #include "Utility/Pstring.h"
00053
00054
00055
00056 #define MIN_INFORM_LEVEL 1
00057 #define MAX_INFORM_LEVEL 5
00058
00059
00060 #define MAX_INFORM_MSG_SIZE 32000
00061 #define INFORM_ALL_NODES (-1)
00062
00063
00064 class Inform {
00065
00066 public:
00067
00068 enum WriteMode { OVERWRITE, APPEND };
00069
00070 public:
00071
00072 Inform(const char * = 0, int = 0);
00073
00074
00075
00076
00077 Inform(const char *prefix, const char *fname, const WriteMode, int = 0);
00078
00079
00080
00081 Inform(const char *, ostream&, int = 0);
00082
00083
00084 ~Inform();
00085
00086
00087 void on(const bool o) { On = o; }
00088 bool isOn() const { return On; }
00089
00090
00091 Inform& setOutputLevel(const int);
00092 int getOutputLevel(void) const { return OutputLevel; }
00093
00094
00095 Inform& setMessageLevel(const int);
00096 int getMessageLevel(void) const { return MsgLevel; }
00097
00098
00099 int getPrintNode() const { return PrintNode; }
00100 void setPrintNode(int n = (-1)) { PrintNode = n; }
00101
00102
00103 ostream& getStream() { return FormatBuf; }
00104
00105
00106 bool openedSuccessfully() { return OpenedSuccessfully; }
00107
00108
00109 Inform& outputMessage(void);
00110
00111
00112
00113 #if (IPPL_IOFLAG_BUG)
00114 typedef long FmtFlags_t;
00115 #else
00116 typedef std::ios_base::fmtflags FmtFlags_t;
00117 #endif
00118
00119 FmtFlags_t setf(FmtFlags_t setbits, FmtFlags_t field)
00120 { return FormatBuf.setf(setbits,field); }
00121
00122 FmtFlags_t setf(FmtFlags_t f) { return FormatBuf.setf(f); }
00123 void unsetf(FmtFlags_t f) { FormatBuf.unsetf(f); }
00124 long flags() const { return FormatBuf.flags(); }
00125 long flags(FmtFlags_t f) { return FormatBuf.flags(f); }
00126 int width() const { return FormatBuf.width(); }
00127 int width(int w) { return FormatBuf.width(w); }
00128 char fill() const { return FormatBuf.fill(); }
00129 char fill(char c) { return FormatBuf.fill(c); }
00130 int precision() const { return FormatBuf.precision(); }
00131 int precision(int p) { return FormatBuf.precision(p); }
00132
00133 private:
00134
00135 char *Name;
00136
00137 #ifdef IPPL_NO_STRINGSTREAM
00138
00139 string MsgBuf;
00140
00141 ostringstream FormatBuf;
00142 #else
00143
00144 char MsgBuf[MAX_INFORM_MSG_SIZE];
00145
00146 ostrstream FormatBuf;
00147 #endif
00148
00149
00150 ostream *MsgDest;
00151
00152
00153 bool NeedClose;
00154
00155
00156 bool OpenedSuccessfully;
00157
00158
00159 bool On;
00160
00161
00162 int PrintNode;
00163
00164
00165
00166 int OutputLevel;
00167
00168
00169
00170
00171 int MsgLevel;
00172
00173
00174
00175 void display_message(char *);
00176
00177
00178 void display_single_line(char *);
00179
00180
00181
00182 void setup(const char *, int);
00183 };
00184
00185
00186
00187 extern Inform& endl(Inform&);
00188
00189
00190 extern Inform& level1(Inform&);
00191 extern Inform& level2(Inform&);
00192 extern Inform& level3(Inform&);
00193 extern Inform& level4(Inform&);
00194 extern Inform& level5(Inform&);
00195
00196
00197
00198 template<class T>
00199 inline
00200 Inform& operator<<(Inform& o, const T& val) {
00201 o.getStream() << val;
00202 return o;
00203 }
00204
00205
00206
00207 inline
00208 Inform& operator<<(Inform& o, Inform& (*d)(Inform&)) {
00209 return d(o);
00210 }
00211
00212
00213
00214 inline
00215 Inform& operator<<(Inform& o, const void *val) {
00216 Inform::FmtFlags_t oldformat = o.setf(ios::hex, ios::basefield);
00217 o.getStream() << "0x" << (long)val;
00218 o.setf(oldformat, ios::basefield);
00219 return o;
00220 }
00221
00222 #if defined(IPPL_LONGLONG)
00223
00224 inline
00225 Inform& operator<<(Inform& o, const long long& val) {
00226 #if ( defined(IPPL_KAI) || defined(IPPL_PGI) )
00227
00228 o.getStream() << static_cast<long double>(val);
00229 #else
00230 o.getStream() << val;
00231 #endif
00232 return o;
00233 }
00234 #endif // IPPL_LONGLONG
00235
00236
00237 inline Inform& operator<<(Inform& out, const string& s) {
00238 out << s.c_str();
00239 return out;
00240 }
00241
00242
00243 #endif // INFORM_H
00244
00245
00246
00247
00248
00249