BDE 4.14.0 Production release
Loading...
Searching...
No Matches
ball_thresholdaggregate.h
Go to the documentation of this file.
1/// @file ball_thresholdaggregate.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// ball_thresholdaggregate.h -*-C++-*-
8#ifndef INCLUDED_BALL_THRESHOLDAGGREGATE
9#define INCLUDED_BALL_THRESHOLDAGGREGATE
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup ball_thresholdaggregate ball_thresholdaggregate
15/// @brief Provide an aggregate of the four logging threshold levels.
16/// @addtogroup bal
17/// @{
18/// @addtogroup ball
19/// @{
20/// @addtogroup ball_thresholdaggregate
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#ball_thresholdaggregate-purpose"> Purpose</a>
25/// * <a href="#ball_thresholdaggregate-classes"> Classes </a>
26/// * <a href="#ball_thresholdaggregate-description"> Description </a>
27/// * <a href="#ball_thresholdaggregate-usage"> Usage </a>
28/// * <a href="#ball_thresholdaggregate-example-1-basic-usage"> Example 1: Basic Usage </a>
29///
30/// # Purpose {#ball_thresholdaggregate-purpose}
31/// Provide an aggregate of the four logging threshold levels.
32///
33/// # Classes {#ball_thresholdaggregate-classes}
34///
35/// - ball::ThresholdAggregate: aggregate of four logging threshold levels
36///
37/// @see ball_severity
38///
39/// # Description {#ball_thresholdaggregate-description}
40/// This component implements a class, `ball::ThresholdAggregate`,
41/// that aggregates four threshold levels: record level, pass-through level,
42/// trigger level, and trigger-all level. Each of these levels must in the
43/// range `[0 .. 255]`, and represents a threshold which, if exceeded, will
44/// invoke a certain action.
45///
46/// ## Usage {#ball_thresholdaggregate-usage}
47///
48///
49/// This section illustrates intended use of this component.
50///
51/// ### Example 1: Basic Usage {#ball_thresholdaggregate-example-1-basic-usage}
52///
53///
54/// The following code fragment illustrates some of the basic operations on
55/// threshold levels provided by `ball::ThresholdAggregate`.
56/// @code
57/// ball::ThresholdAggregate levels(192, 160, 128, 96);
58/// assert(192 == levels.recordLevel());
59/// assert(160 == levels.passLevel());
60/// assert(128 == levels.triggerLevel());
61/// assert( 96 == levels.triggerAllLevel());
62///
63/// levels.setLevels(160, 128, 96, 64);
64/// assert(160 == levels.recordLevel());
65/// assert(128 == levels.passLevel());
66/// assert( 96 == levels.triggerLevel());
67/// assert( 64 == levels.triggerAllLevel());
68/// @endcode
69/// @}
70/** @} */
71/** @} */
72
73/** @addtogroup bal
74 * @{
75 */
76/** @addtogroup ball
77 * @{
78 */
79/** @addtogroup ball_thresholdaggregate
80 * @{
81 */
82
83#include <balscm_version.h>
84
85#include <bsl_iosfwd.h>
86
87
88namespace ball {
89
90 // ========================
91 // class ThresholdAggregate
92 // ========================
93
94/// This class implements an aggregate of the four logging threshold levels.
95///
96/// See @ref ball_thresholdaggregate
98
99 // DATA
100 unsigned char d_recordLevel; // record
101 unsigned char d_passLevel; // pass
102 unsigned char d_triggerLevel; // trigger
103 unsigned char d_triggerAllLevel; // trigger-all
104
105 // FRIENDS
106 friend bool operator==(const ThresholdAggregate&,
107 const ThresholdAggregate&);
108 public:
109 // CLASS METHODS
110
111 /// Return a hash value calculated from the specified threshold
112 /// `aggregate` using the specified `size` as the number of slots. The
113 /// hash value is guaranteed to be in the range `[0, size - 1]`. The
114 /// behavior is undefined unless `0 < size`.
115 static int hash(const ThresholdAggregate& aggregate, int size);
116
117 /// Return `true` if each of the specified `recordLevel`, `passLevel`,
118 /// `triggerLevel`, and `triggerAllLevel` threshold values is in the
119 /// range `[0 .. 255]`, and `false` otherwise.
120 static bool areValidThresholdLevels(int recordLevel,
121 int passLevel,
122 int triggerLevel,
123 int triggerAllLevel);
124
125 /// Return the numerically greatest of the specified `recordLevel`,
126 /// `passLevel`, `triggerLevel`, and `triggerAllLevel` values.
127 static int maxLevel(int recordLevel,
128 int passLevel,
129 int triggerLevel,
130 int triggerAllLevel);
131
132 /// Return the numerically greatest of the four logging threshold levels
133 /// held by the specified threshold `aggregate`.
134 static int maxLevel(const ThresholdAggregate& aggregate);
135
136 // CREATORS
137
138 /// Create a threshold aggregate whose threshold levels are all 0.
140
141 /// Create a threshold aggregate whose threshold levels are the
142 /// specified `recordLevel`, `passLevel`, `triggerLevel`, and
143 /// `triggerAllLevel`, respectively. The behavior is undefined if any
144 /// threshold level is not in the range `[0 .. 255]`.
146 int passLevel,
147 int triggerLevel,
148 int triggerAllLevel);
149
150 /// Create a threshold aggregate having the same value as that of the
151 /// specified `original` threshold aggregate.
152 ThresholdAggregate(const ThresholdAggregate& original);
153
154 /// Destroy this object.
156
157 // MANIPULATORS
158
159 /// Assign the value of the specified `rhs` threshold aggregate to this
160 /// aggregate, and return a reference to this modifiable aggregate.
162
163 /// Set the threshold levels of this threshold aggregate to the
164 /// specified `recordLevel`, `passLevel`, `triggerLevel`, and
165 /// `triggerAllLevel` values, respectively, if each of the specified
166 /// values is in the range `[0 .. 255]`. Return 0 on success, and a
167 /// non-zero value otherwise (with no effect on the threshold levels of
168 /// this aggregate).
170 int passLevel,
171 int triggerLevel,
172 int triggerAllLevel);
173
174 /// Set the record level of this threshold aggregate to the specified
175 /// `recordLevel`.
176 void setRecordLevel(int recordLevel);
177
178 /// Set the pass level of this threshold aggregate to the specified
179 /// `passLevel`.
180 void setPassLevel(int passLevel);
181
182 /// Set the trigger level of this threshold aggregate to the specified
183 /// `triggerLevel`.
185
186 /// Set the trigger-all level of this threshold aggregate to the
187 /// specified `triggerAllLevel`.
189
190 // ACCESSORS
191
192 /// Return the record level of this threshold aggregate.
193 int recordLevel() const;
194
195 /// Return the pass level of this threshold aggregate.
196 int passLevel() const;
197
198 /// Return the trigger level of this threshold aggregate.
199 int triggerLevel() const;
200
201 /// Return the trigger-all level of this threshold aggregate.
202 int triggerAllLevel() const;
203
204 /// Format this object to the specified output `stream` at the
205 /// (absolute value of) the optionally specified indentation `level`
206 /// and return a reference to `stream`. If `level` is specified,
207 /// optionally specify `spacesPerLevel`, the number of spaces per
208 /// indentation level for this and all of its nested objects. If
209 /// `level` is negative, suppress indentation of the first line. If
210 /// `spacesPerLevel` is negative, format the entire output on one line,
211 /// suppressing all but the initial indentation (as governed by
212 /// `level`). If `stream` is not valid on entry, this operation has no
213 /// effect.
214 bsl::ostream& print(bsl::ostream& stream,
215 int level = 0,
216 int spacesPerLevel = 4) const;
217};
218
219// FREE OPERATORS
220
221/// Return `true` if the specified `lhs` and `rhs` threshold aggregates have
222/// the same value, and `false` otherwise. Two threshold aggregates have
223/// the same value if all four of their respective threshold levels are the
224/// same.
225bool operator==(const ThresholdAggregate& lhs, const ThresholdAggregate& rhs);
226
227/// Return `true` if the specified `lhs` and `rhs` threshold aggregates do
228/// not have the same value, and `false` otherwise. Two threshold
229/// aggregates do not have the same value if any of their four respective
230/// threshold levels differ.
231bool operator!=(const ThresholdAggregate& lhs, const ThresholdAggregate& rhs);
232
233/// Write the value of the specified threshold `aggregate` to the specified
234/// output `stream` and return a reference to the modifiable `stream`.
235bsl::ostream& operator<<(bsl::ostream& stream,
236 const ThresholdAggregate& aggregate);
237
238// ============================================================================
239// INLINE DEFINITIONS
240// ============================================================================
241
242 // ------------------------
243 // class ThresholdAggregate
244 // ------------------------
245
246// ACCESSORS USED INLINE BY OTHER METHODS
247inline
249{
250 return d_recordLevel;
251}
252
253inline
255{
256 return d_passLevel;
257}
258
259inline
261{
262 return d_triggerLevel;
263}
264
265inline
267{
268 return d_triggerAllLevel;
269}
270
271// CLASS METHODS
272inline
274 int passLevel,
275 int triggerLevel,
276 int triggerAllLevel)
277{
278 enum { k_BITS_PER_CHAR = 8 };
279
281 >> k_BITS_PER_CHAR);
282}
283
284inline
286{
287 return maxLevel(aggregate.recordLevel(), aggregate.passLevel(),
288 aggregate.triggerLevel(), aggregate.triggerAllLevel());
289}
290
291// CREATORS
292inline
294: d_recordLevel(0)
295, d_passLevel(0)
296, d_triggerLevel(0)
297, d_triggerAllLevel(0)
298{
299}
300
301inline
303 int passLevel,
304 int triggerLevel,
305 int triggerAllLevel)
306: d_recordLevel(static_cast<unsigned char>(recordLevel))
307, d_passLevel(static_cast<unsigned char>(passLevel))
308, d_triggerLevel(static_cast<unsigned char>(triggerLevel))
309, d_triggerAllLevel(static_cast<unsigned char>(triggerAllLevel))
310{
311}
312
313inline
315: d_recordLevel(original.d_recordLevel)
316, d_passLevel(original.d_passLevel)
317, d_triggerLevel(original.d_triggerLevel)
318, d_triggerAllLevel(original.d_triggerAllLevel)
319{
320}
321
322// MANIPULATORS
323inline
325{
326 d_recordLevel = static_cast<unsigned char>(recordLevel);
327}
328
329inline
331{
332 d_passLevel = static_cast<unsigned char>(passLevel);
333}
334
335inline
337{
338 d_triggerLevel = static_cast<unsigned char>(triggerLevel);
339}
340
341inline
343{
344 d_triggerAllLevel = static_cast<unsigned char>(triggerAllLevel);
345}
346
347} // close package namespace
348
349// FREE OPERATORS
350inline
351bool ball::operator==(const ThresholdAggregate& lhs,
352 const ThresholdAggregate& rhs)
353{
354 return lhs.d_recordLevel == rhs.d_recordLevel
355 && lhs.d_passLevel == rhs.d_passLevel
356 && lhs.d_triggerLevel == rhs.d_triggerLevel
357 && lhs.d_triggerAllLevel == rhs.d_triggerAllLevel;
358}
359
360inline
361bool ball::operator!=(const ThresholdAggregate& lhs,
362 const ThresholdAggregate& rhs)
363{
364 return !(lhs == rhs);
365}
366
367inline
368bsl::ostream& ball::operator<<(bsl::ostream& stream,
369 const ThresholdAggregate& aggregate)
370{
371 return aggregate.print(stream, 0, -1);
372}
373
374
375
376#endif
377
378// ----------------------------------------------------------------------------
379// Copyright 2015 Bloomberg Finance L.P.
380//
381// Licensed under the Apache License, Version 2.0 (the "License");
382// you may not use this file except in compliance with the License.
383// You may obtain a copy of the License at
384//
385// http://www.apache.org/licenses/LICENSE-2.0
386//
387// Unless required by applicable law or agreed to in writing, software
388// distributed under the License is distributed on an "AS IS" BASIS,
389// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
390// See the License for the specific language governing permissions and
391// limitations under the License.
392// ----------------------------- END-OF-FILE ----------------------------------
393
394/** @} */
395/** @} */
396/** @} */
Definition ball_thresholdaggregate.h:97
int triggerLevel() const
Return the trigger level of this threshold aggregate.
Definition ball_thresholdaggregate.h:260
int recordLevel() const
Return the record level of this threshold aggregate.
Definition ball_thresholdaggregate.h:248
~ThresholdAggregate()=default
Destroy this object.
void setRecordLevel(int recordLevel)
Definition ball_thresholdaggregate.h:324
void setTriggerAllLevel(int triggerAllLevel)
Definition ball_thresholdaggregate.h:342
int passLevel() const
Return the pass level of this threshold aggregate.
Definition ball_thresholdaggregate.h:254
void setTriggerLevel(int triggerLevel)
Definition ball_thresholdaggregate.h:336
friend bool operator==(const ThresholdAggregate &, const ThresholdAggregate &)
void setPassLevel(int passLevel)
Definition ball_thresholdaggregate.h:330
static int hash(const ThresholdAggregate &aggregate, int size)
ThresholdAggregate & operator=(const ThresholdAggregate &rhs)
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
static int maxLevel(int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel)
ThresholdAggregate()
Create a threshold aggregate whose threshold levels are all 0.
Definition ball_thresholdaggregate.h:293
int setLevels(int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel)
static bool areValidThresholdLevels(int recordLevel, int passLevel, int triggerLevel, int triggerAllLevel)
Definition ball_thresholdaggregate.h:273
int triggerAllLevel() const
Return the trigger-all level of this threshold aggregate.
Definition ball_thresholdaggregate.h:266
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
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)