0028832: MMgt_TShared can be replaced by Standard_Transient
[occt.git] / src / Message / Message_Messenger.hxx
1 // Created on: 2007-06-28
2 // Created by: OCC Team
3 // Copyright (c) 2007-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_Messenger_HeaderFile
17 #define _Message_Messenger_HeaderFile
18
19 #include <Standard.hxx>
20 #include <Standard_Type.hxx>
21
22 #include <Message_SequenceOfPrinters.hxx>
23 #include <Standard_Transient.hxx>
24 #include <Standard_Boolean.hxx>
25 #include <Standard_Integer.hxx>
26 #include <Standard_Type.hxx>
27 #include <Standard_CString.hxx>
28 #include <Message_Gravity.hxx>
29 class Message_Printer;
30 class TCollection_AsciiString;
31 class TCollection_ExtendedString;
32
33 // resolve name collisions with WinAPI headers
34 #ifdef AddPrinter
35   #undef AddPrinter
36 #endif
37
38 class Message_Messenger;
39 DEFINE_STANDARD_HANDLE(Message_Messenger, Standard_Transient)
40
41 //! Messenger is API class providing general-purpose interface for
42 //! libraries that may issue text messages without knowledge
43 //! of how these messages will be further processed.
44 //!
45 //! The messenger contains a sequence of "printers" which can be
46 //! customized by the application, and dispatches every received
47 //! message to all the printers.
48 //!
49 //! For convenience, a number of operators << are defined with left
50 //! argument being Handle(Message_Messenger); thus it can be used
51 //! with syntax similar to C++ streams.
52 //! Note that all these operators use trace level Warning.
53 class Message_Messenger : public Standard_Transient
54 {
55
56 public:
57
58   
59   //! Empty constructor; initializes by single printer directed to cout.
60   //! Note: the default messenger is not empty but directed to cout
61   //! in order to protect against possibility to forget defining printers.
62   //! If printing to cout is not needed, clear messenger by GetPrinters().Clear()
63   Standard_EXPORT Message_Messenger();
64   
65   //! Create messenger with single printer
66   Standard_EXPORT Message_Messenger(const Handle(Message_Printer)& thePrinter);
67   
68   //! Add a printer to the messenger.
69   //! The printer will be added only if it is not yet in the list.
70   //! Returns True if printer has been added.
71   Standard_EXPORT Standard_Boolean AddPrinter (const Handle(Message_Printer)& thePrinter);
72   
73   //! Removes specified printer from the messenger.
74   //! Returns True if this printer has been found in the list
75   //! and removed.
76   Standard_EXPORT Standard_Boolean RemovePrinter (const Handle(Message_Printer)& thePrinter);
77   
78   //! Removes printers of specified type (including derived classes)
79   //! from the messenger.
80   //! Returns number of removed printers.
81   Standard_EXPORT Standard_Integer RemovePrinters (const Handle(Standard_Type)& theType);
82   
83   //! Returns current sequence of printers
84     const Message_SequenceOfPrinters& Printers() const;
85   
86   //! Returns sequence of printers
87   //! The sequence can be modified.
88     Message_SequenceOfPrinters& ChangePrinters();
89   
90   //! Dispatch a message to all the printers in the list.
91   //! Three versions of string representations are accepted for
92   //! convenience, by default all are converted to ExtendedString.
93   //! The parameter putEndl specifies whether the new line should
94   //! be started after this message (default) or not (may have
95   //! sense in some conditions).
96   Standard_EXPORT void Send (const Standard_CString theString, const Message_Gravity theGravity = Message_Warning, const Standard_Boolean putEndl = Standard_True) const;
97   
98   //! See above
99   Standard_EXPORT void Send (const TCollection_AsciiString& theString, const Message_Gravity theGravity = Message_Warning, const Standard_Boolean putEndl = Standard_True) const;
100   
101   //! See above
102   Standard_EXPORT void Send (const TCollection_ExtendedString& theString, const Message_Gravity theGravity = Message_Warning, const Standard_Boolean putEndl = Standard_True) const;
103
104
105
106
107   DEFINE_STANDARD_RTTIEXT(Message_Messenger,Standard_Transient)
108
109 protected:
110
111
112
113
114 private:
115
116
117   Message_SequenceOfPrinters myPrinters;
118
119
120 };
121
122
123 #include <Message_Messenger.lxx>
124
125
126
127
128
129 #endif // _Message_Messenger_HeaderFile