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 #include <StandardStream.h>
00026 #include <Vector.h>
00027 #include <iostream>
00028 #include <iomanip>
00029 using std::cerr;
00030 using std::ios;
00031 using std::setiosflags;
00032
00033 StandardStream::StandardStream(int indent)
00034 :OPS_Stream(OPS_STREAM_TAGS_FileStream),
00035 fileOpen(0), indentSize(indent)
00036 {
00037 if (indentSize < 1) indentSize = 1;
00038 indentString = new char[indentSize+1];
00039 for (int i=0; i<indentSize; i++)
00040 strcpy(indentString, " ");
00041 }
00042 StandardStream::~StandardStream()
00043 {
00044 if (fileOpen == 1)
00045 theFile.close();
00046
00047
00048 }
00049
00050 int
00051 StandardStream::setFile(const char *fileName, openMode mode)
00052 {
00053 if (fileOpen == 1) {
00054 theFile.close();
00055 fileOpen = 0;
00056 }
00057
00058 if (mode == OVERWRITE)
00059 theFile.open(fileName, ios::out);
00060 else
00061 theFile.open(fileName, ios::out| ios::app);
00062
00063 if (theFile.bad()) {
00064 std::cerr << "WARNING - StandardStream::setFile()";
00065 std::cerr << " - could not open file " << fileName << std::endl;
00066
00067 return -1;
00068 } else
00069 fileOpen = 1;
00070
00071 return 0;
00072 }
00073
00074
00075 int
00076 StandardStream::setPrecision(int prec)
00077 {
00078 cerr << std::setprecision(prec);
00079
00080 if (fileOpen != 0)
00081 theFile << std::setprecision(prec);
00082
00083 return 0;
00084 }
00085
00086 int
00087 StandardStream::setFloatField(floatField field)
00088 {
00089 if (field == FIXEDD) {
00090 cerr << setiosflags(ios::fixed);
00091 if (fileOpen != 0)
00092 theFile << setiosflags(ios::fixed);
00093 }
00094 else if (field == SCIENTIFIC) {
00095 cerr << setiosflags(ios::scientific);
00096 if (fileOpen != 0)
00097 theFile << setiosflags(ios::scientific);
00098 }
00099
00100 return 0;
00101 }
00102
00103
00104 int
00105 StandardStream::tag(const char *tagName)
00106 {
00107
00108 this->indent();
00109 (*this) << tagName << "\n";
00110
00111 numIndent++;
00112
00113 return 0;
00114 }
00115
00116 int
00117 StandardStream::tag(const char *tagName, const char *value)
00118 {
00119
00120 this->indent();
00121 (*this) << tagName << " " << value << "\n";
00122
00123
00124 numIndent++;
00125
00126 return 0;
00127 }
00128
00129 int
00130 StandardStream::endTag()
00131 {
00132 numIndent--;
00133
00134 return 0;
00135 }
00136
00137 int
00138 StandardStream::attr(const char *name, int value)
00139 {
00140 this->indent();
00141 (*this) << name << " = " << value << "\n";
00142
00143 return 0;
00144 }
00145
00146 int
00147 StandardStream::attr(const char *name, double value)
00148 {
00149 this->indent();
00150 (*this) << name << " = " << value << "\n";
00151
00152 return 0;
00153 }
00154
00155 int
00156 StandardStream::attr(const char *name, const char *value)
00157 {
00158 this->indent();
00159 (*this) << name << " = " << value << "\n";
00160
00161 return 0;
00162 }
00163
00164 int
00165 StandardStream::write(Vector &data)
00166 {
00167 this->indent();
00168 (*this) << data;
00169
00170 return 0;
00171 }
00172
00173
00174 OPS_Stream&
00175 StandardStream::write(const char *s,int n)
00176 {
00177 cerr.write(s, n);
00178
00179 if (fileOpen != 0)
00180 theFile.write(s, n);
00181
00182 return *this;
00183 }
00184
00185 OPS_Stream&
00186 StandardStream::write(const unsigned char*s, int n)
00187 {
00188 cerr.write((const char *) s, n);
00189
00190 if (fileOpen != 0)
00191 theFile.write((const char *) s, n);
00192
00193 return *this;
00194 }
00195 OPS_Stream&
00196 StandardStream::write(const signed char*s, int n)
00197 {
00198 cerr.write((const char *)s, n);
00199
00200 if (fileOpen != 0)
00201 theFile.write((const char *) s, n);
00202
00203 return *this;
00204 }
00205 OPS_Stream&
00206 StandardStream::write(const void *s, int n)
00207 {
00208 cerr.write((const char *)s, n);
00209
00210 if (fileOpen != 0)
00211 theFile.write((const char *) s, n);
00212
00213 return *this;
00214 }
00215 OPS_Stream&
00216 StandardStream::operator<<(char c)
00217 {
00218 cerr << c;
00219
00220 if (fileOpen != 0)
00221 theFile << c;
00222
00223 return *this;
00224 }
00225 OPS_Stream&
00226 StandardStream::operator<<(unsigned char c)
00227 {
00228 cerr << c;
00229
00230 if (fileOpen != 0)
00231 theFile << c;
00232
00233 return *this;
00234 }
00235 OPS_Stream&
00236 StandardStream::operator<<(signed char c)
00237 {
00238
00239 cerr << c;
00240
00241 if (fileOpen != 0)
00242 theFile << c;
00243
00244 return *this;
00245 }
00246 OPS_Stream&
00247 StandardStream::operator<<(const char *s)
00248 {
00249
00250
00251 cerr << s;
00252 cerr.flush();
00253
00254 if (fileOpen != 0) {
00255 theFile << s;
00256 theFile.flush();
00257 }
00258
00259 return *this;
00260 }
00261
00262 OPS_Stream&
00263 StandardStream::operator<<(const unsigned char *s)
00264 {
00265 cerr << s;
00266
00267 if (fileOpen != 0)
00268 theFile << s;
00269
00270 return *this;
00271 }
00272 OPS_Stream&
00273 StandardStream::operator<<(const signed char *s)
00274 {
00275 cerr << s;
00276
00277 if (fileOpen != 0)
00278 theFile << s;
00279
00280 return *this;
00281 }
00282 OPS_Stream&
00283 StandardStream::operator<<(const void *p)
00284 {
00285
00286
00287
00288
00289
00290
00291 return *this;
00292 }
00293 OPS_Stream&
00294 StandardStream::operator<<(int n)
00295 {
00296 cerr << 1.0*n;
00297
00298 if (fileOpen != 0)
00299 theFile << 1.0*n;
00300
00301 return *this;
00302 }
00303
00304 OPS_Stream&
00305 StandardStream::operator<<(unsigned int n)
00306 {
00307 cerr << 1.0*n;
00308
00309 if (fileOpen != 0)
00310 theFile << 1.0*n;
00311
00312 return *this;
00313 }
00314 OPS_Stream&
00315 StandardStream::operator<<(long n)
00316 {
00317
00318
00319
00320
00321
00322
00323 return *this;
00324 }
00325 OPS_Stream&
00326 StandardStream::operator<<(unsigned long n)
00327 {
00328
00329
00330
00331
00332
00333
00334 return *this;
00335 }
00336 OPS_Stream&
00337 StandardStream::operator<<(short n)
00338 {
00339
00340
00341
00342
00343
00344
00345 return *this;
00346 }
00347 OPS_Stream&
00348 StandardStream::operator<<(unsigned short n)
00349 {
00350
00351
00352
00353
00354
00355
00356 return *this;
00357 }
00358
00359 OPS_Stream&
00360 StandardStream::operator<<(bool b)
00361 {
00362
00363
00364
00365
00366
00367
00368 return *this;
00369 }
00370 OPS_Stream&
00371 StandardStream::operator<<(double n)
00372 {
00373 cerr << n;
00374
00375 if (fileOpen != 0)
00376 theFile << n;
00377
00378 return *this;
00379 }
00380 OPS_Stream&
00381 StandardStream::operator<<(float n)
00382 {
00383 cerr << n;
00384
00385 if (fileOpen != 0)
00386 theFile << n;
00387
00388 return *this;
00389 }
00390
00391
00392 void
00393 StandardStream::indent(void)
00394 {
00395 for (int i=0; i<numIndent; i++) {
00396 cerr << indentString;
00397 if (fileOpen != 0)
00398 theFile << indentString;
00399 }
00400 }
00401
00402 int
00403 StandardStream::sendSelf(int commitTag, Channel &theChannel)
00404 {
00405 return 0;
00406 }
00407
00408 int
00409 StandardStream::recvSelf(int commitTag, Channel &theChannel,
00410 FEM_ObjectBroker &theBroker)
00411 {
00412
00413 return 0;
00414 }