1e44c8b22088a0df17d6cb11cda947fa5e0a4451
[occt.git] / src / Message / Message_Messenger.cxx
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
21 IMPLEMENT_STANDARD_RTTIEXT(Message_Messenger,Standard_Transient)
22
23 //=======================================================================
24 //function : Message_Messenger
25 //purpose  : 
26 //=======================================================================
27 Message_Messenger::Message_Messenger ()
28 {
29   AddPrinter ( new Message_PrinterOStream );
30 }
31
32 //=======================================================================
33 //function : Message_Messenger
34 //purpose  : 
35 //=======================================================================
36
37 Message_Messenger::Message_Messenger (const Handle(Message_Printer)& thePrinter)
38 {
39   AddPrinter (thePrinter);
40 }
41
42 //=======================================================================
43 //function : AddPrinter
44 //purpose  : 
45 //=======================================================================
46
47 Standard_Boolean Message_Messenger::AddPrinter (const Handle(Message_Printer)& thePrinter)
48 {
49   // check whether printer is already in the list
50   for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
51   {
52     const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
53     if (aPrinter == thePrinter)
54     {
55       return Standard_False;
56     }
57   }
58
59   myPrinters.Append (thePrinter);
60   return Standard_True;
61 }
62
63 //=======================================================================
64 //function : RemovePrinter
65 //purpose  : 
66 //=======================================================================
67
68 Standard_Boolean Message_Messenger::RemovePrinter (const Handle(Message_Printer)& thePrinter)
69 {
70   // find printer in the list
71   for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
72   {
73     const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
74     if (aPrinter == thePrinter)
75     {
76       myPrinters.Remove (aPrinterIter);
77       return Standard_True;
78     }
79   }
80   return Standard_False;
81 }
82
83 //=======================================================================
84 //function : RemovePrinters
85 //purpose  : 
86 //=======================================================================
87
88 Standard_Integer Message_Messenger::RemovePrinters (const Handle(Standard_Type)& theType)
89 {
90   // remove printers from the list
91   Standard_Integer nb = 0;
92   for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More();)
93   {
94     const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
95     if (!aPrinter.IsNull() && aPrinter->IsKind (theType))
96     {
97       myPrinters.Remove (aPrinterIter);
98       nb++;
99     }
100     else
101     {
102       aPrinterIter.Next();
103     }
104   }
105   return nb;
106 }
107
108 //=======================================================================
109 //function : Send
110 //purpose  : 
111 //=======================================================================
112
113 void Message_Messenger::Send (const Standard_CString theString,
114                               const Message_Gravity theGravity,
115                               const Standard_Boolean putEndl) 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, putEndl);
123     }
124   }
125 }
126
127 //=======================================================================
128 //function : Send
129 //purpose  : 
130 //=======================================================================
131
132 void Message_Messenger::Send (const TCollection_AsciiString& theString,
133                                      const Message_Gravity theGravity,
134                                      const Standard_Boolean putEndl) const
135 {
136   for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
137   {
138     const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
139     if (!aPrinter.IsNull())
140     {
141       aPrinter->Send (theString, theGravity, putEndl);
142     }
143   }
144 }
145
146 //=======================================================================
147 //function : Send
148 //purpose  : 
149 //=======================================================================
150
151 void Message_Messenger::Send (const TCollection_ExtendedString& theString,
152                                      const Message_Gravity theGravity,
153                                      const Standard_Boolean putEndl) const
154 {
155   for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
156   {
157     const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
158     if (!aPrinter.IsNull())
159     {
160       aPrinter->Send (theString, theGravity, putEndl);
161     }
162   }
163 }