From 854b7cc6f65450da968723def6fc114e8dbfc771 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 6 Nov 2020 18:40:22 +0300 Subject: [PATCH] 0031945: Foundation Classes - unique names of alerts of message report in DumpJson --- src/Message/Message_CompositeAlerts.cxx | 5 +---- src/Message/Message_Report.cxx | 3 ++- src/Standard/Standard_Dump.cxx | 4 ++++ src/Standard/Standard_Dump.hxx | 9 +++++++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Message/Message_CompositeAlerts.cxx b/src/Message/Message_CompositeAlerts.cxx index 5d315f3e8c..c9daf6dc44 100644 --- a/src/Message/Message_CompositeAlerts.cxx +++ b/src/Message/Message_CompositeAlerts.cxx @@ -164,15 +164,12 @@ void Message_CompositeAlerts::DumpJson (Standard_OStream& theOStream, { OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) + Standard_Integer anInc = 1; for (unsigned int i = 0; i < sizeof(myAlerts)/sizeof(myAlerts[0]); ++i) { if (myAlerts[i].IsEmpty()) continue; - Message_Gravity aGravity = (Message_Gravity)i; - OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aGravity) - - Standard_Integer anInc = 1; for (Message_ListOfAlert::Iterator anIt (myAlerts[i]); anIt.More(); anIt.Next(), anInc++) { const Handle(Message_Alert)& anAlert = anIt.Value(); diff --git a/src/Message/Message_Report.cxx b/src/Message/Message_Report.cxx index 70de6b011a..41c64accfa 100644 --- a/src/Message/Message_Report.cxx +++ b/src/Message/Message_Report.cxx @@ -488,10 +488,11 @@ void Message_Report::DumpJson (Standard_OStream& theOStream, Standard_Integer th Standard_Integer anAlertLevels = myAlertLevels.Size(); OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, anAlertLevels) + Standard_Integer anInc = 1; for (NCollection_Map::Iterator anIterator (myActiveMetrics); anIterator.More(); anIterator.Next()) { Message_MetricType anActiveMetric = anIterator.Value(); - OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, anActiveMetric) + OCCT_DUMP_FIELD_VALUE_NUMERICAL_INC (theOStream, anActiveMetric, anInc++) } OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myLimit) diff --git a/src/Standard/Standard_Dump.cxx b/src/Standard/Standard_Dump.cxx index a56292f912..4d594bf61e 100644 --- a/src/Standard/Standard_Dump.cxx +++ b/src/Standard/Standard_Dump.cxx @@ -358,6 +358,10 @@ TCollection_AsciiString Standard_Dump::FormatJson (const Standard_SStream& theSt else aText += aSymbol; } + else if (aSymbol == '\n') + { + aText += ""; // json does not support multi-lined values, skip this symbol + } else aText += aSymbol; diff --git a/src/Standard/Standard_Dump.hxx b/src/Standard/Standard_Dump.hxx index e0333c03e4..d3afcac4d8 100644 --- a/src/Standard/Standard_Dump.hxx +++ b/src/Standard/Standard_Dump.hxx @@ -77,6 +77,15 @@ theOStream << "\"" << aName << "\": " << theField; \ } +//! @def OCCT_DUMP_FIELD_VALUE_NUMERICAL +//! Append into output value: "Name": Field +#define OCCT_DUMP_FIELD_VALUE_NUMERICAL_INC(theOStream, theField, theIncName) \ +{ \ + TCollection_AsciiString aName = Standard_Dump::DumpFieldToName (#theField) + theIncName; \ + Standard_Dump::AddValuesSeparator (theOStream); \ + theOStream << "\"" << aName << "\": " << theField; \ +} + //! @def OCCT_INIT_FIELD_VALUE_REAL //! Append vector values into output value: "Name": [value_1, value_2, ...] //! This macro is intended to have only one row for dumped object in Json. -- 2.39.5