1 // Created on: 2001-01-06
2 // Created by: OCC Team
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <Message_Messenger.ixx>
22 #include <Message_PrinterOStream.hxx>
24 //=======================================================================
25 //function : Message_Messenger
27 //=======================================================================
29 Message_Messenger::Message_Messenger ()
31 AddPrinter ( new Message_PrinterOStream );
34 //=======================================================================
35 //function : Message_Messenger
37 //=======================================================================
39 Message_Messenger::Message_Messenger (const Handle(Message_Printer)& thePrinter)
41 AddPrinter (thePrinter);
44 //=======================================================================
45 //function : AddPrinter
47 //=======================================================================
49 Standard_Boolean Message_Messenger::AddPrinter (const Handle(Message_Printer)& thePrinter)
51 // check whether printer is already in the list
52 for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
53 if ( myPrinters(i) == thePrinter )
54 return Standard_False;
56 myPrinters.Append (thePrinter);
60 //=======================================================================
61 //function : RemovePrinter
63 //=======================================================================
65 Standard_Boolean Message_Messenger::RemovePrinter (const Handle(Message_Printer)& thePrinter)
67 // find printer in the list
68 for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
69 if ( myPrinters(i) == thePrinter )
71 myPrinters.Remove (i);
74 return Standard_False;
77 //=======================================================================
78 //function : RemovePrinters
80 //=======================================================================
82 Standard_Integer Message_Messenger::RemovePrinters (const Handle(Standard_Type)& theType)
84 // remove printers from the list
85 Standard_Integer nb = 0;
86 for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
87 if ( myPrinters(i)->IsKind(theType) )
89 myPrinters.Remove (i--);
95 //=======================================================================
98 //=======================================================================
100 void Message_Messenger::Send (const Standard_CString theString,
101 const Message_Gravity theGravity,
102 const Standard_Boolean putEndl) const
104 Standard_Integer nb = myPrinters.Length();
105 for (Standard_Integer i = 1; i <= nb; i++)
107 Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
108 if ( ! aPrinter.IsNull() )
109 aPrinter->Send ( theString, theGravity, putEndl );
113 //=======================================================================
116 //=======================================================================
118 void Message_Messenger::Send (const TCollection_AsciiString& theString,
119 const Message_Gravity theGravity,
120 const Standard_Boolean putEndl) const
122 Standard_Integer nb = myPrinters.Length();
123 for (Standard_Integer i = 1; i <= nb; i++)
125 Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
126 if ( ! aPrinter.IsNull() )
127 aPrinter->Send ( theString, theGravity, putEndl );
131 //=======================================================================
134 //=======================================================================
136 void Message_Messenger::Send (const TCollection_ExtendedString& theString,
137 const Message_Gravity theGravity,
138 const Standard_Boolean putEndl) const
140 Standard_Integer nb = myPrinters.Length();
141 for (Standard_Integer i = 1; i <= nb; i++)
143 Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
144 if ( ! aPrinter.IsNull() )
145 aPrinter->Send ( theString, theGravity, putEndl );