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