BDE 4.39.x Production Release
Loading...
Searching...
No Matches
ball_hierarchicalcategorysetting.h
Go to the documentation of this file.
1/// @file ball_hierarchicalcategorysetting.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// ball_hierarchicalcategorysetting.h -*-C++-*-
8#ifndef INCLUDED_BALL_HIERARCHICALCATEGORYSETTING
9#define INCLUDED_BALL_HIERARCHICALCATEGORYSETTING
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup ball_hierarchicalcategorysetting ball_hierarchicalcategorysetting
15/// @brief Provide a container for a name prefix and associated thresholds.
16/// @addtogroup bal
17/// @{
18/// @addtogroup ball
19/// @{
20/// @addtogroup ball_hierarchicalcategorysetting
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#ball_hierarchicalcategorysetting-purpose"> Purpose</a>
25/// * <a href="#ball_hierarchicalcategorysetting-classes"> Classes </a>
26/// * <a href="#ball_hierarchicalcategorysetting-description"> Description </a>
27/// * <a href="#ball_hierarchicalcategorysetting-usage"> Usage </a>
28/// * <a href="#ball_hierarchicalcategorysetting-example-1-basic-use-of-ball-hierarchicalcategorysetting"> Example 1: Basic Use of ball::HierarchicalCategorySetting </a>
29///
30/// # Purpose {#ball_hierarchicalcategorysetting-purpose}
31/// Provide a container for a name prefix and associated thresholds.
32///
33/// # Classes {#ball_hierarchicalcategorysetting-classes}
34///
35/// - ball::HierarchicalCategorySetting: contains prefix and its threshold levels
36///
37/// @see ball_categorymanager
38///
39/// # Description {#ball_hierarchicalcategorysetting-description}
40/// This component provides the class
41/// `ball::HierarchicalCategorySetting` that represents the properties of a
42/// hierarchical logging category setting with a category name prefix and the 4
43/// threshold levels. See @ref ball_loggermanager for a description of the
44/// purpose of the various thresholds.
45///
46/// ## Usage {#ball_hierarchicalcategorysetting-usage}
47///
48///
49/// This section illustrates intended use of this component.
50///
51/// ### Example 1: Basic Use of ball::HierarchicalCategorySetting {#ball_hierarchicalcategorysetting-example-1-basic-use-of-ball-hierarchicalcategorysetting}
52///
53///
54/// The following example demonstrates how to create and use a
55/// `ball::HierarchicalCategorySetting` object to configure logging thresholds
56/// for categories with a specific name prefix.
57///
58/// First, we create a hierarchical category setting for all categories starting
59/// with "EQUITY":
60/// @code
61/// ball::HierarchicalCategorySetting setting(
62/// "EQUITY",
63/// 192, // recordLevel
64/// 128, // passLevel
65/// 96, // triggerLevel
66/// 64); // triggerAllLevel
67/// @endcode
68///
69/// Then, we can query the category prefix and threshold levels:
70/// @code
71/// assert(setting.categoryPrefix() == "EQUITY");
72/// assert(setting.recordLevel() == 192);
73/// assert(setting.passLevel() == 128);
74/// assert(setting.triggerLevel() == 96);
75/// assert(setting.triggerAllLevel() == 64);
76/// @endcode
77///
78/// Finally, we can modify the threshold levels:
79/// @code
80/// int rc = setting.setLevels(160, 96, 64, 32);
81/// assert(0 == rc);
82/// assert(setting.recordLevel() == 160);
83/// @endcode
84/// @}
85/** @} */
86/** @} */
87
88/** @addtogroup bal
89 * @{
90 */
91/** @addtogroup ball
92 * @{
93 */
94/** @addtogroup ball_hierarchicalcategorysetting
95 * @{
96 */
97
98#include <balscm_version.h>
99
101
102#include <bslma_allocator.h>
103
104#include <bslmf_movableref.h>
105
106#include <bsls_keyword.h>
107
108#include <bsl_iosfwd.h>
109#include <bsl_string.h>
110#include <bsl_string_view.h>
111
112
113namespace ball {
114
115 // =================================
116 // class HierarchicalCategorySetting
117 // =================================
118
119/// This class represents a hierarchical category setting that consists of a
120/// category name prefix and 4 threshold level settings for categories whose
121/// name starts with that prefix. Instances of `HierarchicalCategorySetting`
122/// are created and manipulated by `LoggerManager`. All threshold levels are
123/// integral values in the range `[0 .. 255]`.
124///
125/// See @ref ball_hierarchicalcategorysetting
127 private:
128 // PRIVATE TYPES
129
130 /// `MoveUtil` is an alias for `bslmf::MovableRefUtil`.
132
133 public:
134 // TYPES
136
137 private:
138 // DATA
139 bsl::string d_categoryPrefix; // category name prefix
140
141 unsigned int d_thresholdLevels; // record, pass, trigger, and
142 // trigger-all levels
143
144 // FRIENDS
149
150 public:
151 // CREATORS
152
153 /// Create a hierarchical category setting object having the specified
154 /// `categoryPrefix` and the specified `recordLevel`, `passLevel`,
155 /// `triggerLevel`, and `triggerAllLevel` threshold values, respectively.
156 /// Optionally specify a `basicAllocator` used to supply memory. If
157 /// `basicAllocator` is 0, the currently installed default allocator is used.
158 ///
159 /// \pre The behavior is undefined unless each of the specified threshold
160 /// levels is in the range `[0 .. 255]`.
163 int recordLevel,
164 int passLevel,
165 int triggerLevel,
166 int triggerAllLevel,
167 allocator_type allocator = allocator_type());
170 const ThresholdAggregate& levels,
171 allocator_type allocator = allocator_type());
172
173 /// Create a hierarchical category setting object initialized to the value
174 /// of the specified `original` object. Optionally specify an `allocator`
175 /// (e.g., the address of a `bslma::Allocator` object) to supply memory;
176 /// otherwise, the default allocator is used.
178 const HierarchicalCategorySetting& original,
179 const allocator_type& allocator = allocator_type());
180
181 /// Create a hierarchical category setting object having the same value as
182 /// the specified `original` object, and adopting all outstanding memory
183 /// allocations and the allocator associated with the `original` object.
184 /// `original` is left in a valid but unspecified state.
188
189 /// Create a hierarchical category setting object having the same value as
190 /// the specified `original` object. The value of `original` is moved to
191 /// the new object, and all outstanding memory allocations and the
192 /// specified `allocator` are adopted if
193 /// `allocator == original.get_allocator()`. `original` is left in a valid
194 /// but unspecified state.
197 const allocator_type& allocator);
198
199 /// Destroy this object.
201
202 // MANIPULATORS
203
204 /// Assign to this object the value of the specified `rhs` object, and
205 /// return a reference providing modifiable access to this object.
207 const HierarchicalCategorySetting& rhs);
208
209 /// Assign to this object the hierarchical category setting of the
210 /// specified `rhs` object, and return a reference providing modifiable
211 /// access to this object. The settings of `rhs` are moved to this object,
212 /// and all outstanding memory allocations and the allocator associated
213 /// with `rhs` are adopted if `get_allocator() == rhs.get_allocator()`.
214 /// `rhs` is left in a valid but unspecified state.
217
218 /// Set the threshold levels of this hierarchical category settings object
219 /// to the specified `recordLevel`, `passLevel`, `triggerLevel`, and
220 /// `triggerAllLevel` values, respectively, if each of the specified values
221 /// is in the range `[0 .. 255]`. Return 0 on success, and a non-zero
222 /// value otherwise (with no effect on the threshold levels of this
223 /// object).
225 int passLevel,
226 int triggerLevel,
227 int triggerAllLevel);
228
229 // ACCESSORS
230
231 /// Return the name prefix of this hierarchical category setting.
233
234 /// Return the record level of this hierarchical category setting.
235 int recordLevel() const;
236
237 /// Return the pass level of this hierarchical category setting.
238 int passLevel() const;
239
240 /// Return the trigger level of this hierarchical category setting.
241 int triggerLevel() const;
242
243 /// Return the trigger-all level of this hierarchical category setting.
244 int triggerAllLevel() const;
245
246 // Aspects
247
248 /// Return the allocator used by this object to supply memory.
250
251 /// Format this object to the specified output `stream` at the (absolute
252 /// value of) the optionally specified indentation `level` and return a
253 /// reference to `stream`. If `level` is specified, optionally specify
254 /// `spacesPerLevel`, the number of spaces per indentation level for this
255 /// and all of its nested objects. If `level` is negative, suppress
256 /// indentation of the first line. If `spacesPerLevel` is negative,
257 /// format the entire output on one line, suppressing all but the initial
258 /// indentation (as governed by `level`). If `stream` is not valid on entry, this operation has no effect.
259 ///
260 /// \note Note that the format is not
261 /// fully specified, and can change without notice.
262 bsl::ostream& print(bsl::ostream& stream,
263 int level = 0,
264 int spacesPerLevel = 4) const;
265};
266
267// FREE OPERATORS
268
269/// Return `true` if the specified `lhs` and `rhs` hierarchical category
270/// settings have the same value, and `false` otherwise. Two such objects have
271/// the same value if they have the same category name prefix and threshold
272/// values.
273bool operator==(const HierarchicalCategorySetting& lhs,
274 const HierarchicalCategorySetting& rhs);
275
276/// Return `true` if the specified `lhs` and `rhs` hierarchical category
277/// settings do not have the same value, and `false` otherwise. Two such
278/// objects differ in value if their category name prefix or threshold values
279/// differ.
280bool operator!=(const HierarchicalCategorySetting& lhs,
281 const HierarchicalCategorySetting& rhs);
282
283/// Write the value of the specified `object` to the specified output `stream`
284/// in a single-line format, and return a non-`const` reference to `stream`.
285/// If `stream` is not valid on entry, this operation has no effect.
286///
287/// \note Note that this human-readable format is not fully specified and can change without
288/// notice. Also note that this method has the same behavior as
289/// `object.print(stream, 0, -1)`, but with the attribute names elided.
290bsl::ostream& operator<<(bsl::ostream& stream,
291 const HierarchicalCategorySetting& object);
292
293// ============================================================================
294// INLINE DEFINITIONS
295// ============================================================================
296
297 // ---------------------------------
298 // class HierarchicalCategorySetting
299 // ---------------------------------
300
301// MANIPULATORS
302inline
305{
306 if (this != &rhs) {
307 d_categoryPrefix = rhs.d_categoryPrefix;
308 d_thresholdLevels = rhs.d_thresholdLevels;
309 }
310 return *this;
311}
312
313inline
316{
317 if (this != &MoveUtil::access(rhs)) {
318 d_categoryPrefix =
319 MoveUtil::move(MoveUtil::access(rhs).d_categoryPrefix);
320 d_thresholdLevels =
321 MoveUtil::move(MoveUtil::access(rhs).d_thresholdLevels);
322 }
323 return *this;
324}
325
326// ACCESSORS
327inline
329{
330 return d_categoryPrefix;
331}
332
333inline
335{
336 return ThresholdAggregateUtil::unpack(d_thresholdLevels).recordLevel();
337}
338
339inline
341{
342 return ThresholdAggregateUtil::unpack(d_thresholdLevels).passLevel();
343}
344
345inline
347{
348 return ThresholdAggregateUtil::unpack(d_thresholdLevels).triggerLevel();
349}
350
351inline
356
357 // Aspects
358
359inline
362{
363 return d_categoryPrefix.get_allocator();
364}
365
366} // close package namespace
367
368// FREE OPERATORS
369inline
370bool ball::operator==(const HierarchicalCategorySetting& lhs,
371 const HierarchicalCategorySetting& rhs)
372{
373 return lhs.d_thresholdLevels == rhs.d_thresholdLevels &&
374 lhs.d_categoryPrefix == rhs.d_categoryPrefix;
375}
376inline
377bool ball::operator!=(const HierarchicalCategorySetting& lhs,
378 const HierarchicalCategorySetting& rhs)
379{
380 return lhs.d_thresholdLevels != rhs.d_thresholdLevels ||
381 lhs.d_categoryPrefix != rhs.d_categoryPrefix;
382}
383
384
385
386#endif // INCLUDED_BALL_HIERARCHICALCATEGORYSETTING
387
388// ----------------------------------------------------------------------------
389// Copyright 2025 Bloomberg Finance L.P.
390//
391// Licensed under the Apache License, Version 2.0 (the "License");
392// you may not use this file except in compliance with the License.
393// You may obtain a copy of the License at
394//
395// http://www.apache.org/licenses/LICENSE-2.0
396//
397// Unless required by applicable law or agreed to in writing, software
398// distributed under the License is distributed on an "AS IS" BASIS,
399// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
400// See the License for the specific language governing permissions and
401// limitations under the License.
402// ----------------------------- END-OF-FILE ----------------------------------
403
404/** @} */
405/** @} */
406/** @} */
Definition ball_hierarchicalcategorysetting.h:126
HierarchicalCategorySetting(const bsl::string_view &categoryPrefix, const ThresholdAggregate &levels, allocator_type allocator=allocator_type())
int triggerAllLevel() const
Return the trigger-all level of this hierarchical category setting.
Definition ball_hierarchicalcategorysetting.h:352
HierarchicalCategorySetting & operator=(const HierarchicalCategorySetting &rhs)
Definition ball_hierarchicalcategorysetting.h:303
int passLevel() const
Return the pass level of this hierarchical category setting.
Definition ball_hierarchicalcategorysetting.h:340
bsl::allocator allocator_type
Definition ball_hierarchicalcategorysetting.h:135
friend bool operator!=(const HierarchicalCategorySetting &, const HierarchicalCategorySetting &)
~HierarchicalCategorySetting()=default
Destroy this object.
HierarchicalCategorySetting(const HierarchicalCategorySetting &original, const allocator_type &allocator=allocator_type())
allocator_type get_allocator() const
Return the allocator used by this object to supply memory.
Definition ball_hierarchicalcategorysetting.h:361
int triggerLevel() const
Return the trigger level of this hierarchical category setting.
Definition ball_hierarchicalcategorysetting.h:346
int recordLevel() const
Return the record level of this hierarchical category setting.
Definition ball_hierarchicalcategorysetting.h:334
friend bool operator==(const HierarchicalCategorySetting &, const HierarchicalCategorySetting &)
HierarchicalCategorySetting(bslmf::MovableRef< HierarchicalCategorySetting > original, const allocator_type &allocator)
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
int setLevels(int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel)
HierarchicalCategorySetting(bslmf::MovableRef< HierarchicalCategorySetting > original) BSLS_KEYWORD_NOEXCEPT
bsl::string_view categoryPrefix() const
Return the name prefix of this hierarchical category setting.
Definition ball_hierarchicalcategorysetting.h:328
HierarchicalCategorySetting(const bsl::string_view &categoryPrefix, int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel, allocator_type allocator=allocator_type())
static ThresholdAggregate unpack(unsigned packed)
Definition ball_thresholdaggregate.h:397
Definition ball_thresholdaggregate.h:101
int triggerLevel() const
Return the trigger level of this threshold aggregate.
Definition ball_thresholdaggregate.h:290
int recordLevel() const
Return the record level of this threshold aggregate.
Definition ball_thresholdaggregate.h:278
int passLevel() const
Return the pass level of this threshold aggregate.
Definition ball_thresholdaggregate.h:284
int triggerAllLevel() const
Return the trigger-all level of this threshold aggregate.
Definition ball_thresholdaggregate.h:296
Definition bslma_bslallocator.h:588
Definition bslstl_stringview.h:471
Definition bslstl_string.h:1252
allocator_type get_allocator() const BSLS_KEYWORD_NOEXCEPT
Return the allocator used by this string to supply memory.
Definition bslstl_string.h:7423
Definition bslmf_movableref.h:752
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:674
Definition ball_administration.h:214
bsl::ostream & operator<<(bsl::ostream &output, const Attribute &attribute)
bool operator!=(const Attribute &lhs, const Attribute &rhs)
bool operator==(const Attribute &lhs, const Attribute &rhs)
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
ALLOCATOR & lhs
Definition bslstl_string.h:3917
Definition bslmf_movableref.h:795
static MovableRef< t_TYPE > move(t_TYPE &reference) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1067
static t_TYPE & access(t_TYPE &ref) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1039