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.hxx>
18 #include <Message_Printer.hxx>
19 #include <Message_PrinterOStream.hxx>
21 IMPLEMENT_STANDARD_RTTIEXT(Message_Messenger,Standard_Transient)
23 //=======================================================================
24 //function : Message_Messenger
26 //=======================================================================
27 Message_Messenger::Message_Messenger ()
29 AddPrinter ( new Message_PrinterOStream );
32 //=======================================================================
33 //function : Message_Messenger
35 //=======================================================================
37 Message_Messenger::Message_Messenger (const Handle(Message_Printer)& thePrinter)
39 AddPrinter (thePrinter);
42 //=======================================================================
43 //function : AddPrinter
45 //=======================================================================
47 Standard_Boolean Message_Messenger::AddPrinter (const Handle(Message_Printer)& thePrinter)
49 // check whether printer is already in the list
50 for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
52 const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
53 if (aPrinter == thePrinter)
55 return Standard_False;
59 myPrinters.Append (thePrinter);
63 //=======================================================================
64 //function : RemovePrinter
66 //=======================================================================
68 Standard_Boolean Message_Messenger::RemovePrinter (const Handle(Message_Printer)& thePrinter)
70 // find printer in the list
71 for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
73 const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
74 if (aPrinter == thePrinter)
76 myPrinters.Remove (aPrinterIter);
80 return Standard_False;
83 //=======================================================================
84 //function : RemovePrinters
86 //=======================================================================
88 Standard_Integer Message_Messenger::RemovePrinters (const Handle(Standard_Type)& theType)
90 // remove printers from the list
91 Standard_Integer nb = 0;
92 for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More();)
94 const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
95 if (!aPrinter.IsNull() && aPrinter->IsKind (theType))
97 myPrinters.Remove (aPrinterIter);
108 //=======================================================================
111 //=======================================================================
113 void Message_Messenger::Send (const Standard_CString theString,
114 const Message_Gravity theGravity,
115 const Standard_Boolean putEndl) const
117 for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
119 const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
120 if (!aPrinter.IsNull())
122 aPrinter->Send (theString, theGravity, putEndl);
127 //=======================================================================
130 //=======================================================================
132 void Message_Messenger::Send (const TCollection_AsciiString& theString,
133 const Message_Gravity theGravity,
134 const Standard_Boolean putEndl) const
136 for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
138 const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
139 if (!aPrinter.IsNull())
141 aPrinter->Send (theString, theGravity, putEndl);
146 //=======================================================================
149 //=======================================================================
151 void Message_Messenger::Send (const TCollection_ExtendedString& theString,
152 const Message_Gravity theGravity,
153 const Standard_Boolean putEndl) const
155 for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
157 const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
158 if (!aPrinter.IsNull())
160 aPrinter->Send (theString, theGravity, putEndl);