0031036: Foundation Classes, Message_PrinterOStream - add option printing colored...
[occt.git] / src / Message / Message_PrinterOStream.hxx
CommitLineData
42cf5bc1 1// Created on: 2001-01-06
2// Created by: OCC Team
3// Copyright (c) 2001-2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
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.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#ifndef _Message_PrinterOStream_HeaderFile
17#define _Message_PrinterOStream_HeaderFile
18
e1d039d5 19#include <Message_ConsoleColor.hxx>
42cf5bc1 20#include <Message_Printer.hxx>
983fd6c0 21#include <Standard_Address.hxx>
42cf5bc1 22#include <Standard_OStream.hxx>
42cf5bc1 23
24class Message_PrinterOStream;
25DEFINE_STANDARD_HANDLE(Message_PrinterOStream, Message_Printer)
26
04232180 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),
42cf5bc1 29//! or file stream maintained internally (depending on constructor).
30class Message_PrinterOStream : public Message_Printer
31{
983fd6c0 32 DEFINE_STANDARD_RTTIEXT(Message_PrinterOStream, Message_Printer)
e1d039d5 33public:
34
35 //! Setup console text color.
36 //!
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.
41 //!
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);
47
42cf5bc1 48public:
42cf5bc1 49
50 //! Empty constructor, defaulting to cout
51 Standard_EXPORT Message_PrinterOStream(const Message_Gravity theTraceLevel = Message_Info);
52
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);
58
59 //! Flushes the output stream and destroys it if it has been
60 //! specified externally with option doFree (or if it is internal
61 //! file stream)
62 Standard_EXPORT void Close();
63~Message_PrinterOStream()
64{
65 Close();
66}
983fd6c0 67
42cf5bc1 68 //! Returns option to convert non-Ascii symbols to UTF8 encoding
983fd6c0 69 Standard_Boolean GetUseUtf8() const { return myUseUtf8; }
42cf5bc1 70
71 //! Sets option to convert non-Ascii symbols to UTF8 encoding
983fd6c0 72 void SetUseUtf8 (const Standard_Boolean useUtf8) { myUseUtf8 = useUtf8; }
73
42cf5bc1 74 //! Returns reference to the output stream
983fd6c0 75 Standard_OStream& GetStream() const { return *(Standard_OStream*)myStream; }
e1d039d5 76
77 //! Returns TRUE if text output into console should be colorized depending on message gravity.
78 Standard_Boolean ToColorize() const { return myToColorize; }
79
80 //! Set if text output into console should be colorized depending on message gravity.
81 void SetToColorize (Standard_Boolean theToColorize) { myToColorize = theToColorize; }
82
42cf5bc1 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;
87
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;
92
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;
99
42cf5bc1 100private:
101
42cf5bc1 102 Standard_Address myStream;
103 Standard_Boolean myIsFile;
104 Standard_Boolean myUseUtf8;
e1d039d5 105 Standard_Boolean myToColorize;
42cf5bc1 106
42cf5bc1 107};
108
42cf5bc1 109#endif // _Message_PrinterOStream_HeaderFile