BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlm_instancecount.h
Go to the documentation of this file.
1/// @file bdlm_instancecount.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlm_instancecount.h -*-C++-*-
8#ifndef INCLUDED_BDLM_INSTANCECOUNT
9#define INCLUDED_BDLM_INSTANCECOUNT
10
11/// @defgroup bdlm_instancecount bdlm_instancecount
12/// @brief Provide a type specific instance count.
13/// @addtogroup bdl
14/// @{
15/// @addtogroup bdlm
16/// @{
17/// @addtogroup bdlm_instancecount
18/// @{
19///
20/// <h1> Outline </h1>
21/// * <a href="#bdlm_instancecount-purpose"> Purpose</a>
22/// * <a href="#bdlm_instancecount-classes"> Classes </a>
23/// * <a href="#bdlm_instancecount-description"> Description </a>
24/// * <a href="#bdlm_instancecount-thread-safety"> Thread Safety </a>
25/// * <a href="#bdlm_instancecount-usage"> Usage </a>
26/// * <a href="#bdlm_instancecount-example-1-using-bdlm-instancecount"> Example 1: Using bdlm::InstanceCount </a>
27///
28/// # Purpose {#bdlm_instancecount-purpose}
29/// Provide a type specific instance count.
30///
31/// @deprecated This component is not ready for public use.
32///
33/// # Classes {#bdlm_instancecount-classes}
34///
35/// - bdlm::InstanceCount: type specific instance count
36///
37/// # Description {#bdlm_instancecount-description}
38/// This component provides a mechanism, `bdlm::InstanceCount`, for
39/// providing type specific instance counts.
40///
41/// ## Thread Safety {#bdlm_instancecount-thread-safety}
42///
43///
44/// This class is *thread-safe* (see {@ref bsldoc_glossary |Thread-Safe}).
45///
46/// ## Usage {#bdlm_instancecount-usage}
47///
48///
49/// This section illustrates intended use of this component.
50///
51/// ### Example 1: Using bdlm::InstanceCount {#bdlm_instancecount-example-1-using-bdlm-instancecount}
52///
53///
54/// This example demonstrates the usage of `bdlm::InstanceCount` to obtain type
55/// specific instance counts.
56///
57/// First, we obtain and verify the instance counts for a few types:
58/// @code
59/// assert(1 == bdlm::InstanceCount::nextInstanceNumber<char>());
60/// assert(1 == bdlm::InstanceCount::nextInstanceNumber<int>());
61/// assert(1 == bdlm::InstanceCount::nextInstanceNumber<double>());
62/// @endcode
63/// Then, we obtain and verify the instance counts for the previous types and
64/// some new types:
65/// @code
66/// assert(2 == bdlm::InstanceCount::nextInstanceNumber<char>());
67/// assert(2 == bdlm::InstanceCount::nextInstanceNumber<int>());
68/// assert(1 == bdlm::InstanceCount::nextInstanceNumber<unsigned>());
69/// assert(1 == bdlm::InstanceCount::nextInstanceNumber<float>());
70/// assert(2 == bdlm::InstanceCount::nextInstanceNumber<double>());
71/// @endcode
72/// Finally, we obtain and verify the next instance counts for these types:
73/// @code
74/// assert(3 == bdlm::InstanceCount::nextInstanceNumber<char>());
75/// assert(3 == bdlm::InstanceCount::nextInstanceNumber<int>());
76/// assert(2 == bdlm::InstanceCount::nextInstanceNumber<unsigned>());
77/// assert(2 == bdlm::InstanceCount::nextInstanceNumber<float>());
78/// assert(3 == bdlm::InstanceCount::nextInstanceNumber<double>());
79/// @endcode
80/// @}
81/** @} */
82/** @} */
83
84/** @addtogroup bdl
85 * @{
86 */
87/** @addtogroup bdlm
88 * @{
89 */
90/** @addtogroup bdlm_instancecount
91 * @{
92 */
93
94#include <bsls_ident.h>
95BSLS_IDENT("$Id$")
96
97#include <bsls_atomic.h>
98#include <bsls_types.h>
99
100
101namespace bdlm {
102
103 // ===================
104 // class InstanceCount
105 // ===================
106
107/// This mechanism provides type specific instance counts.
109
110 // TYPES
111 typedef bsls::Types::Uint64 Value; // storage type for instance counts
112
113 // CLASS METHODS
114
115 /// Return the next instance number for the specified `OBJECT_TYPE`.
116 template <class OBJECT_TYPE>
117 static Value nextInstanceNumber();
118};
119
120// ============================================================================
121// INLINE DEFINITIONS
122// ============================================================================
123
124 // -------------------
125 // class InstanceCount
126 // -------------------
127
128// CLASS METHODS
129template <class OBJECT_TYPE>
130inline
132{
133 static bsls::AtomicUint64 count(0);
134
135 return ++count;
136}
137
138} // close package namespace
139
140
141#endif
142
143// ----------------------------------------------------------------------------
144// Copyright 2024 Bloomberg Finance L.P.
145//
146// Licensed under the Apache License, Version 2.0 (the "License");
147// you may not use this file except in compliance with the License.
148// You may obtain a copy of the License at
149//
150// http://www.apache.org/licenses/LICENSE-2.0
151//
152// Unless required by applicable law or agreed to in writing, software
153// distributed under the License is distributed on an "AS IS" BASIS,
154// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
155// See the License for the specific language governing permissions and
156// limitations under the License.
157// ----------------------------- END-OF-FILE ----------------------------------
158
159/** @} */
160/** @} */
161/** @} */
Definition bsls_atomic.h:1195
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlm_instancecount.h:101
This mechanism provides type specific instance counts.
Definition bdlm_instancecount.h:108
static Value nextInstanceNumber()
Return the next instance number for the specified OBJECT_TYPE.
Definition bdlm_instancecount.h:131
bsls::Types::Uint64 Value
Definition bdlm_instancecount.h:111
unsigned long long Uint64
Definition bsls_types.h:137