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 #include <Message_Messenger.hxx>
17 
18 #include <Message_Printer.hxx>
19 #include <Message_PrinterOStream.hxx>
20 #include <Standard_Dump.hxx>
21 
IMPLEMENT_STANDARD_RTTIEXT(Message_Messenger,Standard_Transient)22 IMPLEMENT_STANDARD_RTTIEXT(Message_Messenger,Standard_Transient)
23 
24 //=======================================================================
25 //function : Message_Messenger
26 //purpose  :
27 //=======================================================================
28 Message_Messenger::Message_Messenger ()
29 {
30   AddPrinter ( new Message_PrinterOStream );
31 }
32 
33 //=======================================================================
34 //function : Message_Messenger
35 //purpose  :
36 //=======================================================================
37 
Message_Messenger(const Handle (Message_Printer)& thePrinter)38 Message_Messenger::Message_Messenger (const Handle(Message_Printer)& thePrinter)
39 {
40   AddPrinter (thePrinter);
41 }
42 
43 //=======================================================================
44 //function : AddPrinter
45 //purpose  :
46 //=======================================================================
47 
AddPrinter(const Handle (Message_Printer)& thePrinter)48 Standard_Boolean Message_Messenger::AddPrinter (const Handle(Message_Printer)& thePrinter)
49 {
50   // check whether printer is already in the list
51   for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
52   {
53     const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
54     if (aPrinter == thePrinter)
55     {
56       return Standard_False;
57     }
58   }
59 
60   myPrinters.Append (thePrinter);
61   return Standard_True;
62 }
63 
64 //=======================================================================
65 //function : RemovePrinter
66 //purpose  :
67 //=======================================================================
68 
RemovePrinter(const Handle (Message_Printer)& thePrinter)69 Standard_Boolean Message_Messenger::RemovePrinter (const Handle(Message_Printer)& thePrinter)
70 {
71   // find printer in the list
72   for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
73   {
74     const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
75     if (aPrinter == thePrinter)
76     {
77       myPrinters.Remove (aPrinterIter);
78       return Standard_True;
79     }
80   }
81   return Standard_False;
82 }
83 
84 //=======================================================================
85 //function : RemovePrinters
86 //purpose  :
87 //=======================================================================
88 
RemovePrinters(const Handle (Standard_Type)& theType)89 Standard_Integer Message_Messenger::RemovePrinters (const Handle(Standard_Type)& theType)
90 {
91   // remove printers from the list
92   Standard_Integer nb = 0;
93   for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More();)
94   {
95     const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
96     if (!aPrinter.IsNull() && aPrinter->IsKind (theType))
97     {
98       myPrinters.Remove (aPrinterIter);
99       nb++;
100     }
101     else
102     {
103       aPrinterIter.Next();
104     }
105   }
106   return nb;
107 }
108 
109 //=======================================================================
110 //function : Send
111 //purpose  :
112 //=======================================================================
113 
Send(const Standard_CString theString,const Message_Gravity theGravity) const114 void Message_Messenger::Send (const Standard_CString theString,
115 			      const Message_Gravity theGravity) const
116 {
117   for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
118   {
119     const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
120     if (!aPrinter.IsNull())
121     {
122       aPrinter->Send (theString, theGravity);
123     }
124   }
125 }
126 
127 //=======================================================================
128 //function : Send
129 //purpose  :
130 //=======================================================================
Send(const Standard_SStream & theStream,const Message_Gravity theGravity) const131 void Message_Messenger::Send (const Standard_SStream& theStream,
132                               const Message_Gravity theGravity) const
133 {
134   for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
135   {
136     const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
137     if (!aPrinter.IsNull())
138     {
139       aPrinter->SendStringStream (theStream, theGravity);
140     }
141   }
142 }
143 
144 //=======================================================================
145 //function : Send
146 //purpose  :
147 //=======================================================================
Send(const TCollection_AsciiString & theString,const Message_Gravity theGravity) const148 void Message_Messenger::Send (const TCollection_AsciiString& theString,
149                               const Message_Gravity theGravity) const
150 {
151   for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
152   {
153     const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
154     if (!aPrinter.IsNull())
155     {
156       aPrinter->Send (theString, theGravity);
157     }
158   }
159 }
160 
161 //=======================================================================
162 //function : Send
163 //purpose  :
164 //=======================================================================
165 
Send(const TCollection_ExtendedString & theString,const Message_Gravity theGravity) const166 void Message_Messenger::Send (const TCollection_ExtendedString& theString,
167                               const Message_Gravity theGravity) const
168 {
169   for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
170   {
171     const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
172     if (!aPrinter.IsNull())
173     {
174       aPrinter->Send (theString, theGravity);
175     }
176   }
177 }
178 
179 //=======================================================================
180 //function : Send
181 //purpose  :
182 //=======================================================================
Send(const Handle (Standard_Transient)& theObject,const Message_Gravity theGravity) const183 void Message_Messenger::Send (const Handle(Standard_Transient)& theObject,
184                               const Message_Gravity theGravity) const
185 {
186   for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
187   {
188     const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
189     if (!aPrinter.IsNull())
190     {
191       aPrinter->SendObject (theObject, theGravity);
192     }
193   }
194 }
195 
196 //=======================================================================
197 //function : DumpJson
198 //purpose  :
199 //=======================================================================
DumpJson(Standard_OStream & theOStream,Standard_Integer) const200 void Message_Messenger::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
201 {
202   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
203 
204   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myPrinters.Size())
205 }
206