File indexing completed on 2025-01-18 10:04:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef _Message_Messenger_HeaderFile
0017 #define _Message_Messenger_HeaderFile
0018
0019 #include <Message_SequenceOfPrinters.hxx>
0020
0021 #include <TCollection_HAsciiString.hxx>
0022 #include <TCollection_HExtendedString.hxx>
0023
0024 class Message_Printer;
0025
0026
0027 #ifdef AddPrinter
0028 #undef AddPrinter
0029 #endif
0030
0031 class Message_Messenger;
0032 DEFINE_STANDARD_HANDLE(Message_Messenger, Standard_Transient)
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 class Message_Messenger : public Standard_Transient
0054 {
0055 DEFINE_STANDARD_RTTIEXT(Message_Messenger, Standard_Transient)
0056 public:
0057
0058
0059
0060
0061
0062
0063 class StreamBuffer
0064 {
0065 public:
0066
0067
0068 ~StreamBuffer() { Flush(); }
0069
0070
0071 void Flush(Standard_Boolean doForce = Standard_False)
0072 {
0073 myStream.flush();
0074 if (doForce || myStream.tellp() != std::streampos(0))
0075 {
0076 if (myMessenger)
0077 {
0078 myMessenger->Send(myStream, myGravity);
0079 }
0080 myStream.str(std::string());
0081 }
0082 }
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094 StreamBuffer (const StreamBuffer& theOther)
0095 : myMessenger(theOther.myMessenger), myGravity(theOther.myGravity)
0096 {
0097 }
0098
0099
0100 template <typename T>
0101 StreamBuffer& operator << (const T& theArg)
0102 {
0103 myStream << theArg;
0104 return *this;
0105 }
0106
0107
0108
0109 StreamBuffer& operator << (std::ostream& (*)(std::ostream&))
0110 {
0111 Flush(Standard_True);
0112 return *this;
0113 }
0114
0115
0116 Standard_SStream& Stream () { return myStream; }
0117
0118
0119 operator Standard_OStream& () { return myStream; }
0120
0121
0122 Message_Messenger* Messenger () { return myMessenger; }
0123
0124 private:
0125 friend class Message_Messenger;
0126
0127
0128
0129 StreamBuffer (Message_Messenger* theMessenger, Message_Gravity theGravity)
0130 : myMessenger (theMessenger),
0131 myGravity (theGravity)
0132 {}
0133
0134 private:
0135 Message_Messenger* myMessenger;
0136 Message_Gravity myGravity;
0137 Standard_SStream myStream;
0138 };
0139
0140 public:
0141
0142
0143
0144
0145
0146 Standard_EXPORT Message_Messenger();
0147
0148
0149 Standard_EXPORT Message_Messenger(const Handle(Message_Printer)& thePrinter);
0150
0151
0152
0153
0154 Standard_EXPORT Standard_Boolean AddPrinter (const Handle(Message_Printer)& thePrinter);
0155
0156
0157
0158
0159 Standard_EXPORT Standard_Boolean RemovePrinter (const Handle(Message_Printer)& thePrinter);
0160
0161
0162
0163
0164 Standard_EXPORT Standard_Integer RemovePrinters (const Handle(Standard_Type)& theType);
0165
0166
0167 const Message_SequenceOfPrinters& Printers() const { return myPrinters; }
0168
0169
0170
0171 Message_SequenceOfPrinters& ChangePrinters() { return myPrinters; }
0172
0173
0174
0175
0176 Standard_EXPORT void Send (const Standard_CString theString,
0177 const Message_Gravity theGravity = Message_Warning) const;
0178
0179
0180 Standard_EXPORT void Send (const Standard_SStream& theStream,
0181 const Message_Gravity theGravity = Message_Warning) const;
0182
0183
0184 Standard_EXPORT void Send (const TCollection_AsciiString& theString,
0185 const Message_Gravity theGravity = Message_Warning) const;
0186
0187
0188 Standard_EXPORT void Send (const TCollection_ExtendedString& theString,
0189 const Message_Gravity theGravity = Message_Warning) const;
0190
0191
0192 StreamBuffer Send (Message_Gravity theGravity) { return StreamBuffer (this, theGravity); }
0193
0194
0195 Standard_EXPORT void Send (const Handle(Standard_Transient)& theObject, const Message_Gravity theGravity = Message_Warning) const;
0196
0197
0198 StreamBuffer SendFail () { return Send (Message_Fail); }
0199
0200
0201 StreamBuffer SendAlarm () { return Send (Message_Alarm); }
0202
0203
0204 StreamBuffer SendWarning () { return Send (Message_Warning); }
0205
0206
0207 StreamBuffer SendInfo () { return Send (Message_Info); }
0208
0209
0210 StreamBuffer SendTrace () { return Send (Message_Trace); }
0211
0212
0213 void SendFail (const TCollection_AsciiString& theMessage) { Send (theMessage, Message_Fail); }
0214
0215
0216 void SendAlarm (const TCollection_AsciiString& theMessage) { Send (theMessage, Message_Alarm); }
0217
0218
0219 void SendWarning (const TCollection_AsciiString& theMessage) { Send (theMessage, Message_Warning); }
0220
0221
0222 void SendInfo (const TCollection_AsciiString& theMessage) { Send (theMessage, Message_Info); }
0223
0224
0225 void SendTrace (const TCollection_AsciiString& theMessage) { Send (theMessage, Message_Trace); }
0226
0227
0228 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0229
0230 private:
0231
0232 Message_SequenceOfPrinters myPrinters;
0233
0234 };
0235
0236 #endif