1 // Created on: 2001-01-06
2 // Created by: OCC Team
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <Message_Messenger.ixx>
17 #include <Message_PrinterOStream.hxx>
19 //=======================================================================
20 //function : Message_Messenger
22 //=======================================================================
24 Message_Messenger::Message_Messenger ()
26 AddPrinter ( new Message_PrinterOStream );
29 //=======================================================================
30 //function : Message_Messenger
32 //=======================================================================
34 Message_Messenger::Message_Messenger (const Handle(Message_Printer)& thePrinter)
36 AddPrinter (thePrinter);
39 //=======================================================================
40 //function : AddPrinter
42 //=======================================================================
44 Standard_Boolean Message_Messenger::AddPrinter (const Handle(Message_Printer)& thePrinter)
46 // check whether printer is already in the list
47 for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
48 if ( myPrinters(i) == thePrinter )
49 return Standard_False;
51 myPrinters.Append (thePrinter);
55 //=======================================================================
56 //function : RemovePrinter
58 //=======================================================================
60 Standard_Boolean Message_Messenger::RemovePrinter (const Handle(Message_Printer)& thePrinter)
62 // find printer in the list
63 for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
64 if ( myPrinters(i) == thePrinter )
66 myPrinters.Remove (i);
69 return Standard_False;
72 //=======================================================================
73 //function : RemovePrinters
75 //=======================================================================
77 Standard_Integer Message_Messenger::RemovePrinters (const Handle(Standard_Type)& theType)
79 // remove printers from the list
80 Standard_Integer nb = 0;
81 for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
82 if ( myPrinters(i)->IsKind(theType) )
84 myPrinters.Remove (i--);
90 //=======================================================================
93 //=======================================================================
95 void Message_Messenger::Send (const Standard_CString theString,
96 const Message_Gravity theGravity,
97 const Standard_Boolean putEndl) const
99 Standard_Integer nb = myPrinters.Length();
100 for (Standard_Integer i = 1; i <= nb; i++)
102 Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
103 if ( ! aPrinter.IsNull() )
104 aPrinter->Send ( theString, theGravity, putEndl );
108 //=======================================================================
111 //=======================================================================
113 void Message_Messenger::Send (const TCollection_AsciiString& theString,
114 const Message_Gravity theGravity,
115 const Standard_Boolean putEndl) const
117 Standard_Integer nb = myPrinters.Length();
118 for (Standard_Integer i = 1; i <= nb; i++)
120 Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
121 if ( ! aPrinter.IsNull() )
122 aPrinter->Send ( theString, theGravity, putEndl );
126 //=======================================================================
129 //=======================================================================
131 void Message_Messenger::Send (const TCollection_ExtendedString& theString,
132 const Message_Gravity theGravity,
133 const Standard_Boolean putEndl) const
135 Standard_Integer nb = myPrinters.Length();
136 for (Standard_Integer i = 1; i <= nb; i++)
138 Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
139 if ( ! aPrinter.IsNull() )
140 aPrinter->Send ( theString, theGravity, putEndl );