BDE 4.39.x Production Release
Loading...
Searching...
No Matches
ball_severityutil.h
Go to the documentation of this file.
1/// @file ball_severityutil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// ball_severityutil.h -*-C++-*-
8#ifndef INCLUDED_BALL_SEVERITYUTIL
9#define INCLUDED_BALL_SEVERITYUTIL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup ball_severityutil ball_severityutil
15/// @brief Provide a suite of utility functions on `ball::Severity` levels.
16/// @addtogroup bal
17/// @{
18/// @addtogroup ball
19/// @{
20/// @addtogroup ball_severityutil
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#ball_severityutil-purpose"> Purpose</a>
25/// * <a href="#ball_severityutil-classes"> Classes </a>
26/// * <a href="#ball_severityutil-description"> Description </a>
27/// * <a href="#ball_severityutil-synopsis"> Synopsis </a>
28/// * <a href="#ball_severityutil-usage"> Usage </a>
29/// * <a href="#ball_severityutil-example-1-basic-usage"> Example 1: Basic Usage </a>
30///
31/// # Purpose {#ball_severityutil-purpose}
32/// Provide a suite of utility functions on `ball::Severity` levels.
33///
34/// # Classes {#ball_severityutil-classes}
35///
36/// - ball::SeverityUtil: namespace for functions on `ball::Severity::Level`
37///
38/// @see ball_severity
39///
40/// # Description {#ball_severityutil-description}
41/// This component provides a suite of pure procedures that apply
42/// to the `ball::Severity::Level` enumeration. In particular, the
43/// `ball::SeverityUtil` `struct` provides a `fromAsciiCaseless` function that
44/// returns the `ball::Severity::Level` enumerator value corresponding to a
45/// given ASCII string (without regard to the case of the characters in the
46/// string) and an `isValidNameCaseless` function that confirms that a given
47/// string corresponds to one of the enumerators in the `ball::Severity::Level`
48/// enumeration (similarly, without regard to the case of the characters in the
49/// string).
50///
51/// ## Synopsis {#ball_severityutil-synopsis}
52///
53///
54/// The following is a list of functions available in this component:
55/// @code
56/// static int ball::SeverityUtil::fromAsciiCaseless(
57/// ball::Severity::Level *level,
58/// const char *name);
59///
60/// static bool ball::SeverityUtil::isValidNameCaseless(const char *name);
61/// @endcode
62///
63/// ## Usage {#ball_severityutil-usage}
64///
65///
66/// This section illustrates intended use of this component.
67///
68/// ### Example 1: Basic Usage {#ball_severityutil-example-1-basic-usage}
69///
70///
71/// In this example, we show how to validate that a set of C-style strings
72/// correspond to `ball::Severity::Level` enumerators, and then use those
73/// strings to generate enumerator values that, in turn, may be used to
74/// administer a logger manager. Here, for convenience, we define our strings
75/// in an array, much as how we might receive them from a command line:
76/// @code
77/// const char *argv[] = {
78/// "INFO", // record
79/// "WARN", // pass
80/// "ERROR", // trigger
81/// "FATAL" // trigger-all
82/// };
83///
84/// assert(ball::SeverityUtil::isValidNameCaseless(argv[0]));
85/// assert(ball::SeverityUtil::isValidNameCaseless(argv[1]));
86/// assert(ball::SeverityUtil::isValidNameCaseless(argv[2]));
87/// assert(ball::SeverityUtil::isValidNameCaseless(argv[3]));
88///
89/// ball::Severity::Level record;
90/// ball::Severity::Level pass;
91/// ball::Severity::Level trigger;
92/// ball::Severity::Level triggerAll;
93///
94/// assert(0 == ball::SeverityUtil::fromAsciiCaseless(&record, argv[0]));
95/// assert(0 == ball::SeverityUtil::fromAsciiCaseless(&pass, argv[1]));
96/// assert(0 == ball::SeverityUtil::fromAsciiCaseless(&trigger, argv[2]));
97/// assert(0 == ball::SeverityUtil::fromAsciiCaseless(&triggerAll, argv[3]));
98///
99/// assert(ball::Severity::e_INFO == record);
100/// assert(ball::Severity::e_WARN == pass);
101/// assert(ball::Severity::e_ERROR == trigger);
102/// assert(ball::Severity::e_FATAL == triggerAll);
103/// @endcode
104/// @}
105/** @} */
106/** @} */
107
108/** @addtogroup bal
109 * @{
110 */
111/** @addtogroup ball
112 * @{
113 */
114/** @addtogroup ball_severityutil
115 * @{
116 */
117
118#include <balscm_version.h>
119
120#include <ball_severity.h>
121
122
123namespace ball {
124
125 // ===================
126 // struct SeverityUtil
127 // ===================
128
129/// This `struct` provides a namespace for non-primitive procedures on the
130/// `Severity::Level` enumeration.
131///
132/// See @ref ball_severityutil
134
135 // CLASS METHODS
136
137 /// Load into the specified `level` the value of the `Severity::Level`
138 /// enumerator corresponding to the specified `name` (without regard to
139 /// the case of the characters in `name`). Return 0 on success, and a
140 /// non-zero value with no effect on `level` otherwise.
141 ///
142 /// \pre The behavior is undefined unless `level` is non-null and `name` is a null-terminated (C-style) string.
143 ///
144 /// \note Note that this procedure will fail unless
145 /// `isValidName(name)` is 'true.
146 static int fromAsciiCaseless(Severity::Level *level, const char *name);
147
148 /// Return `true` if the specified `name` corresponds to an enumerator
149 /// in the `Severity::Level` enumeration (without regard to the
150 /// characters in `name`), and `false` otherwise.
151 ///
152 /// \pre The behavior is undefined unless `name` is a null-terminated (C-style) string.
153 ///
154 /// \note Note that the names corresponding to `Severity::Level` enumerators are
155 /// case *insensitive*.
156 static bool isValidNameCaseless(const char *name);
157
158#ifndef BDE_OMIT_INTERNAL_DEPRECATED
159 /// Load into the specified `level` the value of the `Severity::Level`
160 /// enumerator corresponding to the specified `name` (without regard to
161 /// the case of the characters in `name`). Return 0 on success, and a
162 /// non-zero value with no effect on `level` otherwise.
163 ///
164 /// \pre The behavior is undefined unless `level` is non-null and `name` is a null-terminated (C-style) string.
165 ///
166 /// \note Note that this procedure will fail unless
167 /// `isValidName(name)` is `true`.
168 ///
169 /// @deprecated Use @ref fromAsciiCaseless instead.
170 static int fromAscii(Severity::Level *level, const char *name);
171
172 /// Return `true` if the specified `name` corresponds to an enumerator
173 /// in the `Severity::Level` enumeration, and `false` otherwise.
174 ///
175 /// \pre The behavior is undefined unless `name` is a null-terminated (C-style) string.
176 ///
177 /// \note Note that the names corresponding to `Severity::Level`
178 /// enumerators are case *insensitive*.
179 ///
180 /// @deprecated Use @ref isValidNameCaseless instead.
181 static bool isValidName(const char *name);
182#endif // BDE_OMIT_INTERNAL_DEPRECATED
183};
184
185// ============================================================================
186// INLINE DEFINITIONS
187// ============================================================================
188
189 // -------------------
190 // struct SeverityUtil
191 // -------------------
192
193#ifndef BDE_OMIT_INTERNAL_DEPRECATED
194// CLASS METHODS
195inline
196int SeverityUtil::fromAscii(Severity::Level *level, const char *name)
197{
198 return fromAsciiCaseless(level, name);
199}
200
201inline
202bool SeverityUtil::isValidName(const char *name)
203{
204 return isValidNameCaseless(name);
205}
206#endif // BDE_OMIT_INTERNAL_DEPRECATED
207
208} // close package namespace
209
210
211#endif
212
213// ----------------------------------------------------------------------------
214// Copyright 2015 Bloomberg Finance L.P.
215//
216// Licensed under the Apache License, Version 2.0 (the "License");
217// you may not use this file except in compliance with the License.
218// You may obtain a copy of the License at
219//
220// http://www.apache.org/licenses/LICENSE-2.0
221//
222// Unless required by applicable law or agreed to in writing, software
223// distributed under the License is distributed on an "AS IS" BASIS,
224// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
225// See the License for the specific language governing permissions and
226// limitations under the License.
227// ----------------------------- END-OF-FILE ----------------------------------
228
229/** @} */
230/** @} */
231/** @} */
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition ball_administration.h:214
Definition ball_severityutil.h:133
static int fromAsciiCaseless(Severity::Level *level, const char *name)
static bool isValidNameCaseless(const char *name)
static bool isValidName(const char *name)
Definition ball_severityutil.h:202
static int fromAscii(Severity::Level *level, const char *name)
Definition ball_severityutil.h:196
Level
Definition ball_severity.h:172