BDE 4.14.0 Production release
Loading...
Searching...
No Matches
balm_metricid.h
Go to the documentation of this file.
1/// @file balm_metricid.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// balm_metricid.h -*-C++-*-
8#ifndef INCLUDED_BALM_METRICID
9#define INCLUDED_BALM_METRICID
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: balm_metricid.h,v 1.4 2008/04/16 20:00:49 hversche Exp $")
13
14/// @defgroup balm_metricid balm_metricid
15/// @brief Provide an identifier for a metric.
16/// @addtogroup bal
17/// @{
18/// @addtogroup balm
19/// @{
20/// @addtogroup balm_metricid
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#balm_metricid-purpose"> Purpose</a>
25/// * <a href="#balm_metricid-classes"> Classes </a>
26/// * <a href="#balm_metricid-description"> Description </a>
27/// * <a href="#balm_metricid-alternative-systems-for-telemetry"> Alternative Systems for Telemetry </a>
28/// * <a href="#balm_metricid-thread-safety"> Thread Safety </a>
29/// * <a href="#balm_metricid-usage"> Usage </a>
30/// * <a href="#balm_metricid-example-1-basic-usage"> Example 1: Basic Usage </a>
31///
32/// # Purpose {#balm_metricid-purpose}
33/// Provide an identifier for a metric.
34///
35/// # Classes {#balm_metricid-classes}
36///
37/// - balm::MetricId: an identifier for a metric
38///
39/// @see balm_metricregistry, balm_metricdescription, balm_category
40///
41/// # Description {#balm_metricid-description}
42/// This component implements an in-core value-semantic type used
43/// to identify a metric. A `balm::MetricId` object's value is the *address* of
44/// a (non-modifiable) `balm::MetricDescription` object. A `balm::MetricId`
45/// object also provides auxiliary methods, `category`, `categoryName`, and
46/// `metricName`, that enables access to the properties of the held
47/// `balm::MetricDescription`. Two `balm::MetricId` objects have the same value
48/// if the values of their respective `balm::MetricDescription` object
49/// *addresses* are the same.
50///
51/// ## Alternative Systems for Telemetry {#balm_metricid-alternative-systems-for-telemetry}
52///
53///
54/// Bloomberg software may alternatively use the GUTS telemetry API, which is
55/// integrated into Bloomberg infrastructure.
56///
57/// ## Thread Safety {#balm_metricid-thread-safety}
58///
59///
60/// `balm::MetricId` is *const* *thread-safe*, meaning that accessors may be
61/// invoked concurrently from different threads, but it is not safe to access
62/// or modify a `balm::MetricId` in one thread while another thread modifies the
63/// same object.
64///
65/// ## Usage {#balm_metricid-usage}
66///
67///
68/// This section illustrates intended use of this component.
69///
70/// ### Example 1: Basic Usage {#balm_metricid-example-1-basic-usage}
71///
72///
73/// The following example demonstrates how to create and use a `balm::MetricId`
74/// object. We start by creating a category and two metric description objects:
75/// @code
76/// balm::Category category("MyCategory");
77/// balm::MetricDescription descriptionA(&category, "MetricA");
78/// balm::MetricDescription descriptionB(&category, "MetricB");
79/// @endcode
80/// Now we create three `balm::MetricId` objects:
81/// @code
82/// balm::MetricId invalidId;
83/// balm::MetricId metricIdA(&descriptionA);
84/// balm::MetricId metricIdB(&descriptionB);
85/// @endcode
86/// We can access and verify the properties of the `balm::MetricId` objects we
87/// have created:
88/// @code
89/// assert(false == invalidId.isValid());
90/// assert(true == metricIdA.isValid());
91/// assert(true == metricIdB.isValid());
92///
93/// assert(0 == invalidId.description());
94/// assert(&descriptionA == metricIdA.description());
95/// assert(&descriptionB == metricIdB.description());
96///
97/// assert(invalidId != metricIdA);
98/// assert(invalidId != metricIdB);
99/// assert(metricIdA != metricIdB);
100/// @endcode
101/// We now verify that copies of a metric id have the same value as the
102/// original:
103/// @code
104/// balm::MetricId copyMetricIdA(metricIdA);
105///
106/// assert(metricIdA == copyMetricIdA);
107/// @endcode
108/// Note that two `balm::MetricId` objects that have different
109/// `balm::MetricDescription` object addresses are *not* equal, *even* if the
110/// descriptions have the same name and category.
111/// @code
112/// balm::MetricDescription newDescriptionB(&category, "MetricB");
113/// balm::MetricId differentIdB(&newDescriptionB);
114///
115/// assert(0 == bsl::strcmp(differentIdB.metricName(),metricIdB.metricName()));
116/// assert(differentIdB.category() == metricIdB.category());
117///
118/// assert(metricIdB != differentIdB); // The 'balm::MetricDescription'
119/// // object addresses are not equal!
120/// @endcode
121/// @}
122/** @} */
123/** @} */
124
125/** @addtogroup bal
126 * @{
127 */
128/** @addtogroup balm
129 * @{
130 */
131/** @addtogroup balm_metricid
132 * @{
133 */
134
135#include <balscm_version.h>
136
137#include <balm_category.h>
139
142
143#include <bsl_iosfwd.h>
144
145
146
147namespace balm {
148 // ==============
149 // class MetricId
150 // ==============
151
152/// This class defines an in-core value-semantic type used to identify a
153/// metric. A `MetricId` object's value is the *address* of a
154/// non-modifiable `MetricDescription` object. In addition, a
155/// `MetricDescription` object provides auxiliary methods, `category`,
156/// `categoryName`, and `name`, that enable access to the properties of the
157/// held `MetricDescription`. Two `MetricId` objects have the same value if
158/// the values of their respective `MetricDescription` object *addresses*
159/// are the same.
160///
161/// See @ref balm_metricid
162class MetricId {
163
164 // DATA
165 const MetricDescription *d_description_p; // metric description
166 // (held, not owned)
167 public:
168 // TRAITS
171
172 // CREATORS
173
174 /// Create an invalid metric id.
175 MetricId();
176
177 /// Create a metric id whose value is the specified `metricDescription`
178 /// address. The behavior is undefined unless `metricDescription` is
179 /// 0, or the indicated metric description object remains valid for the
180 /// lifetime of this metric id object.
181 MetricId(const MetricDescription *metricDescription);
182
183 /// Create a metric id with the value of the specified 'original' metric
184 /// id. The behavior is undefined unless the 'description()' of 'original'
185 /// is 0, or the indicated metric description object remains valid for the
186 /// lifetime of this metric id object.
187 MetricId(const MetricId& original) = default;
188
189 /// Destroy this object.
190 ~MetricId() = default;
191
192 // MANIPULATORS
193
194 /// Assign this metric id the value of the specified 'rhs' metric id
195 /// object, and return a reference to this object. The behavior is
196 /// undefined unless the 'description()' of 'rhs' is 0, or the
197 /// metric-description object remains valid for the lifetime of this
198 /// metric-id object.
199 MetricId& operator=(const MetricId& rhs) = default;
200
201 /// Return a reference to the modifiable address of the *held*
202 /// non-modifiable `MetricDescription`, which defines the value of this
203 /// metric id.
205
206 // ACCESSORS
207
208 /// Return a reference to the non-modifiable address of the *held*
209 /// non-modifiable `MetricDescription`, which defines the value of this
210 /// metric id.
211 const MetricDescription * const & description() const;
212
213 /// Return `true` if this metric id object contains the address of a
214 /// valid `MetricDescription` object, and false `otherwise`. Note that
215 /// this method is logically equivalent to `0 != description()`.
216 bool isValid() const;
217
218 /// Return the address of the non-modifiable `Category` object
219 /// identifying the category with which this metric id is associated.
220 /// The behavior is undefined unless `isValid()` is `true`. Note that
221 /// this method is logically equivalent to `description()->category()`.
222 const Category *category() const;
223
224 /// Return the address of the non-modifiable name for the category with
225 /// which this metric id is associated. The behavior is undefined
226 /// unless `isValid()` is `true`. Note that this method is logically
227 /// equivalent to `description()->category()->name()`.
228 const char *categoryName() const;
229
230 /// Return the address of the non-modifiable name of this metric id.
231 /// The behavior is undefined unless `isValid()` is `true`. Note that
232 /// this method is logically equivalent to `description()->name()`.
233 const char *metricName() const;
234
235 /// Print this metric id to the specified output `stream` in some
236 /// single-line human-readable form, and return a reference to the
237 /// modifiable `stream`.
238 bsl::ostream& print(bsl::ostream& stream) const;
239};
240
241// ============================================================================
242// INLINE DEFINITIONS
243// ============================================================================
244
245// FREE OPERATORS
246
247/// Return `true` if the specified `lhs` and `rhs` metric ids have the same
248/// value and `false` otherwise. Two metric ids have the same value if they
249/// each hold the address of the same `MetricDescription` object, or both
250/// addresses are 0.
251inline
252bool operator==(const MetricId& lhs, const MetricId& rhs);
253
254/// Return `true` if the specified `lhs` and `rhs` metric ids do not have
255/// the same value and `false` otherwise. Two metric ids do not have same
256/// value if they refer to different `MetricDescription` object *addresses*,
257/// or exactly one address is 0.
258inline
259bool operator!=(const MetricId& lhs, const MetricId& rhs);
260
261/// Return `true` if the specified `lhs` metric id is less than (ordered
262/// before) the specified `rhs` metric id, and return `false` otherwise'.
263/// The `lhs` is considered less if the (unsigned) *address* of the
264/// contained `MetricDescription` object is numerically less than the `rhs`
265/// description. Note that this function does *not* provide any form of
266/// alphabetic ordering, and is logically equivalent to the expression
267/// `lhs.description() < rhs.description()`.
268inline
269bool operator<(const MetricId& lhs, const MetricId& rhs);
270
271/// Write a description of the specified `rhs` metric id to the specified
272/// `stream` in some human-readable format, and return a reference to the
273/// modifiable `stream`.
274inline
275bsl::ostream& operator<<(bsl::ostream& stream, const MetricId& rhs);
276
277// ============================================================================
278// INLINE FUNCTION DEFINITIONS
279// ============================================================================
280
281 // --------------
282 // class MetricId
283 // --------------
284
285// CREATORS
286inline
288: d_description_p(0)
289{
290}
291
292inline
293MetricId::MetricId(const MetricDescription *metricDescription)
294: d_description_p(metricDescription)
295{
296}
297
298// MANIPULATORS
299inline
301{
302 return d_description_p;
303}
304
305// ACCESSORS
306inline
308{
309 return d_description_p;
310}
311
312inline
314{
315 return 0 != d_description_p;
316}
317
318inline
320{
321 return d_description_p->category();
322}
323
324inline
325const char *MetricId::categoryName() const
326{
327 return d_description_p->category()->name();
328}
329
330inline
331const char *MetricId::metricName() const
332{
333 return d_description_p->name();
334}
335} // close package namespace
336
337// FREE OPERATORS
338inline
339bool balm::operator==(const MetricId& lhs, const MetricId& rhs)
340{
341 return lhs.description() == rhs.description();
342}
343
344inline
345bool balm::operator!=(const MetricId& lhs, const MetricId& rhs)
346{
347 return !(lhs == rhs);
348}
349
350inline
351bool balm::operator<(const MetricId& lhs, const MetricId& rhs)
352{
353 return lhs.description() < rhs.description();
354}
355
356inline
357bsl::ostream& balm::operator<<(bsl::ostream& stream, const MetricId& rhs)
358{
359 return rhs.print(stream);
360}
361
362
363
364#endif
365
366// ----------------------------------------------------------------------------
367// Copyright 2015 Bloomberg Finance L.P.
368//
369// Licensed under the Apache License, Version 2.0 (the "License");
370// you may not use this file except in compliance with the License.
371// You may obtain a copy of the License at
372//
373// http://www.apache.org/licenses/LICENSE-2.0
374//
375// Unless required by applicable law or agreed to in writing, software
376// distributed under the License is distributed on an "AS IS" BASIS,
377// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
378// See the License for the specific language governing permissions and
379// limitations under the License.
380// ----------------------------- END-OF-FILE ----------------------------------
381
382/** @} */
383/** @} */
384/** @} */
Definition balm_category.h:151
const char * name() const
Definition balm_category.h:334
Definition balm_metricdescription.h:158
const Category * category() const
Definition balm_metricdescription.h:367
const char * name() const
Definition balm_metricdescription.h:361
Definition balm_metricid.h:162
bool isValid() const
Definition balm_metricid.h:313
const Category * category() const
Definition balm_metricid.h:319
const MetricDescription *& description()
Definition balm_metricid.h:300
const char * metricName() const
Definition balm_metricid.h:331
~MetricId()=default
Destroy this object.
MetricId(const MetricId &original)=default
MetricId()
Create an invalid metric id.
Definition balm_metricid.h:287
MetricId & operator=(const MetricId &rhs)=default
BSLMF_NESTED_TRAIT_DECLARATION(MetricId, bsl::is_trivially_copyable)
const char * categoryName() const
Definition balm_metricid.h:325
bsl::ostream & print(bsl::ostream &stream) const
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition balm_bdlmmetricsadapter.h:141
bool operator<(const MetricId &lhs, const MetricId &rhs)
bool operator==(const IntegerMetric &lhs, const IntegerMetric &rhs)
bsl::ostream & operator<<(bsl::ostream &stream, const Category &rhs)
bool operator!=(const IntegerMetric &lhs, const IntegerMetric &rhs)
Definition bslmf_istriviallycopyable.h:329