0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / Message / Message_Messenger.cxx
CommitLineData
b311480e 1// Created on: 2001-01-06
2// Created by: OCC Team
3// Copyright (c) 2001-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21#include <Message_Messenger.ixx>
22#include <Message_PrinterOStream.hxx>
23
24//=======================================================================
25//function : Message_Messenger
26//purpose :
27//=======================================================================
28
29Message_Messenger::Message_Messenger ()
30{
31 AddPrinter ( new Message_PrinterOStream );
32}
33
34//=======================================================================
35//function : Message_Messenger
36//purpose :
37//=======================================================================
38
39Message_Messenger::Message_Messenger (const Handle(Message_Printer)& thePrinter)
40{
41 AddPrinter (thePrinter);
42}
43
44//=======================================================================
45//function : AddPrinter
46//purpose :
47//=======================================================================
48
49Standard_Boolean Message_Messenger::AddPrinter (const Handle(Message_Printer)& thePrinter)
50{
51 // check whether printer is already in the list
52 for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
53 if ( myPrinters(i) == thePrinter )
54 return Standard_False;
55 // add to the list
56 myPrinters.Append (thePrinter);
57 return Standard_True;
58}
59
60//=======================================================================
61//function : RemovePrinter
62//purpose :
63//=======================================================================
64
65Standard_Boolean Message_Messenger::RemovePrinter (const Handle(Message_Printer)& thePrinter)
66{
67 // find printer in the list
68 for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
69 if ( myPrinters(i) == thePrinter )
70 {
71 myPrinters.Remove (i);
72 return Standard_True;
73 }
74 return Standard_False;
75}
76
77//=======================================================================
78//function : RemovePrinters
79//purpose :
80//=======================================================================
81
82Standard_Integer Message_Messenger::RemovePrinters (const Handle(Standard_Type)& theType)
83{
84 // remove printers from the list
85 Standard_Integer nb = 0;
86 for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
87 if ( myPrinters(i)->IsKind(theType) )
88 {
89 myPrinters.Remove (i--);
90 nb++;
91 }
92 return nb;
93}
94
95//=======================================================================
96//function : Send
97//purpose :
98//=======================================================================
99
100void Message_Messenger::Send (const Standard_CString theString,
101 const Message_Gravity theGravity,
102 const Standard_Boolean putEndl) const
103{
104 Standard_Integer nb = myPrinters.Length();
105 for (Standard_Integer i = 1; i <= nb; i++)
106 {
107 Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
108 if ( ! aPrinter.IsNull() )
109 aPrinter->Send ( theString, theGravity, putEndl );
110 }
111}
112
113//=======================================================================
114//function : Send
115//purpose :
116//=======================================================================
117
118void Message_Messenger::Send (const TCollection_AsciiString& theString,
119 const Message_Gravity theGravity,
120 const Standard_Boolean putEndl) const
121{
122 Standard_Integer nb = myPrinters.Length();
123 for (Standard_Integer i = 1; i <= nb; i++)
124 {
125 Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
126 if ( ! aPrinter.IsNull() )
127 aPrinter->Send ( theString, theGravity, putEndl );
128 }
129}
130
131//=======================================================================
132//function : Send
133//purpose :
134//=======================================================================
135
136void Message_Messenger::Send (const TCollection_ExtendedString& theString,
137 const Message_Gravity theGravity,
138 const Standard_Boolean putEndl) const
139{
140 Standard_Integer nb = myPrinters.Length();
141 for (Standard_Integer i = 1; i <= nb; i++)
142 {
143 Handle(Message_Printer) aPrinter = Handle(Message_Printer)::DownCast ( myPrinters(i) );
144 if ( ! aPrinter.IsNull() )
145 aPrinter->Send ( theString, theGravity, putEndl );
146 }
147}