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.
17 #include <Message_Messenger.hxx>
18 #include <Message_Printer.hxx>
19 #include <Message_PrinterOStream.hxx>
20 #include <Standard_Type.hxx>
21 #include <TCollection_AsciiString.hxx>
22 #include <TCollection_ExtendedString.hxx>
24 IMPLEMENT_STANDARD_RTTIEXT(Message_Messenger,Standard_Transient)
26 //=======================================================================
27 //function : Message_Messenger
29 //=======================================================================
30 Message_Messenger::Message_Messenger ()
32 AddPrinter ( new Message_PrinterOStream );
35 //=======================================================================
36 //function : Message_Messenger
38 //=======================================================================
40 Message_Messenger::Message_Messenger (const Handle(Message_Printer)& thePrinter)
42 AddPrinter (thePrinter);
45 //=======================================================================
46 //function : AddPrinter
48 //=======================================================================
50 Standard_Boolean Message_Messenger::AddPrinter (const Handle(Message_Printer)& thePrinter)
52 // check whether printer is already in the list
53 for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
54 if ( myPrinters(i) == thePrinter )
55 return Standard_False;
57 myPrinters.Append (thePrinter);
61 //=======================================================================
62 //function : RemovePrinter
64 //=======================================================================
66 Standard_Boolean Message_Messenger::RemovePrinter (const Handle(Message_Printer)& thePrinter)
68 // find printer in the list
69 for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
70 if ( myPrinters(i) == thePrinter )
72 myPrinters.Remove (i);
75 return Standard_False;
78 //=======================================================================
79 //function : RemovePrinters
81 //=======================================================================
83 Standard_Integer Message_Messenger::RemovePrinters (const Handle(Standard_Type)& theType)
85 // remove printers from the list
86 Standard_Integer nb = 0;
87 for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
88 if ( myPrinters(i)->IsKind(theType) )
90 myPrinters.Remove (i--);
96 //=======================================================================
99 //=======================================================================
101 void Message_Messenger::Send (const Standard_CString theString,
102 const Message_Gravity theGravity,
103 const Standard_Boolean putEndl) const
105 Standard_Integer nb = myPrinters.Length();
106 for (Standard_Integer i = 1; i <= nb; i++)
108 Handle(Message_Printer) aPrinter = myPrinters(i);
109 if ( ! aPrinter.IsNull() )
110 aPrinter->Send ( theString, theGravity, putEndl );
114 //=======================================================================
117 //=======================================================================
119 void Message_Messenger::Send (const TCollection_AsciiString& theString,
120 const Message_Gravity theGravity,
121 const Standard_Boolean putEndl) const
123 Standard_Integer nb = myPrinters.Length();
124 for (Standard_Integer i = 1; i <= nb; i++)
126 Handle(Message_Printer) aPrinter = myPrinters(i);
127 if ( ! aPrinter.IsNull() )
128 aPrinter->Send ( theString, theGravity, putEndl );
132 //=======================================================================
135 //=======================================================================
137 void Message_Messenger::Send (const TCollection_ExtendedString& theString,
138 const Message_Gravity theGravity,
139 const Standard_Boolean putEndl) const
141 Standard_Integer nb = myPrinters.Length();
142 for (Standard_Integer i = 1; i <= nb; i++)
144 Handle(Message_Printer) aPrinter = myPrinters(i);
145 if ( ! aPrinter.IsNull() )
146 aPrinter->Send ( theString, theGravity, putEndl );