BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlm_metric.h
Go to the documentation of this file.
1/// @file bdlm_metric.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlm_metric.h -*-C++-*-
8#ifndef INCLUDED_BDLM_METRIC
9#define INCLUDED_BDLM_METRIC
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id$")
13
14/// @defgroup bdlm_metric bdlm_metric
15/// @brief Provide a class to store metric values of different types.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlm
19/// @{
20/// @addtogroup bdlm_metric
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlm_metric-purpose"> Purpose</a>
25/// * <a href="#bdlm_metric-classes"> Classes </a>
26/// * <a href="#bdlm_metric-description"> Description </a>
27/// * <a href="#bdlm_metric-usage"> Usage </a>
28///
29/// # Purpose {#bdlm_metric-purpose}
30/// Provide a class to store metric values of different types.
31///
32/// # Classes {#bdlm_metric-classes}
33///
34/// - bdlm::Metric: variant of metric values
35///
36/// # Description {#bdlm_metric-description}
37/// This component defines a value semantic class, `bdlmt::Metric`,
38/// that represents a measurement (or measurements) for a metric.
39/// A `bdlm::Metric` value is collected from an object that reports metrics
40/// using a callback that is registered with the `bdlm::MetricsRegistry`. A
41/// `bdlm::Metric` value is a variant type, which can hold one of several types
42/// of measurements (in theory). Currently the only supported metric type is a
43/// `Guage`, which represents a single instantaneous value for the most recent
44/// measurement.
45///
46/// ## Usage {#bdlm_metric-usage}
47///
48///
49/// The intended use of this component is illustrated in
50/// {@ref bdlm_metricsregistrar |Usage}.
51/// @}
52/** @} */
53/** @} */
54
55/** @addtogroup bdl
56 * @{
57 */
58/** @addtogroup bdlm
59 * @{
60 */
61/** @addtogroup bdlm_metric
62 * @{
63 */
64
65#include <bdlb_variant.h>
66
67#include <bsls_assert.h>
68
69
70namespace bdlm {
71
72/// This class provides storage for various types of metric values.
73///
74/// See @ref bdlm_metric
75class Metric {
76
77 public:
78 // PUBLIC TYPES
79 typedef double Gauge;
80
81 private:
82 // DATA
83 bdlb::Variant<Gauge> d_value; // value of the metric
84
85 // FRIENDS
86 friend bool operator==(const Metric& lhs, const Metric& rhs);
87 friend bool operator!=(const Metric& lhs, const Metric& rhs);
88
89 public:
90 // CREATORS
91
92 /// Create a default (empty) metric.
93 Metric();
94
95 /// Create a metric with the specified `value`.
96 explicit Metric(const Gauge& value);
97
98 ~Metric() = default;
99 // Destroy this 'Metric' object.
100
101 // MANIPULATORS
102
103 /// Assign to this metric the specified `value`.
104 Metric& operator=(const Gauge& value);
105
106 // ACCESSORS
107
108 /// Return `true` if the value of this metric is of gauge type, and
109 /// `false` otherwise.
110 bool isGauge() const;
111
112 /// Return a `const` reference to the value of this metric of gauge type.
113 ///
114 /// \pre The behavior is undefined unless `true == isGuage()`.
115 const Gauge& theGauge() const;
116};
117
118// FREE OPERATORS
119
120/// Return `true` if the specified `lhs` and `rhs` have the same value, and
121/// `false` otherwise. Two `Metric` objects have the same value if their
122/// types are the same and they have the same value.
123bool operator==(const Metric& lhs, const Metric& rhs);
124
125/// Return `true` if the specified `lhs` command-line metric has a different
126/// value from the specified `rhs` command-line metric, and `false`
127/// otherwise. Two `Metric` objects do not have the same value if their
128/// types are not the same or they have different values.
129bool operator!=(const Metric& lhs, const Metric& rhs);
130
131// ============================================================================
132// INLINE DEFINITIONS
133// ============================================================================
134
135 // ------------
136 // class Metric
137 // ------------
138
139// CREATORS
140inline
142: d_value()
143{
144}
145
146inline
148: d_value(value)
149{
150}
151
152// MANIPULATORS
153inline
155{
156 d_value = value;
157 return *this;
158}
159
160// ACCESSORS
161inline
162bool Metric::isGauge() const
163{
164 return d_value.is<Gauge>();
165}
166
167inline
169{
171
172 return d_value.the<Gauge>();
173}
174
175// FREE OPERATORS
176inline
177bool operator==(const Metric& lhs, const Metric& rhs)
178{
179 return lhs.d_value == rhs.d_value;
180}
181
182inline
183bool operator!=(const Metric& lhs, const Metric& rhs)
184{
185 return lhs.d_value != rhs.d_value;
186}
187
188} // close package namespace
189
190
191#endif
192
193// ----------------------------------------------------------------------------
194// Copyright 2024 Bloomberg Finance L.P.
195//
196// Licensed under the Apache License, Version 2.0 (the "License");
197// you may not use this file except in compliance with the License.
198// You may obtain a copy of the License at
199//
200// http://www.apache.org/licenses/LICENSE-2.0
201//
202// Unless required by applicable law or agreed to in writing, software
203// distributed under the License is distributed on an "AS IS" BASIS,
204// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
205// See the License for the specific language governing permissions and
206// limitations under the License.
207// ----------------------------- END-OF-FILE ----------------------------------
208
209/** @} */
210/** @} */
211/** @} */
bool is() const
Definition bdlb_variant.h:7725
TYPE & the()
Definition bdlb_variant.h:7637
Definition bdlb_variant.h:2389
Definition bdlm_metric.h:75
bool isGauge() const
Definition bdlm_metric.h:162
double Gauge
Definition bdlm_metric.h:79
friend bool operator!=(const Metric &lhs, const Metric &rhs)
Definition bdlm_metric.h:183
friend bool operator==(const Metric &lhs, const Metric &rhs)
Definition bdlm_metric.h:177
Metric()
Create a default (empty) metric.
Definition bdlm_metric.h:141
~Metric()=default
const Gauge & theGauge() const
Definition bdlm_metric.h:168
Metric & operator=(const Gauge &value)
Assign to this metric the specified value.
Definition bdlm_metric.h:154
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlm_instancecount.h:100