1 // Created on: 2001-01-06
2 // Created by: OCC Team
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _Message_PrinterOStream_HeaderFile
17 #define _Message_PrinterOStream_HeaderFile
19 #include <Message_Printer.hxx>
20 #include <Standard_Address.hxx>
21 #include <Standard_OStream.hxx>
23 class Message_PrinterOStream;
24 DEFINE_STANDARD_HANDLE(Message_PrinterOStream, Message_Printer)
26 //! Implementation of a message printer associated with an std::ostream
27 //! The std::ostream may be either externally defined one (e.g. std::cout),
28 //! or file stream maintained internally (depending on constructor).
29 class Message_PrinterOStream : public Message_Printer
31 DEFINE_STANDARD_RTTIEXT(Message_PrinterOStream, Message_Printer)
34 //! Empty constructor, defaulting to cout
35 Standard_EXPORT Message_PrinterOStream(const Message_Gravity theTraceLevel = Message_Info);
37 //! Create printer for output to a specified file.
38 //! The option theDoAppend specifies whether file should be
39 //! appended or rewritten.
40 //! For specific file names (cout, cerr) standard streams are used
41 Standard_EXPORT Message_PrinterOStream(const Standard_CString theFileName, const Standard_Boolean theDoAppend, const Message_Gravity theTraceLevel = Message_Info);
43 //! Flushes the output stream and destroys it if it has been
44 //! specified externally with option doFree (or if it is internal
46 Standard_EXPORT void Close();
47 ~Message_PrinterOStream()
52 //! Returns option to convert non-Ascii symbols to UTF8 encoding
53 Standard_Boolean GetUseUtf8() const { return myUseUtf8; }
55 //! Sets option to convert non-Ascii symbols to UTF8 encoding
56 void SetUseUtf8 (const Standard_Boolean useUtf8) { myUseUtf8 = useUtf8; }
58 //! Returns reference to the output stream
59 Standard_OStream& GetStream() const { return *(Standard_OStream*)myStream; }
61 //! Puts a message to the current stream
62 //! if its gravity is equal or greater
63 //! to the trace level set by SetTraceLevel()
64 Standard_EXPORT virtual void Send (const Standard_CString theString, const Message_Gravity theGravity, const Standard_Boolean putEndl = Standard_True) const Standard_OVERRIDE;
66 //! Puts a message to the current stream
67 //! if its gravity is equal or greater
68 //! to the trace level set by SetTraceLevel()
69 Standard_EXPORT virtual void Send (const TCollection_AsciiString& theString, const Message_Gravity theGravity, const Standard_Boolean putEndl = Standard_True) const Standard_OVERRIDE;
71 //! Puts a message to the current stream
72 //! if its gravity is equal or greater
73 //! to the trace level set by SetTraceLevel()
74 //! Non-Ascii symbols are converted to UTF-8 if UseUtf8
75 //! option is set, else replaced by symbols '?'
76 Standard_EXPORT virtual void Send (const TCollection_ExtendedString& theString, const Message_Gravity theGravity, const Standard_Boolean putEndl = Standard_True) const Standard_OVERRIDE;
80 Standard_Address myStream;
81 Standard_Boolean myIsFile;
82 Standard_Boolean myUseUtf8;
86 #endif // _Message_PrinterOStream_HeaderFile