01c6a1c8946220bc0d732b3d98ba83c59857b4bd
[occt.git] / src / Message / Message_PrinterOStream.hxx
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
19 #include <Standard.hxx>
20 #include <Standard_Type.hxx>
21
22 #include <Standard_Address.hxx>
23 #include <Standard_Boolean.hxx>
24 #include <Message_Printer.hxx>
25 #include <Message_Gravity.hxx>
26 #include <Standard_CString.hxx>
27 #include <Standard_OStream.hxx>
28 class TCollection_AsciiString;
29 class TCollection_ExtendedString;
30
31
32 class Message_PrinterOStream;
33 DEFINE_STANDARD_HANDLE(Message_PrinterOStream, Message_Printer)
34
35 //! Implementation of a message printer associated with an ostream
36 //! The ostream may be either externally defined one (e.g. cout),
37 //! or file stream maintained internally (depending on constructor).
38 class Message_PrinterOStream : public Message_Printer
39 {
40
41 public:
42
43   
44   //! Empty constructor, defaulting to cout
45   Standard_EXPORT Message_PrinterOStream(const Message_Gravity theTraceLevel = Message_Info);
46   
47   //! Create printer for output to a specified file.
48   //! The option theDoAppend specifies whether file should be
49   //! appended or rewritten.
50   //! For specific file names (cout, cerr) standard streams are used
51   Standard_EXPORT Message_PrinterOStream(const Standard_CString theFileName, const Standard_Boolean theDoAppend, const Message_Gravity theTraceLevel = Message_Info);
52   
53   //! Flushes the output stream and destroys it if it has been
54   //! specified externally with option doFree (or if it is internal
55   //! file stream)
56   Standard_EXPORT void Close();
57 ~Message_PrinterOStream()
58 {
59   Close();
60 }
61   
62   //! Returns option to convert non-Ascii symbols to UTF8 encoding
63     Standard_Boolean GetUseUtf8() const;
64   
65   //! Sets option to convert non-Ascii symbols to UTF8 encoding
66     void SetUseUtf8 (const Standard_Boolean useUtf8);
67   
68   //! Returns reference to the output stream
69     Standard_OStream& GetStream() const;
70   
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   Standard_EXPORT virtual void Send (const Standard_CString theString, const Message_Gravity theGravity, const Standard_Boolean putEndl = Standard_True) const Standard_OVERRIDE;
75   
76   //! Puts a message to the current stream
77   //! if its gravity is equal or greater
78   //! to the trace level set by SetTraceLevel()
79   Standard_EXPORT virtual void Send (const TCollection_AsciiString& theString, const Message_Gravity theGravity, const Standard_Boolean putEndl = Standard_True) const Standard_OVERRIDE;
80   
81   //! Puts a message to the current stream
82   //! if its gravity is equal or greater
83   //! to the trace level set by SetTraceLevel()
84   //! Non-Ascii symbols are converted to UTF-8 if UseUtf8
85   //! option is set, else replaced by symbols '?'
86   Standard_EXPORT virtual void Send (const TCollection_ExtendedString& theString, const Message_Gravity theGravity, const Standard_Boolean putEndl = Standard_True) const Standard_OVERRIDE;
87
88
89
90   DEFINE_STANDARD_RTTIEXT(Message_PrinterOStream,Message_Printer)
91
92 protected:
93
94
95
96
97 private:
98
99
100   Standard_Address myStream;
101   Standard_Boolean myIsFile;
102   Standard_Boolean myUseUtf8;
103
104
105 };
106
107
108 #include <Message_PrinterOStream.lxx>
109
110
111
112
113
114 #endif // _Message_PrinterOStream_HeaderFile