1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0031501: Foundation Classes, Message_Printer - remove theToPutEndl argument

The argument putEndl has been removed from Message_Messenger::Send() and Message_Printer::Send() methods.

Message_Printer interface has been changed, so that sub-classes have to implement new method
Message_Printer::send() accepting TCollection_AsciiString.
Old three Message_Printer::Send() methods remain available without putEndl argument
and redirecting to new send() method by default.

Removed dummy Message_PrinterOStream::GetUseUtf8() property.
Message_PrinterOStream, Message_PrinterSystemLog and Draw_Printer
now implement single method Message_Printer::send() instead of triplet.
This commit is contained in:
kgv
2020-04-15 22:44:49 +03:00
committed by bugmaster
parent 0ebe5b0a7f
commit fa8a462827
15 changed files with 156 additions and 344 deletions

View File

@@ -111,15 +111,14 @@ Standard_Integer Message_Messenger::RemovePrinters (const Handle(Standard_Type)&
//=======================================================================
void Message_Messenger::Send (const Standard_CString theString,
const Message_Gravity theGravity,
const Standard_Boolean putEndl) const
const Message_Gravity theGravity) const
{
for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
{
const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
if (!aPrinter.IsNull())
{
aPrinter->Send (theString, theGravity, putEndl);
aPrinter->Send (theString, theGravity);
}
}
}
@@ -130,15 +129,14 @@ void Message_Messenger::Send (const Standard_CString theString,
//=======================================================================
void Message_Messenger::Send (const TCollection_AsciiString& theString,
const Message_Gravity theGravity,
const Standard_Boolean putEndl) const
const Message_Gravity theGravity) const
{
for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
{
const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
if (!aPrinter.IsNull())
{
aPrinter->Send (theString, theGravity, putEndl);
aPrinter->Send (theString, theGravity);
}
}
}
@@ -149,15 +147,14 @@ void Message_Messenger::Send (const TCollection_AsciiString& theString,
//=======================================================================
void Message_Messenger::Send (const TCollection_ExtendedString& theString,
const Message_Gravity theGravity,
const Standard_Boolean putEndl) const
const Message_Gravity theGravity) const
{
for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
{
const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
if (!aPrinter.IsNull())
{
aPrinter->Send (theString, theGravity, putEndl);
aPrinter->Send (theString, theGravity);
}
}
}

View File

@@ -174,22 +174,16 @@ public:
//! Dispatch a message to all the printers in the list.
//! Three versions of string representations are accepted for
//! convenience, by default all are converted to ExtendedString.
//! The parameter putEndl specifies whether the new line should
//! be started after this message (default) or not (may have
//! sense in some conditions).
Standard_EXPORT void Send (const Standard_CString theString,
const Message_Gravity theGravity = Message_Warning,
const Standard_Boolean putEndl = Standard_True) const;
const Message_Gravity theGravity = Message_Warning) const;
//! See above
Standard_EXPORT void Send (const TCollection_AsciiString& theString,
const Message_Gravity theGravity = Message_Warning,
const Standard_Boolean putEndl = Standard_True) const;
const Message_Gravity theGravity = Message_Warning) const;
//! See above
Standard_EXPORT void Send (const TCollection_ExtendedString& theString,
const Message_Gravity theGravity = Message_Warning,
const Standard_Boolean putEndl = Standard_True) const;
const Message_Gravity theGravity = Message_Warning) const;
//! Create string buffer for message of specified type
StreamBuffer Send (Message_Gravity theGravity) { return StreamBuffer (this, theGravity); }

View File

@@ -33,14 +33,12 @@ Message_Printer::Message_Printer()
//function : Send
//purpose :
//=======================================================================
void Message_Printer::Send (const Standard_CString theString,
const Message_Gravity theGravity,
const Standard_Boolean theToOutEol) const
const Message_Gravity theGravity) const
{
if (theGravity >= myTraceLevel)
{
Send (TCollection_ExtendedString (theString, Standard_True), theGravity, theToOutEol);
send (TCollection_AsciiString (theString), theGravity);
}
}
@@ -48,13 +46,24 @@ void Message_Printer::Send (const Standard_CString theString,
//function : Send
//purpose :
//=======================================================================
void Message_Printer::Send (const TCollection_AsciiString& theString,
const Message_Gravity theGravity,
const Standard_Boolean theToOutEol) const
void Message_Printer::Send (const TCollection_ExtendedString& theString,
const Message_Gravity theGravity) const
{
if (theGravity >= myTraceLevel)
{
Send (TCollection_ExtendedString (theString), theGravity, theToOutEol);
send (TCollection_AsciiString (theString), theGravity);
}
}
//=======================================================================
//function : Send
//purpose :
//=======================================================================
void Message_Printer::Send (const TCollection_AsciiString& theString,
const Message_Gravity theGravity) const
{
if (theGravity >= myTraceLevel)
{
send (theString, theGravity);
}
}

View File

@@ -48,25 +48,33 @@ public:
void SetTraceLevel (const Message_Gravity theTraceLevel) { myTraceLevel = theTraceLevel; }
//! Send a string message with specified trace level.
//! The parameter theToPutEol specified whether end-of-line should be added to the end of the message.
//! This method must be redefined in descentant.
Standard_EXPORT virtual void Send (const TCollection_ExtendedString& theString, const Message_Gravity theGravity, const Standard_Boolean theToPutEol) const = 0;
//! The last Boolean argument is deprecated and unused.
//! Default implementation redirects to send().
Standard_EXPORT virtual void Send (const TCollection_ExtendedString& theString,
const Message_Gravity theGravity) const;
//! Send a string message with specified trace level.
//! The parameter theToPutEol specified whether end-of-line should be added to the end of the message.
//! Default implementation calls first method Send().
Standard_EXPORT virtual void Send (const Standard_CString theString, const Message_Gravity theGravity, const Standard_Boolean theToPutEol) const;
//! The last Boolean argument is deprecated and unused.
//! Default implementation redirects to send().
Standard_EXPORT virtual void Send (const Standard_CString theString,
const Message_Gravity theGravity) const;
//! Send a string message with specified trace level.
//! The parameter theToPutEol specified whether end-of-line should be added to the end of the message.
//! Default implementation calls first method Send().
Standard_EXPORT virtual void Send (const TCollection_AsciiString& theString, const Message_Gravity theGravity, const Standard_Boolean theToPutEol) const;
//! The last Boolean argument is deprecated and unused.
//! Default implementation redirects to send().
Standard_EXPORT virtual void Send (const TCollection_AsciiString& theString,
const Message_Gravity theGravity) const;
protected:
//! Empty constructor with Message_Info trace level
Standard_EXPORT Message_Printer();
//! Send a string message with specified trace level.
//! This method must be redefined in descentant.
Standard_EXPORT virtual void send (const TCollection_AsciiString& theString,
const Message_Gravity theGravity) const = 0;
protected:
Message_Gravity myTraceLevel;

View File

@@ -36,7 +36,6 @@ IMPLEMENT_STANDARD_RTTIEXT(Message_PrinterOStream,Message_Printer)
Message_PrinterOStream::Message_PrinterOStream (const Message_Gravity theTraceLevel)
: myStream (&std::cout),
myIsFile (Standard_False),
myUseUtf8 (Standard_False),
myToColorize (Standard_True)
{
myTraceLevel = theTraceLevel;
@@ -52,7 +51,6 @@ Message_PrinterOStream::Message_PrinterOStream (const Standard_CString theFileNa
const Message_Gravity theTraceLevel)
: myStream (&std::cout),
myIsFile (Standard_False),
myUseUtf8 (Standard_False),
myToColorize (Standard_True)
{
myTraceLevel = theTraceLevel;
@@ -112,13 +110,11 @@ void Message_PrinterOStream::Close ()
}
//=======================================================================
//function : Send
//purpose :
//function : send
//purpose :
//=======================================================================
void Message_PrinterOStream::Send (const Standard_CString theString,
const Message_Gravity theGravity,
const Standard_Boolean putEndl) const
void Message_PrinterOStream::send (const TCollection_AsciiString& theString,
const Message_Gravity theGravity) const
{
if (theGravity < myTraceLevel
|| myStream == NULL)
@@ -165,35 +161,7 @@ void Message_PrinterOStream::Send (const Standard_CString theString,
{
*aStream << theString;
}
if (putEndl)
{
(*aStream) << std::endl;
}
}
//=======================================================================
//function : Send
//purpose :
//=======================================================================
void Message_PrinterOStream::Send (const TCollection_AsciiString &theString,
const Message_Gravity theGravity,
const Standard_Boolean putEndl) const
{
Send ( theString.ToCString(), theGravity, putEndl );
}
//=======================================================================
//function : Send
//purpose :
//=======================================================================
void Message_PrinterOStream::Send (const TCollection_ExtendedString &theString,
const Message_Gravity theGravity,
const Standard_Boolean putEndl) const
{
TCollection_AsciiString aStr (theString, myUseUtf8 ? Standard_Character(0) : '?');
Send (aStr.ToCString(), theGravity, putEndl);
(*aStream) << std::endl;
}
//=======================================================================

View File

@@ -65,12 +65,6 @@ public:
Close();
}
//! Returns option to convert non-Ascii symbols to UTF8 encoding
Standard_Boolean GetUseUtf8() const { return myUseUtf8; }
//! Sets option to convert non-Ascii symbols to UTF8 encoding
void SetUseUtf8 (const Standard_Boolean useUtf8) { myUseUtf8 = useUtf8; }
//! Returns reference to the output stream
Standard_OStream& GetStream() const { return *(Standard_OStream*)myStream; }
@@ -80,28 +74,17 @@ public:
//! Set if text output into console should be colorized depending on message gravity.
void SetToColorize (Standard_Boolean theToColorize) { myToColorize = theToColorize; }
protected:
//! Puts a message to the current stream
//! if its gravity is equal or greater
//! to the trace level set by SetTraceLevel()
Standard_EXPORT virtual void Send (const Standard_CString theString, const Message_Gravity theGravity, const Standard_Boolean putEndl = Standard_True) const Standard_OVERRIDE;
//! Puts a message to the current stream
//! if its gravity is equal or greater
//! to the trace level set by SetTraceLevel()
Standard_EXPORT virtual void Send (const TCollection_AsciiString& theString, const Message_Gravity theGravity, const Standard_Boolean putEndl = Standard_True) const Standard_OVERRIDE;
//! Puts a message to the current stream
//! if its gravity is equal or greater
//! to the trace level set by SetTraceLevel()
//! Non-Ascii symbols are converted to UTF-8 if UseUtf8
//! option is set, else replaced by symbols '?'
Standard_EXPORT virtual void Send (const TCollection_ExtendedString& theString, const Message_Gravity theGravity, const Standard_Boolean putEndl = Standard_True) const Standard_OVERRIDE;
Standard_EXPORT virtual void send (const TCollection_AsciiString& theString, const Message_Gravity theGravity) const Standard_OVERRIDE;
private:
Standard_Address myStream;
Standard_Boolean myIsFile;
Standard_Boolean myUseUtf8;
Standard_Boolean myToColorize;
};

View File

@@ -149,12 +149,11 @@ Message_PrinterSystemLog::~Message_PrinterSystemLog()
}
//=======================================================================
//function : Send
//function : send
//purpose :
//=======================================================================
void Message_PrinterSystemLog::Send (const Standard_CString theString,
const Message_Gravity theGravity,
const Standard_Boolean ) const
void Message_PrinterSystemLog::send (const TCollection_AsciiString& theString,
const Message_Gravity theGravity) const
{
if (theGravity < myTraceLevel)
{
@@ -162,38 +161,18 @@ void Message_PrinterSystemLog::Send (const Standard_CString theString,
}
#if defined(_WIN32)
Send (TCollection_ExtendedString (theString), theGravity, true);
#elif defined(__ANDROID__)
__android_log_write (getAndroidLogPriority (theGravity), myEventSourceName.ToCString(), theString);
#elif defined(__EMSCRIPTEN__)
if (theGravity == Message_Trace)
if (myEventSource != NULL)
{
debugMsgToConsole (theString);
#if !defined(OCCT_UWP)
const TCollection_ExtendedString aWideString (theString);
const WORD aLogType = getEventLogPriority (theGravity);
const wchar_t* aMessage[1] = { aWideString.ToWideString() };
ReportEventW ((HANDLE )myEventSource, aLogType, 0, 0, NULL,
1, 0, aMessage, NULL);
#else
(void )theString;
#endif
}
else
{
emscripten_log (getEmscriptenPriority (theGravity), "%s", theString);
}
#else
syslog (getSysLogPriority (theGravity), "%s", theString);
#endif
}
//=======================================================================
//function : Send
//purpose :
//=======================================================================
void Message_PrinterSystemLog::Send (const TCollection_AsciiString& theString,
const Message_Gravity theGravity,
const Standard_Boolean ) const
{
if (theGravity < myTraceLevel)
{
return;
}
#if defined(_WIN32)
Send (TCollection_ExtendedString (theString), theGravity, true);
#elif defined(__ANDROID__)
__android_log_write (getAndroidLogPriority (theGravity), myEventSourceName.ToCString(), theString.ToCString());
#elif defined(__EMSCRIPTEN__)
@@ -209,33 +188,3 @@ void Message_PrinterSystemLog::Send (const TCollection_AsciiString& theString,
syslog (getSysLogPriority (theGravity), "%s", theString.ToCString());
#endif
}
//=======================================================================
//function : Send
//purpose :
//=======================================================================
void Message_PrinterSystemLog::Send (const TCollection_ExtendedString& theString,
const Message_Gravity theGravity,
const Standard_Boolean ) const
{
if (theGravity < myTraceLevel)
{
return;
}
#if defined(_WIN32)
if (myEventSource != NULL)
{
#if !defined(OCCT_UWP)
const WORD aLogType = getEventLogPriority (theGravity);
const wchar_t* aMessage[1] = { theString.ToWideString() };
ReportEventW ((HANDLE )myEventSource, aLogType, 0, 0, NULL,
1, 0, aMessage, NULL);
#else
(void )theString;
#endif
}
#else
Send (TCollection_AsciiString (theString), theGravity, true);
#endif
}

View File

@@ -36,20 +36,11 @@ public:
//! Destructor.
Standard_EXPORT virtual ~Message_PrinterSystemLog();
protected:
//! Puts a message to the system log.
Standard_EXPORT virtual void Send (const Standard_CString theString,
const Message_Gravity theGravity,
const Standard_Boolean theToPutEndl) const Standard_OVERRIDE;
//! Puts a message to the system log.
Standard_EXPORT virtual void Send (const TCollection_AsciiString& theString,
const Message_Gravity theGravity,
const Standard_Boolean theToPutEndl) const Standard_OVERRIDE;
//! Puts a message to the system log.
Standard_EXPORT virtual void Send (const TCollection_ExtendedString& theString,
const Message_Gravity theGravity,
const Standard_Boolean theToPutEndl) const Standard_OVERRIDE;
Standard_EXPORT virtual void send (const TCollection_AsciiString& theString,
const Message_Gravity theGravity) const Standard_OVERRIDE;
private: