]> OCCT Git - occt.git/commitdiff
0031945: Foundation Classes - unique names of alerts of message report in DumpJson IR-2020-12-18
authornds <nds@opencascade.com>
Fri, 18 Dec 2020 10:09:08 +0000 (13:09 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 18 Dec 2020 16:48:03 +0000 (19:48 +0300)
- add OCCT_DUMP_FIELD_VALUE_NUMERICAL_INC and OCCT_DUMP_FIELD_VALUES_DUMPED_INC - to increment key Value;
- add OCCT_DUMP_STREAM_VALUE_DUMPED - to give stream as a parameter of the DumpJson;
- correct Message_Report, Message_CompositeAlerts to increment keys;
- correct Message_AttributeMeter to have in result start and stop values united in value block: [start stop]. It's better for parsing;
- correct result of Message::MetricToString output for updated in 29451 Message_MetricType enum;
- correct Standard_Dump::AddValuesSeparator to avoid adding ',' in additional case;
- correct Standard_Dump::FormatJson to add opening/closing brace for the whole result (for valid parsing);
- correct Standard_Dump::FormatJson to ignore '\n' in value.

src/Message/Message.cxx
src/Message/Message_AttributeMeter.cxx
src/Message/Message_AttributeStream.cxx
src/Message/Message_CompositeAlerts.cxx
src/Message/Message_Report.cxx
src/Standard/Standard_Dump.cxx
src/Standard/Standard_Dump.hxx

index 0a4de987519e43143f133ef0f486b5331528d2ad..cdc7dc65207ab4c20f3f1a3ff285c0fb8434ba63 100644 (file)
 
 namespace
 {
-  static Standard_CString Message_Table_PrintMetricTypeEnum[11] =
+  static Standard_CString Message_Table_PrintMetricTypeEnum[13] =
   {
-    "NONE", "UserTimeCPU", "SystemTimeInfo", "WallClock", "MemPrivate", "MemVirtual",
+    "NONE", "ThreadCPUUserTime", "ThreadCPUSystemTime", "ProcessCPUUserTime", "ProcessCPUSystemTime",
+    "WallClock", "MemPrivate", "MemVirtual",
     "MemWorkingSet", "MemWorkingSetPeak", "MemSwapUsage", "MemSwapUsagePeak", "MemHeapUsage"
   };
 }
index 0fe5042dc25402354d2d2d0e7a33973dcbb30952..531c0f0e9cc2403b0686fdfe8e757e83657abcac 100644 (file)
@@ -255,13 +255,7 @@ void Message_AttributeMeter::DumpJson (Standard_OStream& theOStream,
   for (NCollection_IndexedDataMap<Message_MetricType, StartToStopValue>::Iterator anIterator (myMetrics);
        anIterator.More(); anIterator.Next())
   {
-    Message_MetricType aMetricType = anIterator.Key();
-    OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aMetricType)
-
-    Standard_Real aStartValue = anIterator.Value().first;
-    OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aStartValue)
-
-    Standard_Real aStopValue = anIterator.Value().second;
-    OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aStopValue)
+    OCCT_DUMP_VECTOR_CLASS (theOStream, Message::MetricToString (anIterator.Key()),
+                            2, anIterator.Value().first, anIterator.Value().second)
   }
 }
index ba0ff7e8a0e6f33b8f8dbe6f14ea2473f96d0bbd..357439558412d356de78fce90f9c983bf1bc5fc8 100644 (file)
@@ -47,6 +47,5 @@ void Message_AttributeStream::DumpJson (Standard_OStream& theOStream,
   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
   OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Message_Attribute)
 
-  TCollection_AsciiString aStream = Standard_Dump::Text (myStream);
-  OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aStream)
+  OCCT_DUMP_STREAM_VALUE_DUMPED (theOStream, myStream)
 }
index 312b0596346012ebd4de667300f2257461eaf344..5c1a267ea354f66beb8410ef55ddae2c8b5ccdcb 100644 (file)
@@ -169,15 +169,16 @@ 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)
   {
-    Message_Gravity aGravity = (Message_Gravity)i;
-    OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aGravity)
+    if (myAlerts[i].IsEmpty())
+      continue;
 
-    for (Message_ListOfAlert::Iterator anIt (myAlerts[i]); anIt.More(); anIt.Next())
+    for (Message_ListOfAlert::Iterator anIt (myAlerts[i]); anIt.More(); anIt.Next(), anInc++)
     {
       const Handle(Message_Alert)& anAlert = anIt.Value();
-      OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, anAlert.get())
+      OCCT_DUMP_FIELD_VALUES_DUMPED_INC (theOStream, theDepth, anAlert.get(), anInc)
     }
   }
 }
index d8ed266198c721090fdc82d5ca5bf3c79d7bc36a..2b038c1726c3fe9d741c9b83fa1348ca7117ae54 100644 (file)
@@ -489,10 +489,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_IndexedMap<Message_MetricType>::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)
index 49e0d16c3bab15ae648921b43e48e2206649c0af..355db4647add205fdabf858c1b145b06c3790a8d 100644 (file)
@@ -24,7 +24,7 @@ void Standard_Dump::AddValuesSeparator (Standard_OStream& theOStream)
   Standard_SStream aStream;
   aStream << theOStream.rdbuf();
   TCollection_AsciiString aStreamStr = Standard_Dump::Text (aStream);
-  if (!aStreamStr.IsEmpty() && !aStreamStr.EndsWith ("{"))
+  if (!aStreamStr.IsEmpty() && !aStreamStr.EndsWith ("{") && !aStreamStr.EndsWith (", "))
     theOStream << ", ";
 }
 
@@ -302,9 +302,15 @@ TCollection_AsciiString Standard_Dump::FormatJson (const Standard_SStream& theSt
 
   Standard_Integer anIndentCount = 0;
   Standard_Boolean isMassiveValues = Standard_False;
-  for (Standard_Integer anIndex = 1; anIndex < aStreamStr.Length(); anIndex++)
+  for (Standard_Integer anIndex = 1; anIndex <= aStreamStr.Length(); anIndex++)
   {
     Standard_Character aSymbol = aStreamStr.Value (anIndex);
+    if (anIndex == 1 && aText.IsEmpty() && aSymbol != '{')
+    {
+      // append opening brace for json start
+      aSymbol = '{';
+      anIndex--;
+    }
     if (aSymbol == '{')
     {
       anIndentCount++;
@@ -313,7 +319,9 @@ TCollection_AsciiString Standard_Dump::FormatJson (const Standard_SStream& theSt
       aText += '\n';
 
       for (int anIndent = 0; anIndent < anIndentCount; anIndent++)
+      {
         aText += anIndentStr;
+      }
     }
     else if (aSymbol == '}')
     {
@@ -348,8 +356,24 @@ 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;
+  
+    if (anIndex == aStreamStr.Length() && aSymbol != '}')
+    {
+      // append closing brace for json end
+      aSymbol = '}';
+
+      anIndentCount--;
+      aText += '\n';
+      for (int anIndent = 0; anIndent < anIndentCount; anIndent++)
+        aText += anIndentStr;
+      aText += aSymbol;
+    }
   }
   return aText;
 }
index d2b294c7d1266325716258145c8f9c755dcac6da..a6935be7fec8f9fd222e6b964ab33dda509ba8bc 100644 (file)
 //! uses the variable name to generate key. If the parameter has prefix symbols "&", "*" and "my", it is cut.
 //!
 //! - OCCT_DUMP_FIELD_VALUE_NUMERICAL. Use it for fields of numerical C++ types, like int, float, double. It creates a pair "key", "value",
+//! - OCCT_DUMP_FIELD_VALUE_NUMERICAL_INC. Use it for fields of numerical C++ types, like int, float, double.
+//!     It creates a pair "key_inc", "value",
 //! - OCCT_DUMP_FIELD_VALUE_STRING. Use it for char* type. It creates a pair "key", "value",
 //! - OCCT_DUMP_FIELD_VALUE_POINTER. Use it for pointer fields. It creates a pair "key", "value", where the value is the pointer address,
 //! - OCCT_DUMP_FIELD_VALUES_DUMPED. Use it for fields that has own Dump implementation. It expects the pointer to the class instance.
 //!     It creates "key": { result of dump of the field }
+//! - OCCT_DUMP_FIELD_VALUES_DUMPED_INC. Use it for fields that has own Dump implementation. It expects the pointer to the class instance.
+//!     It creates "key_inc": { result of dump of the field }
+//! - OCCT_DUMP_STREAM_VALUE_DUMPED. Use it for Standard_SStream. It creates "key": { text of stream }
 //! - OCCT_DUMP_FIELD_VALUES_NUMERICAL. Use it for unlimited list of fields of C++ double type.
 //!     It creates massive of values [value_1, value_2, ...]
 //! - OCCT_DUMP_FIELD_VALUES_STRING. Use it for unlimited list of fields of TCollection_AsciiString types.
   theOStream << "\"" << aName << "\": " << theField; \
 }
 
+//! @def OCCT_DUMP_FIELD_VALUE_NUMERICAL
+//! Append into output value: "Name": Field
+//! Inc name value added to the key to provide unique keys
+#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.
   } \
 }
 
+//! @def OCCT_DUMP_FIELD_VALUES_DUMPED_INC
+//! Append into output value: "Name": { field dumped values }
+//! It computes Dump of the fields. The expected field is a pointer.
+//! Use this macro for fields of the dumped class which has own Dump implementation.
+//! The macros is recursive. Recursion is stopped when the depth value becomes equal to zero.
+//! Depth = -1 is the default value, dump here is unlimited.
+//! Inc name value added to the key to provide unique keys
+#define OCCT_DUMP_FIELD_VALUES_DUMPED_INC(theOStream, theDepth, theField, theIncName) \
+{ \
+  if (theDepth != 0 && (void*)(theField) != NULL) \
+  { \
+    Standard_SStream aFieldStream; \
+    (theField)->DumpJson (aFieldStream, theDepth - 1); \
+    TCollection_AsciiString aName = Standard_Dump::DumpFieldToName (#theField) + theIncName; \
+    Standard_Dump::DumpKeyToClass (theOStream, aName, Standard_Dump::Text (aFieldStream)); \
+  } \
+}
+
 //! @def OCCT_INIT_FIELD_VALUES_DUMPED
 //! Append into output value: "Name": { field dumped values }
 //! It computes Dump of the fields. The expected field is a pointer.
     return Standard_False; \
 }
 
+//! @def OCCT_DUMP_STREAM_VALUE_DUMPED
+//! Append into output value: "Name": { stream text }
+//! It computes Dump of the fields. The expected field is a pointer.
+//! Use this macro for Standard_SStream field.
+#define OCCT_DUMP_STREAM_VALUE_DUMPED(theOStream, theField) \
+{ \
+  TCollection_AsciiString aName = Standard_Dump::DumpFieldToName (#theField); \
+  Standard_Dump::DumpKeyToClass (theOStream, aName, Standard_Dump::Text (theField)); \
+}
+
 //! @def OCCT_DUMP_FIELD_VALUES_NUMERICAL
 //! Append real values into output values in an order: [value_1, value_2, ...]
 //! It computes Dump of the parent. The expected field is a parent class name to call ClassName::Dump.
@@ -267,6 +310,7 @@ public:
   //! - for '{' append after '\n' and indent to the next value, increment current indent value
   //! - for '}' append '\n' and current indent before it, decrement indent value
   //! - for ',' append after '\n' and indent to the next value. If the current symbol is in massive container [], do nothing
+  //! Covers result with opened and closed brackets on the top level, if it has no symbols there.
   //! @param theStream source value
   //! @param theIndent count of ' ' symbols to apply hierarchical indent of the text values
   //! @return text presentation