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_ConsoleColor.hxx>
20 #include <Message_Printer.hxx>
21 #include <Standard_Address.hxx>
22 #include <Standard_OStream.hxx>
24 class Message_PrinterOStream;
25 DEFINE_STANDARD_HANDLE(Message_PrinterOStream, Message_Printer)
27 //! Implementation of a message printer associated with an std::ostream
28 //! The std::ostream may be either externally defined one (e.g. std::cout),
29 //! or file stream maintained internally (depending on constructor).
30 class Message_PrinterOStream : public Message_Printer
32 DEFINE_STANDARD_RTTIEXT(Message_PrinterOStream, Message_Printer)
35 //! Setup console text color.
37 //! On Windows, this would affect active terminal color output.
38 //! On other systems, this would put special terminal codes;
39 //! the terminal should support these codes or them will appear in text otherwise.
40 //! The same will happen when stream is redirected into text file.
42 //! Beware that within multi-threaded environment inducing console colors
43 //! might lead to colored text mixture due to concurrency.
44 Standard_EXPORT static void SetConsoleTextColor (Standard_OStream* theOStream,
45 Message_ConsoleColor theTextColor,
46 bool theIsIntenseText = false);
50 //! Empty constructor, defaulting to cout
51 Standard_EXPORT Message_PrinterOStream(const Message_Gravity theTraceLevel = Message_Info);
53 //! Create printer for output to a specified file.
54 //! The option theDoAppend specifies whether file should be
55 //! appended or rewritten.
56 //! For specific file names (cout, cerr) standard streams are used
57 Standard_EXPORT Message_PrinterOStream(const Standard_CString theFileName, const Standard_Boolean theDoAppend, const Message_Gravity theTraceLevel = Message_Info);
59 //! Flushes the output stream and destroys it if it has been
60 //! specified externally with option doFree (or if it is internal
62 Standard_EXPORT void Close();
63 ~Message_PrinterOStream()
68 //! Returns option to convert non-Ascii symbols to UTF8 encoding
69 Standard_Boolean GetUseUtf8() const { return myUseUtf8; }
71 //! Sets option to convert non-Ascii symbols to UTF8 encoding
72 void SetUseUtf8 (const Standard_Boolean useUtf8) { myUseUtf8 = useUtf8; }
74 //! Returns reference to the output stream
75 Standard_OStream& GetStream() const { return *(Standard_OStream*)myStream; }
77 //! Returns TRUE if text output into console should be colorized depending on message gravity; TRUE by default.
78 Standard_Boolean ToColorize() const { return myToColorize; }
80 //! Set if text output into console should be colorized depending on message gravity.
81 void SetToColorize (Standard_Boolean theToColorize) { myToColorize = theToColorize; }
83 //! Puts a message to the current stream
84 //! if its gravity is equal or greater
85 //! to the trace level set by SetTraceLevel()
86 Standard_EXPORT virtual void Send (const Standard_CString theString, const Message_Gravity theGravity, const Standard_Boolean putEndl = Standard_True) const Standard_OVERRIDE;
88 //! Puts a message to the current stream
89 //! if its gravity is equal or greater
90 //! to the trace level set by SetTraceLevel()
91 Standard_EXPORT virtual void Send (const TCollection_AsciiString& theString, const Message_Gravity theGravity, const Standard_Boolean putEndl = Standard_True) const Standard_OVERRIDE;
93 //! Puts a message to the current stream
94 //! if its gravity is equal or greater
95 //! to the trace level set by SetTraceLevel()
96 //! Non-Ascii symbols are converted to UTF-8 if UseUtf8
97 //! option is set, else replaced by symbols '?'
98 Standard_EXPORT virtual void Send (const TCollection_ExtendedString& theString, const Message_Gravity theGravity, const Standard_Boolean putEndl = Standard_True) const Standard_OVERRIDE;
102 Standard_Address myStream;
103 Standard_Boolean myIsFile;
104 Standard_Boolean myUseUtf8;
105 Standard_Boolean myToColorize;
109 #endif // _Message_PrinterOStream_HeaderFile