0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / src / Message / Message_Messenger.cxx
CommitLineData
b311480e 1// Created on: 2001-01-06
2// Created by: OCC Team
973c2be1 3// Copyright (c) 2001-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
42cf5bc1 16
17#include <Message_Messenger.hxx>
ec357c5c 18#include <Message_Printer.hxx>
42cf5bc1 19#include <Message_PrinterOStream.hxx>
20#include <Standard_Type.hxx>
21#include <TCollection_AsciiString.hxx>
22#include <TCollection_ExtendedString.hxx>
7fd59977 23
92efcf78 24IMPLEMENT_STANDARD_RTTIEXT(Message_Messenger,MMgt_TShared)
25
7fd59977 26//=======================================================================
27//function : Message_Messenger
28//purpose :
29//=======================================================================
7fd59977 30Message_Messenger::Message_Messenger ()
31{
32 AddPrinter ( new Message_PrinterOStream );
33}
34
35//=======================================================================
36//function : Message_Messenger
37//purpose :
38//=======================================================================
39
40Message_Messenger::Message_Messenger (const Handle(Message_Printer)& thePrinter)
41{
42 AddPrinter (thePrinter);
43}
44
45//=======================================================================
46//function : AddPrinter
47//purpose :
48//=======================================================================
49
50Standard_Boolean Message_Messenger::AddPrinter (const Handle(Message_Printer)& thePrinter)
51{
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;
56 // add to the list
57 myPrinters.Append (thePrinter);
58 return Standard_True;
59}
60
61//=======================================================================
62//function : RemovePrinter
63//purpose :
64//=======================================================================
65
66Standard_Boolean Message_Messenger::RemovePrinter (const Handle(Message_Printer)& thePrinter)
67{
68 // find printer in the list
69 for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
70 if ( myPrinters(i) == thePrinter )
71 {
72 myPrinters.Remove (i);
73 return Standard_True;
74 }
75 return Standard_False;
76}
77
78//=======================================================================
79//function : RemovePrinters
80//purpose :
81//=======================================================================
82
83Standard_Integer Message_Messenger::RemovePrinters (const Handle(Standard_Type)& theType)
84{
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) )
89 {
90 myPrinters.Remove (i--);
91 nb++;
92 }
93 return nb;
94}
95
96//=======================================================================
97//function : Send
98//purpose :
99//=======================================================================
100
101void Message_Messenger::Send (const Standard_CString theString,
102 const Message_Gravity theGravity,
103 const Standard_Boolean putEndl) const
104{
105 Standard_Integer nb = myPrinters.Length();
106 for (Standard_Integer i = 1; i <= nb; i++)
107 {
108 Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
109 if ( ! aPrinter.IsNull() )
110 aPrinter->Send ( theString, theGravity, putEndl );
111 }
112}
113
114//=======================================================================
115//function : Send
116//purpose :
117//=======================================================================
118
119void Message_Messenger::Send (const TCollection_AsciiString& theString,
120 const Message_Gravity theGravity,
121 const Standard_Boolean putEndl) const
122{
123 Standard_Integer nb = myPrinters.Length();
124 for (Standard_Integer i = 1; i <= nb; i++)
125 {
126 Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
127 if ( ! aPrinter.IsNull() )
128 aPrinter->Send ( theString, theGravity, putEndl );
129 }
130}
131
132//=======================================================================
133//function : Send
134//purpose :
135//=======================================================================
136
137void Message_Messenger::Send (const TCollection_ExtendedString& theString,
138 const Message_Gravity theGravity,
139 const Standard_Boolean putEndl) const
140{
141 Standard_Integer nb = myPrinters.Length();
142 for (Standard_Integer i = 1; i <= nb; i++)
143 {
144 Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
145 if ( ! aPrinter.IsNull() )
146 aPrinter->Send ( theString, theGravity, putEndl );
147 }
148}