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>
18 #include <Message_Printer.hxx>
20 //=======================================================================
21 //function : Message_Messenger
23 //=======================================================================
25 Message_Messenger::Message_Messenger ()
27 AddPrinter ( new Message_PrinterOStream );
30 //=======================================================================
31 //function : Message_Messenger
33 //=======================================================================
35 Message_Messenger::Message_Messenger (const Handle(Message_Printer)& thePrinter)
37 AddPrinter (thePrinter);
40 //=======================================================================
41 //function : AddPrinter
43 //=======================================================================
45 Standard_Boolean Message_Messenger::AddPrinter (const Handle(Message_Printer)& thePrinter)
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;
52 myPrinters.Append (thePrinter);
56 //=======================================================================
57 //function : RemovePrinter
59 //=======================================================================
61 Standard_Boolean Message_Messenger::RemovePrinter (const Handle(Message_Printer)& thePrinter)
63 // find printer in the list
64 for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
65 if ( myPrinters(i) == thePrinter )
67 myPrinters.Remove (i);
70 return Standard_False;
73 //=======================================================================
74 //function : RemovePrinters
76 //=======================================================================
78 Standard_Integer Message_Messenger::RemovePrinters (const Handle(Standard_Type)& theType)
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) )
85 myPrinters.Remove (i--);
91 //=======================================================================
94 //=======================================================================
96 void Message_Messenger::Send (const Standard_CString theString,
97 const Message_Gravity theGravity,
98 const Standard_Boolean putEndl) const
100 Standard_Integer nb = myPrinters.Length();
101 for (Standard_Integer i = 1; i <= nb; i++)
103 Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
104 if ( ! aPrinter.IsNull() )
105 aPrinter->Send ( theString, theGravity, putEndl );
109 //=======================================================================
112 //=======================================================================
114 void Message_Messenger::Send (const TCollection_AsciiString& theString,
115 const Message_Gravity theGravity,
116 const Standard_Boolean putEndl) const
118 Standard_Integer nb = myPrinters.Length();
119 for (Standard_Integer i = 1; i <= nb; i++)
121 Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
122 if ( ! aPrinter.IsNull() )
123 aPrinter->Send ( theString, theGravity, putEndl );
127 //=======================================================================
130 //=======================================================================
132 void Message_Messenger::Send (const TCollection_ExtendedString& theString,
133 const Message_Gravity theGravity,
134 const Standard_Boolean putEndl) const
136 Standard_Integer nb = myPrinters.Length();
137 for (Standard_Integer i = 1; i <= nb; i++)
139 Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
140 if ( ! aPrinter.IsNull() )
141 aPrinter->Send ( theString, theGravity, putEndl );