- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
class fileOutBuf : public streambuf
{
public:
// ...
typedef char char_type;
typedef int int_type;
typedef int streamsize;
// ...
int printf( const char * fpFormat, ... );
inline int vprintf( const char * fpFormat, va_list fvaList )
{
if ( NULL != dpFileDescriptor )
{
if ( true == sdVerboseFlag && false == dSkipVerboseOutput)
vfprintf( dpVerboseFileDescriptor, fpFormat, fvaList );
return vfprintf( dpFileDescriptor, fpFormat, fvaList );
}
else
{
if ( NULL != dpOutputFuncPtr )
return (*dpOutputFuncPtr)( fpFormat, fvaList );
}
return 0;
}
// ....
virtual int_type overflow( int_type c = EOF );
virtual streamsize xsputn( const char_type *s, streamsize n );
// ....
};
int fileOutBuf::printf( const char * fpFormat, ... )
{
va_list lvaList;
int lRet;
va_start( lvaList, fpFormat );
if ( NULL != dpFileDescriptor )
{
if ( true == sdVerboseFlag && false == dSkipVerboseOutput)
vfprintf( dpVerboseFileDescriptor, fpFormat, lvaList );
lRet = vfprintf( dpFileDescriptor, fpFormat, lvaList );
}
else
{
if ( NULL != dpOutputFuncPtr )
lRet = (*dpOutputFuncPtr)( fpFormat, lvaList );
}
va_end( lvaList );
return lRet;
}
fileOutBuf::int_type fileOutBuf::overflow( int_type c )
{
if ( NULL != dpFileDescriptor )
{
if ( true == sdVerboseFlag && false == dSkipVerboseOutput)
fputc( c, dpVerboseFileDescriptor );
return fputc( c, dpFileDescriptor );
}
else
return fileOutBuf::printf( "%c", c );
}
fileOutBuf::streamsize fileOutBuf::xsputn( const fileOutBuf::char_type *s, fileOutBuf::streamsize n )
{
if ( NULL != dpFileDescriptor )
{
if ( true == sdVerboseFlag && false == dSkipVerboseOutput)
fwrite( s, sizeof( char_type ), n, dpVerboseFileDescriptor );
return fwrite( s, sizeof( char_type ), n, dpFileDescriptor );
}
else
return fileOutBuf::printf( "%*s", n, s );
}
нетривиальная капипаста или делаем из мухи слона.
ЗЫ после удаления всей капипасты, от класа в целом осталось что-то около 50 строк.