BDE 4.39.x 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/// # Classes {#bdlm_instancecount-classes}
32///
33/// - bdlm::InstanceCount: type specific instance count
34///
35/// # Description {#bdlm_instancecount-description}
36/// This component provides a mechanism, `bdlm::InstanceCount`, for
37/// providing type specific instance counts.
38///
39/// ## Thread Safety {#bdlm_instancecount-thread-safety}
40///
41///
42/// This class is *fully thread-safe*
43/// (see {@ref bsldoc_glossary |Fully Thread-Safe}).
44///
45/// ## Usage {#bdlm_instancecount-usage}
46///
47///
48/// This section illustrates intended use of this component.
49///
50/// ### Example 1: Using bdlm::InstanceCount {#bdlm_instancecount-example-1-using-bdlm-instancecount}
51///
52///
53/// This example demonstrates the usage of `bdlm::InstanceCount` to obtain type
54/// specific instance counts.
55///
56/// First, we obtain and verify the instance counts for a few types:
57/// @code
58/// assert(1 == bdlm::InstanceCount::nextInstanceNumber<char>());
59/// assert(1 == bdlm::InstanceCount::nextInstanceNumber<int>());
60/// assert(1 == bdlm::InstanceCount::nextInstanceNumber<double>());
61/// @endcode
62/// Then, we obtain and verify the instance counts for the previous types and
63/// some new types:
64/// @code
65/// assert(2 == bdlm::InstanceCount::nextInstanceNumber<char>());
66/// assert(2 == bdlm::InstanceCount::nextInstanceNumber<int>());
67/// assert(1 == bdlm::InstanceCount::nextInstanceNumber<unsigned>());
68/// assert(1 == bdlm::InstanceCount::nextInstanceNumber<float>());
69/// assert(2 == bdlm::InstanceCount::nextInstanceNumber<double>());
70/// @endcode
71/// Finally, we obtain and verify the next instance counts for these types:
72/// @code
73/// assert(3 == bdlm::InstanceCount::nextInstanceNumber<char>());
74/// assert(3 == bdlm::InstanceCount::nextInstanceNumber<int>());
75/// assert(2 == bdlm::InstanceCount::nextInstanceNumber<unsigned>());
76/// assert(2 == bdlm::InstanceCount::nextInstanceNumber<float>());
77/// assert(3 == bdlm::InstanceCount::nextInstanceNumber<double>());
78/// @endcode
79/// @}
80/** @} */
81/** @} */
82
83/** @addtogroup bdl
84 * @{
85 */
86/** @addtogroup bdlm
87 * @{
88 */
89/** @addtogroup bdlm_instancecount
90 * @{
91 */
92
93#include <bsls_ident.h>
94BSLS_IDENT("$Id$")
95
96#include <bsls_atomicoperations.h>
97#include <bsls_types.h>
98
99
100namespace bdlm {
101
102 // ===================
103 // class InstanceCount
104 // ===================
105
106/// This mechanism provides type specific instance counts.
107///
108/// See @ref bdlm_instancecount
110
111 // TYPES
112 typedef bsls::Types::Uint64 Value; // storage type for instance counts
113
114 // CLASS METHODS
115
116 /// Return the next instance number for the specified `OBJECT_TYPE`.
117 template <class OBJECT_TYPE>
118 static Value nextInstanceNumber();
119};
120
121// ============================================================================
122// INLINE DEFINITIONS
123// ============================================================================
124
125 // -------------------
126 // class InstanceCount
127 // -------------------
128
129// CLASS METHODS
130template <class OBJECT_TYPE>
131inline
133{
134 static bsls::AtomicOperations::AtomicTypes::Uint64 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/** @} */
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlm_instancecount.h:100
Definition bdlm_instancecount.h:109
static Value nextInstanceNumber()
Return the next instance number for the specified OBJECT_TYPE.
Definition bdlm_instancecount.h:132
bsls::Types::Uint64 Value
Definition bdlm_instancecount.h:112
static Types::Uint64 incrementUint64Nv(AtomicTypes::Uint64 *atomicUint)
Definition bsls_atomicoperations.h:2269
unsigned long long Uint64
Definition bsls_types.h:139