0024947: Redesign OCCT legacy type system -- automatic
[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.ixx>
17 #include <Message_PrinterOStream.hxx>
18 #include <Message_Printer.hxx>
19
20 //=======================================================================
21 //function : Message_Messenger
22 //purpose  : 
23 //=======================================================================
24
25 Message_Messenger::Message_Messenger ()
26 {
27   AddPrinter ( new Message_PrinterOStream );
28 }
29
30 //=======================================================================
31 //function : Message_Messenger
32 //purpose  : 
33 //=======================================================================
34
35 Message_Messenger::Message_Messenger (const Handle(Message_Printer)& thePrinter)
36 {
37   AddPrinter (thePrinter);
38 }
39
40 //=======================================================================
41 //function : AddPrinter
42 //purpose  : 
43 //=======================================================================
44
45 Standard_Boolean Message_Messenger::AddPrinter (const Handle(Message_Printer)& thePrinter)
46 {
47   // check whether printer is already in the list
48   for (Standard_Integer i=1; i <= myPrinters.Length(); i++) 
49     if ( myPrinters(i) == thePrinter ) 
50       return Standard_False;
51   // add to the list
52   myPrinters.Append (thePrinter);
53   return Standard_True;
54 }
55
56 //=======================================================================
57 //function : RemovePrinter
58 //purpose  : 
59 //=======================================================================
60
61 Standard_Boolean Message_Messenger::RemovePrinter (const Handle(Message_Printer)& thePrinter)
62 {
63   // find printer in the list
64   for (Standard_Integer i=1; i <= myPrinters.Length(); i++) 
65     if ( myPrinters(i) == thePrinter ) 
66     {
67       myPrinters.Remove (i);
68       return Standard_True;
69     }
70   return Standard_False;
71 }
72
73 //=======================================================================
74 //function : RemovePrinters
75 //purpose  : 
76 //=======================================================================
77
78 Standard_Integer Message_Messenger::RemovePrinters (const Handle(Standard_Type)& theType)
79 {
80   // remove printers from the list
81   Standard_Integer nb = 0;
82   for (Standard_Integer i=1; i <= myPrinters.Length(); i++) 
83     if ( myPrinters(i)->IsKind(theType) ) 
84     {
85       myPrinters.Remove (i--);
86       nb++;
87     }
88   return nb;
89 }
90
91 //=======================================================================
92 //function : Send
93 //purpose  : 
94 //=======================================================================
95
96 void Message_Messenger::Send (const Standard_CString theString,
97                               const Message_Gravity theGravity,
98                               const Standard_Boolean putEndl) const
99 {
100   Standard_Integer nb = myPrinters.Length();
101   for (Standard_Integer i = 1; i <= nb; i++)
102   {
103     Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
104     if ( ! aPrinter.IsNull() ) 
105       aPrinter->Send ( theString, theGravity, putEndl );
106   }
107 }
108
109 //=======================================================================
110 //function : Send
111 //purpose  : 
112 //=======================================================================
113
114 void Message_Messenger::Send (const TCollection_AsciiString& theString,
115                                      const Message_Gravity theGravity,
116                                      const Standard_Boolean putEndl) const
117 {
118   Standard_Integer nb = myPrinters.Length();
119   for (Standard_Integer i = 1; i <= nb; i++)
120   {
121     Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
122     if ( ! aPrinter.IsNull() ) 
123       aPrinter->Send ( theString, theGravity, putEndl );
124   }
125 }
126
127 //=======================================================================
128 //function : Send
129 //purpose  : 
130 //=======================================================================
131
132 void Message_Messenger::Send (const TCollection_ExtendedString& theString,
133                                      const Message_Gravity theGravity,
134                                      const Standard_Boolean putEndl) const
135 {
136   Standard_Integer nb = myPrinters.Length();
137   for (Standard_Integer i = 1; i <= nb; i++)
138   {
139     Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
140     if ( ! aPrinter.IsNull() ) 
141       aPrinter->Send ( theString, theGravity, putEndl );
142   }
143 }