00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "TestStream.h"
00020
00021
00022
00023 namespace TestToolBox
00024 {
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #define TESTSTREAM_OUTPUT_OPERATOR(TYP) \
00043 TTB_INLINE TestStream& TestStream::operator << (TYP in_item) \
00044 { \
00045 if (Selected (M_STDOUT)) \
00046 std::cout << in_item; \
00047 if (Selected (M_OUTFILE)) \
00048 *m_pOutFile << in_item; \
00049 if (Selected (M_RPTFILE)) \
00050 *m_pRptFile << in_item; \
00051 return *this; \
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 #define TESTSTREAM_WRITE( CHAR_POINTER_TYPE ) \
00067 TTB_INLINE TestStream& TestStream::write \
00068 (CHAR_POINTER_TYPE in_pCh, int in_count) \
00069 { \
00070 if (Selected (M_STDOUT)) \
00071 std::cout.write ((char*)in_pCh, in_count); \
00072 if (Selected (M_OUTFILE)) \
00073 m_pOutFile->write((char*)in_pCh, in_count); \
00074 if (Selected (M_RPTFILE)) \
00075 m_pRptFile->write((char*)in_pCh, in_count); \
00076 return *this; \
00077 }
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 #ifdef _WINDLL
00096
00097
00098 NullStream cin;
00099 NullStream cout;
00100 NullStream cerr;
00101
00102 #endif // ifdef _WINDLL
00103
00104
00105
00106
00107
00108
00109
00110 TTB_INLINE TestStream::TestStream(
00111 std::fstream* in_pOutFile,
00112 std::fstream* in_pRptFile):
00113 m_pOutFile (in_pOutFile),
00114 m_pRptFile (in_pRptFile),
00115 m_mode (0),
00116 m_baseMode (M_STDOUT),
00117 m_allowedStreams (M_STDOUT | M_OUTFILE | M_RPTFILE)
00118 {
00119 if (m_pOutFile)
00120 {
00121 m_baseMode |= M_OUTFILE;
00122 }
00123
00124 if (m_pRptFile)
00125 {
00126 m_baseMode |= M_RPTFILE;
00127 }
00128
00129
00130 ResetMode();
00131
00132 }
00133
00134
00135
00136
00137
00138
00139 TTB_INLINE int TestStream::width(int in_newWidth)
00140 {
00141 int retVal = 0;
00142
00143 if (Selected (M_STDOUT))
00144 retVal = std::cout.width(in_newWidth);
00145
00146 if (Selected (M_OUTFILE))
00147 retVal = m_pOutFile->width(in_newWidth);
00148
00149 if (Selected (M_RPTFILE))
00150 retVal = m_pRptFile->width(in_newWidth);
00151
00152 return retVal;
00153
00154 }
00155
00156
00157
00158
00159
00160
00161 TTB_INLINE int TestStream::width(void) const
00162 {
00163 int retVal = 0;
00164
00165 if (Selected (M_STDOUT))
00166 retVal = std::cout.width();
00167
00168 if (Selected (M_OUTFILE))
00169 retVal = m_pOutFile->width();
00170
00171 if (Selected (M_RPTFILE))
00172 retVal = m_pRptFile->width();
00173
00174 return retVal;
00175
00176 }
00177
00178
00179
00180
00181
00182
00183 TTB_INLINE long TestStream::setf (long in_flags)
00184 {
00185 long retVal = 0;
00186
00187 if (Selected (M_STDOUT))
00188 retVal = std::cout.setf(in_flags);
00189
00190 if (Selected (M_OUTFILE))
00191 retVal = m_pOutFile->setf(in_flags);
00192
00193 if (Selected (M_RPTFILE))
00194 retVal = m_pRptFile->setf(in_flags);
00195
00196 return retVal;
00197
00198 }
00199
00200
00201
00202
00203
00204
00205 TTB_INLINE long TestStream::setf (long in_flags, long in_mask)
00206 {
00207 long retVal = 0;
00208
00209 if (Selected (M_STDOUT))
00210 retVal = std::cout.setf(in_flags, in_mask);
00211
00212 if (Selected (M_OUTFILE))
00213 retVal = m_pOutFile->setf(in_flags, in_mask);
00214
00215 if (Selected (M_RPTFILE))
00216 retVal = m_pRptFile->setf(in_flags, in_mask);
00217
00218 return retVal;
00219
00220 }
00221
00222
00223
00224
00225
00226
00227 TTB_INLINE long TestStream::unsetf (long in_flags)
00228 {
00229 long retVal = 0;
00230
00231 if (Selected (M_STDOUT))
00232 std::cout.unsetf(in_flags);
00233
00234 if (Selected (M_OUTFILE))
00235 m_pOutFile->unsetf(in_flags);
00236
00237 if (Selected (M_RPTFILE))
00238 m_pRptFile->unsetf(in_flags);
00239
00240 return retVal;
00241
00242 }
00243
00244
00245
00246
00247
00248
00249
00250 TTB_INLINE TestStream& TestStream::operator << (std::string in_str)
00251 {
00252 if (Selected (M_STDOUT))
00253 std::cout << in_str.c_str();
00254 if (Selected (M_OUTFILE))
00255 *m_pOutFile << in_str.c_str();
00256 if (Selected (M_RPTFILE))
00257 *m_pRptFile << in_str.c_str();
00258 return *this;
00259 }
00260
00261
00262 TESTSTREAM_OUTPUT_OPERATOR( unsigned char* )
00263 TESTSTREAM_OUTPUT_OPERATOR( const char* )
00264 TESTSTREAM_OUTPUT_OPERATOR( char )
00265 TESTSTREAM_OUTPUT_OPERATOR( unsigned char )
00266 TESTSTREAM_OUTPUT_OPERATOR( short )
00267 TESTSTREAM_OUTPUT_OPERATOR( unsigned short )
00268 TESTSTREAM_OUTPUT_OPERATOR( int )
00269 TESTSTREAM_OUTPUT_OPERATOR( unsigned int )
00270 TESTSTREAM_OUTPUT_OPERATOR( long )
00271 TESTSTREAM_OUTPUT_OPERATOR( unsigned long )
00272 TESTSTREAM_OUTPUT_OPERATOR( float )
00273 TESTSTREAM_OUTPUT_OPERATOR( double )
00274 TESTSTREAM_OUTPUT_OPERATOR( long double )
00275
00276
00277
00278
00279
00280
00281 TTB_INLINE TestStream& TestStream::operator << ( std::ostream& (*f)(std::ostream&) )
00282 {
00283
00284 #ifndef _WINDLL
00285 if (Selected (M_STDOUT))
00286 f(std::cout);
00287 #endif
00288
00289 if (Selected (M_OUTFILE))
00290 f(*m_pOutFile);
00291
00292 if (Selected (M_RPTFILE))
00293 f(*m_pRptFile);
00294
00295 return *this;
00296 }
00297
00298
00299
00300
00301
00302
00303 TTB_INLINE TestStream& TestStream::operator << ( std::ios& (*f)(std::ios&) )
00304 {
00305
00306 #ifndef _WINDLL
00307 if (Selected (M_STDOUT))
00308 f(std::cout);
00309 #endif
00310
00311 if (Selected (M_OUTFILE))
00312 f(*m_pOutFile);
00313
00314 if (Selected (M_RPTFILE))
00315 f(*m_pRptFile);
00316
00317 return *this;
00318 }
00319
00320
00321
00322
00323
00324
00325
00326 TESTSTREAM_WRITE( const unsigned char* )
00327 TESTSTREAM_WRITE( const signed char* )
00328
00329
00330
00331
00332
00333
00334 };
00335
00336
00337
00338