michael@0: // Common/StdOutStream.cpp michael@0: michael@0: #include "StdAfx.h" michael@0: michael@0: #include michael@0: michael@0: #include "StdOutStream.h" michael@0: #include "Common/IntToString.h" michael@0: #include "Common/StringConvert.h" michael@0: michael@0: static const char kNewLineChar = '\n'; michael@0: michael@0: static const char *kFileOpenMode = "wt"; michael@0: michael@0: CStdOutStream g_StdOut(stdout); michael@0: CStdOutStream g_StdErr(stderr); michael@0: michael@0: bool CStdOutStream::Open(const char *fileName) michael@0: { michael@0: Close(); michael@0: _stream = fopen(fileName, kFileOpenMode); michael@0: _streamIsOpen = (_stream != 0); michael@0: return _streamIsOpen; michael@0: } michael@0: michael@0: bool CStdOutStream::Close() michael@0: { michael@0: if(!_streamIsOpen) michael@0: return true; michael@0: _streamIsOpen = (fclose(_stream) != 0); michael@0: return !_streamIsOpen; michael@0: } michael@0: michael@0: bool CStdOutStream::Flush() michael@0: { michael@0: if(!_streamIsOpen) michael@0: return false; michael@0: return (fflush(_stream) == 0); michael@0: } michael@0: michael@0: CStdOutStream::~CStdOutStream () michael@0: { michael@0: Close(); michael@0: } michael@0: michael@0: CStdOutStream & CStdOutStream::operator<<(CStdOutStream & (*aFunction)(CStdOutStream &)) michael@0: { michael@0: (*aFunction)(*this); michael@0: return *this; michael@0: } michael@0: michael@0: CStdOutStream & endl(CStdOutStream & outStream) michael@0: { michael@0: return outStream << kNewLineChar; michael@0: } michael@0: michael@0: CStdOutStream & CStdOutStream::operator<<(const char *string) michael@0: { michael@0: fputs(string, _stream); michael@0: return *this; michael@0: } michael@0: michael@0: CStdOutStream & CStdOutStream::operator<<(const wchar_t *string) michael@0: { michael@0: *this << (const char *)UnicodeStringToMultiByte(string, CP_OEMCP); michael@0: return *this; michael@0: } michael@0: michael@0: CStdOutStream & CStdOutStream::operator<<(char c) michael@0: { michael@0: fputc(c, _stream); michael@0: return *this; michael@0: } michael@0: michael@0: CStdOutStream & CStdOutStream::operator<<(int number) michael@0: { michael@0: char textString[32]; michael@0: ConvertInt64ToString(number, textString); michael@0: return operator<<(textString); michael@0: } michael@0: michael@0: CStdOutStream & CStdOutStream::operator<<(UInt64 number) michael@0: { michael@0: char textString[32]; michael@0: ConvertUInt64ToString(number, textString); michael@0: return operator<<(textString); michael@0: }