1 // Copyright (c) 2020 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _Message_AttributeMeter_HeaderFile
15 #define _Message_AttributeMeter_HeaderFile
17 #include <Message_Attribute.hxx>
18 #include <Message_MetricType.hxx>
20 #include <NCollection_IndexedDataMap.hxx>
22 class Message_AlertExtended;
24 //! Alert object storing alert metrics values.
25 //! Start and stop values for each metric.
26 class Message_AttributeMeter : public Message_Attribute
30 //! Returns default value of the metric when it is not defined
31 //! @return undefined value
32 static Standard_Real UndefinedMetricValue() { return -1.0; }
36 //! Constructor with string argument
37 Standard_EXPORT Message_AttributeMeter (const TCollection_AsciiString& theName = TCollection_AsciiString());
39 //! Checks whether the attribute has values for the metric
40 //! @param theMetric [in] metric type
41 //! @return true if the metric values exist in the attribute
42 Standard_EXPORT Standard_Boolean HasMetric (const Message_MetricType& theMetric) const;
44 //! Returns true when both values of the metric are set.
45 //! @param theMetric [in] metric type
46 //! @return true if metric values are valid
47 Standard_EXPORT Standard_Boolean IsMetricValid (const Message_MetricType& theMetric) const;
49 //! Returns start value for the metric
50 //! @param theMetric [in] metric type
51 //! @return real value
52 Standard_EXPORT Standard_Real StartValue (const Message_MetricType& theMetric) const;
54 //! Sets start values for the metric
55 //! @param theMetric [in] metric type
56 Standard_EXPORT void SetStartValue (const Message_MetricType& theMetric, const Standard_Real theValue);
58 //! Returns stop value for the metric
59 //! @param theMetric [in] metric type
60 //! @return real value
61 Standard_EXPORT Standard_Real StopValue (const Message_MetricType& theMetric) const;
63 //! Sets stop values for the metric
64 //! @param theMetric [in] metric type
65 Standard_EXPORT void SetStopValue (const Message_MetricType& theMetric, const Standard_Real theValue);
69 //! Sets start values of default report metrics into the alert
70 //! @param theAlert an alert
71 static void StartAlert (const Handle(Message_AlertExtended)& theAlert) { SetAlertMetrics (theAlert, Standard_True); }
73 //! Sets stop values of default report metrics into the alert
74 //! @param theAlert an alert
75 static void StopAlert (const Handle(Message_AlertExtended)& theAlert) { SetAlertMetrics (theAlert, Standard_False); }
77 //! Sets current values of default report metrics into the alert.
78 //! Processed only alert with Message_AttributeMeter attribute
79 //! @param theAlert an alert
80 //! @param theStartValue flag, if true, the start value is collected otherwise stop
81 static Standard_EXPORT void SetAlertMetrics (const Handle(Message_AlertExtended)& theAlert,
82 const Standard_Boolean theStartValue);
84 //! Dumps the content of me into the stream
85 virtual Standard_EXPORT void DumpJson (Standard_OStream& theOStream,
86 Standard_Integer theDepth = -1) const Standard_OVERRIDE;
88 DEFINE_STANDARD_RTTIEXT(Message_AttributeMeter, Message_Attribute)
92 typedef std::pair<Standard_Real, Standard_Real> StartToStopValue;
93 NCollection_IndexedDataMap<Message_MetricType, StartToStopValue> myMetrics; //!< computed metrics
96 #endif // _Message_AttributeMeter_HeaderFile