BDE 4.14.0 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.
132
133 // CLASS METHODS
134
135 /// Load into the specified `level` the value of the `Severity::Level`
136 /// enumerator corresponding to the specified `name` (without regard to
137 /// the case of the characters in `name`). Return 0 on success, and a
138 /// non-zero value with no effect on `level` otherwise. The behavior is
139 /// undefined unless `level` is non-null and `name` is a null-terminated
140 /// (C-style) string. Note that this procedure will fail unless
141 /// `isValidName(name)` is 'true.
142 static int fromAsciiCaseless(Severity::Level *level, const char *name);
143
144 /// Return `true` if the specified `name` corresponds to an enumerator
145 /// in the `Severity::Level` enumeration (without regard to the
146 /// characters in `name`), and `false` otherwise. The behavior is
147 /// undefined unless `name` is a null-terminated (C-style) string. Note
148 /// that the names corresponding to `Severity::Level` enumerators are
149 /// case *insensitive*.
150 static bool isValidNameCaseless(const char *name);
151
152#ifndef BDE_OMIT_INTERNAL_DEPRECATED
153 /// Load into the specified `level` the value of the `Severity::Level`
154 /// enumerator corresponding to the specified `name` (without regard to
155 /// the case of the characters in `name`). Return 0 on success, and a
156 /// non-zero value with no effect on `level` otherwise. The behavior is
157 /// undefined unless `level` is non-null and `name` is a null-terminated
158 /// (C-style) string. Note that this procedure will fail unless
159 /// `isValidName(name)` is `true`.
160 ///
161 /// @deprecated Use @ref fromAsciiCaseless instead.
162 static int fromAscii(Severity::Level *level, const char *name);
163
164 /// Return `true` if the specified `name` corresponds to an enumerator
165 /// in the `Severity::Level` enumeration, and `false` otherwise. The
166 /// behavior is undefined unless `name` is a null-terminated (C-style)
167 /// string. Note that the names corresponding to `Severity::Level`
168 /// enumerators are case *insensitive*.
169 ///
170 /// @deprecated Use @ref isValidNameCaseless instead.
171 static bool isValidName(const char *name);
172#endif // BDE_OMIT_INTERNAL_DEPRECATED
173};
174
175// ============================================================================
176// INLINE DEFINITIONS
177// ============================================================================
178
179 // -------------------
180 // struct SeverityUtil
181 // -------------------
182
183#ifndef BDE_OMIT_INTERNAL_DEPRECATED
184// CLASS METHODS
185inline
186int SeverityUtil::fromAscii(Severity::Level *level, const char *name)
187{
188 return fromAsciiCaseless(level, name);
189}
190
191inline
192bool SeverityUtil::isValidName(const char *name)
193{
194 return isValidNameCaseless(name);
195}
196#endif // BDE_OMIT_INTERNAL_DEPRECATED
197
198} // close package namespace
199
200
201#endif
202
203// ----------------------------------------------------------------------------
204// Copyright 2015 Bloomberg Finance L.P.
205//
206// Licensed under the Apache License, Version 2.0 (the "License");
207// you may not use this file except in compliance with the License.
208// You may obtain a copy of the License at
209//
210// http://www.apache.org/licenses/LICENSE-2.0
211//
212// Unless required by applicable law or agreed to in writing, software
213// distributed under the License is distributed on an "AS IS" BASIS,
214// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
215// See the License for the specific language governing permissions and
216// limitations under the License.
217// ----------------------------- END-OF-FILE ----------------------------------
218
219/** @} */
220/** @} */
221/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition ball_administration.h:214
Definition ball_severityutil.h:131
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:192
static int fromAscii(Severity::Level *level, const char *name)
Definition ball_severityutil.h:186
Level
Definition ball_severity.h:167