BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlt_iso8601utilparseconfiguration.h
Go to the documentation of this file.
1/// @file bdlt_iso8601utilparseconfiguration.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlt_iso8601utilparseconfiguration.h -*-C++-*-
8#ifndef INCLUDED_BDLT_ISO8601UTILPARSECONFIGURATION
9#define INCLUDED_BDLT_ISO8601UTILPARSECONFIGURATION
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlt_iso8601utilparseconfiguration bdlt_iso8601utilparseconfiguration
15/// @brief Provide an attribute class to configure ISO 8601 string parsing.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlt
19/// @{
20/// @addtogroup bdlt_iso8601utilparseconfiguration
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlt_iso8601utilparseconfiguration-purpose"> Purpose</a>
25/// * <a href="#bdlt_iso8601utilparseconfiguration-classes"> Classes </a>
26/// * <a href="#bdlt_iso8601utilparseconfiguration-description"> Description </a>
27/// * <a href="#bdlt_iso8601utilparseconfiguration-attributes"> Attributes </a>
28/// * <a href="#bdlt_iso8601utilparseconfiguration-usage"> Usage </a>
29///
30/// # Purpose {#bdlt_iso8601utilparseconfiguration-purpose}
31/// Provide an attribute class to configure ISO 8601 string parsing.
32///
33/// # Classes {#bdlt_iso8601utilparseconfiguration-classes}
34///
35/// - bdlt::Iso8601UtilParseConfiguration: config for ISO 8601 string parsing
36///
37/// @see bdlt_iso8601util, bdlt_iso8601utilconfiguration
38///
39/// # Description {#bdlt_iso8601utilparseconfiguration-description}
40/// This component provides an unconstrained (value-semantic)
41/// attribute class, `bdlt::Iso8601UtilParseConfiguration`, that may be used to
42/// configure various aspects of generated ISO 8601 strings.
43///
44/// ## Attributes {#bdlt_iso8601utilparseconfiguration-attributes}
45///
46///
47/// @code
48/// Name Type Default
49/// ---------------- ---- -------
50/// relaxed bool false
51/// basic bool false
52/// @endcode
53/// * `relaxed == false` means that date and time fields of `Datetime`s must
54/// be separated by `t` or `T`. `relaxed == true` means that they may be
55/// separated by `t`, `T`, or ` `.
56/// * `basic == false` means that year, month and day fields within `Date`s
57/// must be separated by `-` and hour, minute, and second fields within
58/// `Time`s must be separated by `:`. `basic == true` means that the fields
59/// within `Date`s and `Time`s must not be separated at all.
60///
61/// Note that in parsing, the `:` between the hour and minute fields of the time
62/// zone is always optional.
63///
64/// ## Usage {#bdlt_iso8601utilparseconfiguration-usage}
65///
66///
67/// This section illustrates intended use of this component.
68///
69/// Our type, `Iso8601UtilParseConfiguration`, has two boolean attributes,
70/// `basic` and `relaxed`.
71/// @code
72/// typedef bdlt::Iso8601UtilParseConfiguration Config;
73/// @endcode
74/// A default configured object has both attributes being `false`:
75/// @code
76/// Config c;
77/// assert(!c.basic());
78/// assert(!c.relaxed());
79/// @endcode
80/// The `setBasic` sets the `basic` attribute, leaves the `relaxed` attribute
81/// alone:
82/// @code
83/// Config c2 = c.setBasic();
84/// assert( c.basic());
85/// assert(!c.relaxed());
86/// @endcode
87/// `setBasic` and `setRelaxed` take a boolean argument that defaults to `true`:
88/// @code
89/// for (int ii = 0; ii < 16; ++ii) {
90/// const bool basic = ii & 1;
91/// const bool relaxed = ii & 2;
92/// const bool basicB = ii & 4;
93/// const bool relaxedB = ii & 8;
94///
95/// // 'c' can have any valid state at this point.
96///
97/// const Config& c3 = c.setBasic(basic);
98/// assert(&c3 != &c); // copy, not reference, returned
99/// const Config& c4 = c.setRelaxed(relaxed);
100/// assert(&c4 != &c); // copy, not reference, returned
101///
102/// assert(c.basic() == basic);
103/// assert(c.relaxed() == relaxed);
104///
105/// c.setRelaxed(relaxedB);
106/// c.setBasic(basicB);
107///
108/// assert(c.relaxed() == relaxedB);
109/// assert(c.basic() == basicB);
110///
111/// Config d = c; // copy 'c' to 'd'
112///
113/// assert(d.relaxed() == relaxedB);
114/// assert(d.basic() == basicB);
115///
116/// assert(d == c);
117/// assert(&d != &c); // 'd' is a copy, not a reference
118///
119/// d.setBasic(); // defaults to 'true'
120/// d.setRelaxed(); // defaults to 'true'
121///
122/// assert(d.basic() == true);
123/// assert(d.relaxed() == true);
124/// }
125/// @endcode
126/// @}
127/** @} */
128/** @} */
129
130/** @addtogroup bdl
131 * @{
132 */
133/** @addtogroup bdlt
134 * @{
135 */
136/** @addtogroup bdlt_iso8601utilparseconfiguration
137 * @{
138 */
139
140#include <bdlscm_version.h>
141
142#include <bsls_assert.h>
143
144#include <bsl_iosfwd.h>
145
146
147namespace bdlt {
148
149 // ====================================
150 // class Iso8601UtilParseConfiguration
151 // ====================================
152
153/// This unconstrained (value-semantic) attribute class characterizes how to
154/// configure certain behavior in `Iso8601Util` functions. See the
155/// @ref bdlt_iso8601utilparseconfiguration-attributes section for information on the class attributes.
156///
157/// See @ref bdlt_iso8601utilparseconfiguration
159
160 private:
161 // DATA
162 bool d_basic;
163 bool d_relaxed;
164
165 // FRIENDS
170
171 public:
172 // CREATORS
173
174 /// Create an `Iso8601UtilParseConfiguration` object having the
175 /// (default) attribute values:
176 /// @code
177 /// relaxed() == false
178 /// basic() == false
179 /// @endcode
181
182 /// Create an `Iso8601UtilParseConfiguration` object having the value of
183 /// the specified `original` configuration.
185 const Iso8601UtilParseConfiguration original) = default;
186
187 /// Destroy this object.
189
190 // MANIPULATORS
191
192 /// Assign to this object the value of the specified `rhs`
193 /// configuration, and return a reference providing modifiable access to
194 /// this object.
195 // Iso8601UtilParseConfiguration& operator=(
196 // const Iso8601UtilParseConfiguration& rhs) = default;
197
198 /// Set the `basic` field of this object to the specified `value` and
199 /// return a copy of this object.
200 Iso8601UtilParseConfiguration setBasic(bool value = true);
201
202 /// Set the `relaxed` field of this object to the specified `value` and
203 /// return a copy of this object.
204 Iso8601UtilParseConfiguration setRelaxed(bool value = true);
205
206 // ACCESSORS
207
208 /// Return `true` if the `basic` field of this object is set and `false`
209 /// otherwise.
210 bool basic() const;
211
212 /// Return `true` if the `relaxed` field of this object is set and
213 /// `false` otherwise.
214 bool relaxed() const;
215
216 // Aspects
217
218 /// Write the value of this object to the specified output `stream` in a
219 /// human-readable format, and return a reference to `stream`.
220 /// Optionally specify an initial indentation `level`, whose absolute
221 /// value is incremented recursively for nested objects. If `level` is
222 /// specified, optionally specify `spacesPerLevel`, whose absolute value
223 /// indicates the number of spaces per indentation level for this and
224 /// all of its nested objects. If `level` is negative, suppress
225 /// indentation of the first line. If `spacesPerLevel` is negative,
226 /// format the entire output on one line, suppressing all but the
227 /// initial indentation (as governed by `level`). If `stream` is not
228 /// valid on entry, this operation has no effect. Note that this
229 /// human-readable format is not fully specified, and can change without
230 /// notice.
231 bsl::ostream& print(bsl::ostream& stream,
232 int level = 0,
233 int spacesPerLevel = 4) const;
234};
235
236// FREE OPERATORS
237
238/// Return `true` if the specified `lhs` and `rhs` objects have the same
239/// value, and `false` otherwise. Two `Iso8601UtilParseConfiguration`
240/// objects have the same value if each of their `basic` and `relaxed`
241/// attributes (respectively) have the same value.
244
245/// Return `true` if the specified `lhs` and `rhs` objects do not have the
246/// same value, and `false` otherwise. Two `Iso8601UtilParseConfiguration`
247/// objects do not have the same value if either of their `basic` or
248/// `relaxed` attributes (respectively) do not have the same value.
251
252/// Write the value of the specified `object` to the specified output
253/// `stream` in a single-line format, and return a reference to `stream`.
254/// If `stream` is not valid on entry, this operation has no effect. Note
255/// that this human-readable format is not fully specified and can change
256/// without notice. Also note that this method has the same behavior as
257/// `object.print(stream, 0, -1)`, but with the attribute names elided.
258bsl::ostream& operator<<(bsl::ostream& stream,
259 const Iso8601UtilParseConfiguration& object);
260
261// ============================================================================
262// INLINE DEFINITIONS
263// ============================================================================
264
265 // -----------------------------------
266 // class Iso8601UtilParseConfiguration
267 // -----------------------------------
268
269// CREATORS
270inline
272: d_basic(false)
273, d_relaxed(false)
274{
275}
276
277inline
280
281// MANIPULATORS
282inline
284 bool value)
285{
286 d_basic = value;
287
288 return *this;
289}
290
291inline
293 bool value)
294{
295 d_relaxed = value;
296
297 return *this;
298}
299
300// ACCESSORS
301inline
303{
304 return d_basic;
305}
306
307inline
309{
310 return d_relaxed;
311}
312
313} // close package namespace
314
315// FREE OPERATORS
316inline
317bool bdlt::operator==(Iso8601UtilParseConfiguration lhs,
318 Iso8601UtilParseConfiguration rhs)
319{
320 return lhs.d_basic == rhs.d_basic && lhs.d_relaxed == rhs.d_relaxed;
321}
322
323inline
324bool bdlt::operator!=(Iso8601UtilParseConfiguration lhs,
325 Iso8601UtilParseConfiguration rhs)
326{
327 return lhs.d_basic != rhs.d_basic || lhs.d_relaxed != rhs.d_relaxed;
328}
329
330
331
332#endif
333
334// ----------------------------------------------------------------------------
335// Copyright 2023 Bloomberg Finance L.P.
336//
337// Licensed under the Apache License, Version 2.0 (the "License");
338// you may not use this file except in compliance with the License.
339// You may obtain a copy of the License at
340//
341// http://www.apache.org/licenses/LICENSE-2.0
342//
343// Unless required by applicable law or agreed to in writing, software
344// distributed under the License is distributed on an "AS IS" BASIS,
345// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
346// See the License for the specific language governing permissions and
347// limitations under the License.
348// ----------------------------- END-OF-FILE ----------------------------------
349
350/** @} */
351/** @} */
352/** @} */
Definition bdlt_iso8601utilparseconfiguration.h:158
bool relaxed() const
Definition bdlt_iso8601utilparseconfiguration.h:308
bool basic() const
Definition bdlt_iso8601utilparseconfiguration.h:302
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
Iso8601UtilParseConfiguration(const Iso8601UtilParseConfiguration original)=default
Iso8601UtilParseConfiguration()
Definition bdlt_iso8601utilparseconfiguration.h:271
~Iso8601UtilParseConfiguration()
Destroy this object.
Definition bdlt_iso8601utilparseconfiguration.h:278
friend bool operator!=(Iso8601UtilParseConfiguration, Iso8601UtilParseConfiguration)
Iso8601UtilParseConfiguration setBasic(bool value=true)
Definition bdlt_iso8601utilparseconfiguration.h:283
Iso8601UtilParseConfiguration setRelaxed(bool value=true)
Definition bdlt_iso8601utilparseconfiguration.h:292
friend bool operator==(Iso8601UtilParseConfiguration, Iso8601UtilParseConfiguration)
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bbldc_basicisma30360.h:112
bool operator==(const Calendar &lhs, const Calendar &rhs)
bsl::ostream & operator<<(bsl::ostream &stream, const Calendar &calendar)
bool operator!=(const Calendar &lhs, const Calendar &rhs)