BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlt_fixutilconfiguration.h
Go to the documentation of this file.
1/// @file bdlt_fixutilconfiguration.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlt_fixutilconfiguration.h -*-C++-*-
8#ifndef INCLUDED_BDLT_FIXUTILCONFIGURATION
9#define INCLUDED_BDLT_FIXUTILCONFIGURATION
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlt_fixutilconfiguration bdlt_fixutilconfiguration
15/// @brief Provide an attribute class to configure FIX string generation.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlt
19/// @{
20/// @addtogroup bdlt_fixutilconfiguration
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlt_fixutilconfiguration-purpose"> Purpose</a>
25/// * <a href="#bdlt_fixutilconfiguration-classes"> Classes </a>
26/// * <a href="#bdlt_fixutilconfiguration-description"> Description </a>
27/// * <a href="#bdlt_fixutilconfiguration-attributes"> Attributes </a>
28/// * <a href="#bdlt_fixutilconfiguration-default-configuration"> Default Configuration </a>
29/// * <a href="#bdlt_fixutilconfiguration-usage"> Usage </a>
30/// * <a href="#bdlt_fixutilconfiguration-example-1-configuring-fix-string-generation"> Example 1: Configuring FIX String Generation </a>
31/// * <a href="#bdlt_fixutilconfiguration-example-2-setting-the-process-wide-default-configuration"> Example 2: Setting the Process-Wide Default Configuration </a>
32///
33/// # Purpose {#bdlt_fixutilconfiguration-purpose}
34/// Provide an attribute class to configure FIX string generation.
35///
36/// # Classes {#bdlt_fixutilconfiguration-classes}
37///
38/// - bdlt::FixUtilConfiguration: configuration for FIX strings
39///
40/// @see bdlt_fixutil
41///
42/// # Description {#bdlt_fixutilconfiguration-description}
43/// This component provides an unconstrained (value-semantic)
44/// attribute class, `bdlt::FixUtilConfiguration`, that may be used to configure
45/// various aspects of generated FIX strings.
46///
47/// ## Attributes {#bdlt_fixutilconfiguration-attributes}
48///
49///
50///
51/// | Name | Type | Default |
52/// | ------------------------- | ---- | ------- |
53/// | fractionalSecondPrecision | int | 3 |
54/// | useZAbbreviationForUtc | bool | false |
55///
56/// * `fractionalSecondPrecision`: number of digits used to represent
57/// fractional seconds; must be in the range `0 .. 6`.
58/// * `useZAbbreviationForUtc`: `true` if `Z` should be used for the timezone
59/// offset instead of `+00:00` (specific to UTC).
60///
61/// ## Default Configuration {#bdlt_fixutilconfiguration-default-configuration}
62///
63///
64/// This component also provides a (process-wide) default configuration that may
65/// be set and retrieved via the `setDefaultConfiguration` and
66/// `defaultConfiguration` class methods, respectively. See Usage Example 2 for
67/// further details.
68///
69/// ## Usage {#bdlt_fixutilconfiguration-usage}
70///
71///
72/// This section illustrates intended use of this component.
73///
74/// ### Example 1: Configuring FIX String Generation {#bdlt_fixutilconfiguration-example-1-configuring-fix-string-generation}
75///
76///
77/// This example demonstrates creation of a `bdlt::FixUtilConfiguration` object
78/// that may be used to influence the format of the output produced by a
79/// hypothetical utility, `my::FixUtil`, that generates and parses FIX strings
80/// for `bdlt` vocabulary types (see @ref bdlt_fixutil , which provides just such
81/// functionality). In particular, suppose that given a sample
82/// `bdlt::DatetimeTz` object:
83/// @code
84/// const bdlt::DatetimeTz datetimeTz(
85/// bdlt::Datetime(2005, 1, 31, 8, 59, 59, 123), 0);
86/// @endcode
87/// `my::FixUtil` produces, by default, the following string (which is a valid
88/// FIX string):
89/// @code
90/// 20050131-08:59:59.123+00:00
91/// @endcode
92/// However, we would like to produce the following (also valid FIX) string
93/// instead:
94/// @code
95/// 20050131-08:59:59.123000Z
96/// @endcode
97/// `bdlt::FixUtilConfiguration` can be used to obtain the desired result
98/// assuming that `my::FixUtil` uses `bdlt::FixUtilConfiguration` to affect the
99/// format of generated strings in this fashion (e.g., again see
100/// @ref bdlt_fixutil ).
101///
102/// First, we construct a `bdlt::FixUtilConfiguration` object that has the
103/// default value:
104/// @code
105/// bdlt::FixUtilConfiguration configuration;
106/// assert( configuration.fractionalSecondPrecision() == 3);
107/// assert(!configuration.useZAbbreviationForUtc());
108/// @endcode
109/// Then, we modify `configuration` to indicate that we want to use 6 digits of
110/// precision in the fractional seconds:
111/// @code
112/// configuration.setFractionalSecondPrecision(6);
113/// assert( configuration.fractionalSecondPrecision() == 6);
114/// assert(!configuration.useZAbbreviationForUtc());
115/// @endcode
116/// Finally, we modify `configuration` to indicate that we want to use `Z` as an
117/// abbreviation for UTC:
118/// @code
119/// configuration.setUseZAbbreviationForUtc(true);
120/// assert( configuration.fractionalSecondPrecision() == 6);
121/// assert( configuration.useZAbbreviationForUtc());
122/// @endcode
123/// Our `configuration` object can now be supplied to `my::FixUtil` to produce
124/// the desired result.
125///
126/// ### Example 2: Setting the Process-Wide Default Configuration {#bdlt_fixutilconfiguration-example-2-setting-the-process-wide-default-configuration}
127///
128///
129/// This example demonstrates how to establish the process-wide default
130/// configuration.
131///
132/// First, we retrieve the default configuration in effect at process start-up
133/// and note that it has the default-constructed value:
134/// @code
135/// bdlt::FixUtilConfiguration configuration =
136/// bdlt::FixUtilConfiguration::defaultConfiguration();
137/// assert(bdlt::FixUtilConfiguration() == configuration);
138/// assert( configuration.fractionalSecondPrecision() == 3);
139/// assert(!configuration.useZAbbreviationForUtc());
140/// @endcode
141/// Next, we modify `configuration` to indicate that we want to output `Z` when
142/// the timezone offset is UTC (i.e., instead of `+00:00`):
143/// @code
144/// configuration.setUseZAbbreviationForUtc(true);
145/// assert( configuration.fractionalSecondPrecision() == 3);
146/// assert( configuration.useZAbbreviationForUtc());
147/// @endcode
148/// Then, we modify `configuration` to display milliseconds:
149/// @code
150/// configuration.setFractionalSecondPrecision(6);
151/// assert( configuration.fractionalSecondPrecision() == 6);
152/// assert( configuration.useZAbbreviationForUtc());
153/// @endcode
154/// Now, we set the default configuration to the value of our `configuration`
155/// object:
156/// @code
157/// bdlt::FixUtilConfiguration::setDefaultConfiguration(configuration);
158/// @endcode
159/// Finally, we verify that the default configuration was updated as expected:
160/// @code
161/// const bdlt::FixUtilConfiguration newConfiguration =
162/// bdlt::FixUtilConfiguration::defaultConfiguration();
163/// assert( newConfiguration.fractionalSecondPrecision() == 6);
164/// assert( newConfiguration.useZAbbreviationForUtc());
165/// @endcode
166/// Note that the expected usage is that the process-wide configuration will be
167/// established *once*, early in `main`, and not changed throughout the lifetime
168/// of a process.
169/// @}
170/** @} */
171/** @} */
172
173/** @addtogroup bdl
174 * @{
175 */
176/** @addtogroup bdlt
177 * @{
178 */
179/** @addtogroup bdlt_fixutilconfiguration
180 * @{
181 */
182
183#include <bdlscm_version.h>
184
185#include <bsls_assert.h>
187#include <bsls_review.h>
188
189#include <bsl_iosfwd.h>
190
191
192namespace bdlt {
193
194 // ==========================
195 // class FixUtilConfiguration
196 // ==========================
197
198/// This unconstrained (value-semantic) attribute class characterizes how to
199/// configure certain behavior in `FixUtil` functions. Currently, only the
200/// `generate` and `generateRaw` methods of that utility are affected by
201/// `FixUtilConfiguration` settings. See the @ref bdlt_fixutilconfiguration-attributes section for
202/// information on the class attributes.
203///
204/// See @ref bdlt_fixutilconfiguration
206
207 private:
208 // PRIVATE TYPES
209
210 /// This enumeration denotes the distinct bits that define the values of
211 /// each of the two configuration attributes.
212 enum {
213 k_FRACTIONAL_SECOND_PRECISION_MASK = 0x07,
214 k_USE_Z_ABBREVIATION_FOR_UTC_BIT = 0x08
215 };
216
217 // CLASS DATA
218 static bsls::AtomicOperations::AtomicTypes::Int
219 s_defaultConfiguration; // process-wide configuration
220
221 // DATA
222 int d_configurationMask; // bitmask defining configuration
223
224 // FRIENDS
226 const FixUtilConfiguration&);
228 const FixUtilConfiguration&);
229
230 private:
231 // PRIVATE CREATORS
232
233 /// Create a `FixUtilConfiguration` object having the value indicated by the specified `configurationMask`.
234 ///
235 /// \pre The behavior is undefined unless
236 /// `configurationMask` represents a valid `FixUtilConfiguration` value.
237 explicit FixUtilConfiguration(int configurationMask);
238
239 public:
240 // CLASS METHODS
241
242 /// Return the value of the process-wide `FixUtilConfiguration` that is
243 /// currently in effect.
245
246 /// Set the value of the process-wide `FixUtilConfiguration` to the specified `configuration`.
247 ///
248 /// \note Note that the expected usage is that the
249 /// process-wide configuration will be established *once*, early in
250 /// `main`, and not changed throughout the lifetime of a process.
251 static void setDefaultConfiguration(
252 const FixUtilConfiguration& configuration);
253
254 // CREATORS
255
256 /// Create a `FixUtilConfiguration` object having the (default)
257 /// attribute values:
258 /// @code
259 /// fractionalSecondPrecision() == 3
260 /// useZAbbreviationForUtc() == false
261 /// @endcode
263
264 /// Create a `FixUtilConfiguration` object having the value of the
265 /// specified `original` configuration.
267
268 /// Destroy this object.
270
271 // MANIPULATORS
272
273 /// Assign to this object the value of the specified `rhs`
274 /// configuration, and return a reference providing modifiable access to
275 /// this object.
277
278 /// Set the `fractionalSecondPrecision` attribute of this object to the specified `value`.
279 ///
280 /// \pre The behavior is undefined unless `0 <= value` and `6 >= value`.
281 ///
282 /// \note Note that the FIX protocol allows for much higher
283 /// precision.
285
286 /// Set the `useZAbbreviationForUtc` attribute of this object to the
287 /// specified `value`.
289
290 // ACCESSORS
291
292 /// Return the value of the `fractionalSecondPrecision` attribute of
293 /// this object.
294 int fractionalSecondPrecision() const;
295
296 /// Return the value of the `useZAbbreviationForUtc` attribute of this
297 /// object.
298 bool useZAbbreviationForUtc() const;
299
300 // Aspects
301
302 /// Write the value of this object to the specified output `stream` in a
303 /// human-readable format, and return a reference to `stream`.
304 /// Optionally specify an initial indentation `level`, whose absolute
305 /// value is incremented recursively for nested objects. If `level` is
306 /// specified, optionally specify `spacesPerLevel`, whose absolute value
307 /// indicates the number of spaces per indentation level for this and
308 /// all of its nested objects. If `level` is negative, suppress
309 /// indentation of the first line. If `spacesPerLevel` is negative,
310 /// format the entire output on one line, suppressing all but the
311 /// initial indentation (as governed by `level`). If `stream` is not valid on entry, this operation has no effect.
312 ///
313 /// \note Note that this
314 /// human-readable format is not fully specified, and can change without
315 /// notice.
316 bsl::ostream& print(bsl::ostream& stream,
317 int level = 0,
318 int spacesPerLevel = 4) const;
319};
320
321// FREE OPERATORS
322
323/// Return `true` if the specified `lhs` and `rhs` objects have the same
324/// value, and `false` otherwise. Two `FixUtilConfiguration` objects have
325/// the same value if each of their `fractionalSecondPrecision` and
326/// `useZAbbreviationForUtc` attributes (respectively) have the same value.
327bool operator==(const FixUtilConfiguration& lhs,
328 const FixUtilConfiguration& rhs);
329
330/// Return `true` if the specified `lhs` and `rhs` objects do not have the
331/// same value, and `false` otherwise. Two `FixUtilConfiguration` objects
332/// do not have the same value if any of their `fractionalSecondPrecision`
333/// or `useZAbbreviationForUtc` attributes (respectively) do not have the
334/// same value.
335bool operator!=(const FixUtilConfiguration& lhs,
336 const FixUtilConfiguration& rhs);
337
338/// Write the value of the specified `object` to the specified output
339/// `stream` in a single-line format, and return a reference to `stream`.
340/// If `stream` is not valid on entry, this operation has no effect.
341///
342/// \note Note that this human-readable format is not fully specified and can change
343/// without notice. Also note that this method has the same behavior as
344/// `object.print(stream, 0, -1)`, but with the attribute names elided.
345bsl::ostream& operator<<(bsl::ostream& stream,
346 const FixUtilConfiguration& object);
347
348// ============================================================================
349// INLINE DEFINITIONS
350// ============================================================================
351
352 // --------------------------
353 // class FixUtilConfiguration
354 // --------------------------
355
356// PRIVATE CREATORS
357inline
359: d_configurationMask(configurationMask)
360{
361 BSLS_ASSERT(0 == (configurationMask
362 & ~(k_FRACTIONAL_SECOND_PRECISION_MASK
363 | k_USE_Z_ABBREVIATION_FOR_UTC_BIT)));
364}
365
366// CLASS METHODS
367inline
368FixUtilConfiguration FixUtilConfiguration::defaultConfiguration()
369{
371 bsls::AtomicOperations::getIntRelaxed(&s_defaultConfiguration));
372}
373
374inline
375void FixUtilConfiguration::setDefaultConfiguration(
376 const FixUtilConfiguration& configuration)
377{
378 bsls::AtomicOperations::setIntRelaxed(&s_defaultConfiguration,
379 configuration.d_configurationMask);
380}
381
382// CREATORS
383inline
384FixUtilConfiguration::FixUtilConfiguration()
385: d_configurationMask(3)
386{
387}
388
389inline
391 const FixUtilConfiguration& original)
392: d_configurationMask(original.d_configurationMask)
393{
394}
395
396inline
398{
399 BSLS_ASSERT(0 == (d_configurationMask
400 & ~(k_FRACTIONAL_SECOND_PRECISION_MASK
401 | k_USE_Z_ABBREVIATION_FOR_UTC_BIT)));
402}
403
404// MANIPULATORS
405inline
407 const FixUtilConfiguration& rhs)
408{
409 d_configurationMask = rhs.d_configurationMask;
410
411 return *this;
412}
413
414// ACCESSORS
415inline
417{
418 return d_configurationMask & k_FRACTIONAL_SECOND_PRECISION_MASK;
419}
420
421inline
423{
424 return d_configurationMask & k_USE_Z_ABBREVIATION_FOR_UTC_BIT;
425}
426
427} // close package namespace
428
429// FREE OPERATORS
430inline
431bool bdlt::operator==(const FixUtilConfiguration& lhs,
432 const FixUtilConfiguration& rhs)
433{
434 return lhs.d_configurationMask == rhs.d_configurationMask;
435}
436
437inline
438bool bdlt::operator!=(const FixUtilConfiguration& lhs,
439 const FixUtilConfiguration& rhs)
440{
441 return lhs.d_configurationMask != rhs.d_configurationMask;
442}
443
444
445
446#endif
447
448// ----------------------------------------------------------------------------
449// Copyright 2016 Bloomberg Finance L.P.
450//
451// Licensed under the Apache License, Version 2.0 (the "License");
452// you may not use this file except in compliance with the License.
453// You may obtain a copy of the License at
454//
455// http://www.apache.org/licenses/LICENSE-2.0
456//
457// Unless required by applicable law or agreed to in writing, software
458// distributed under the License is distributed on an "AS IS" BASIS,
459// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
460// See the License for the specific language governing permissions and
461// limitations under the License.
462// ----------------------------- END-OF-FILE ----------------------------------
463
464/** @} */
465/** @} */
466/** @} */
Definition bdlt_fixutilconfiguration.h:205
bool useZAbbreviationForUtc() const
Definition bdlt_fixutilconfiguration.h:422
void setFractionalSecondPrecision(int value)
static void setDefaultConfiguration(const FixUtilConfiguration &configuration)
Definition bdlt_fixutilconfiguration.h:375
friend bool operator!=(const FixUtilConfiguration &, const FixUtilConfiguration &)
~FixUtilConfiguration()
Destroy this object.
Definition bdlt_fixutilconfiguration.h:397
friend bool operator==(const FixUtilConfiguration &, const FixUtilConfiguration &)
FixUtilConfiguration & operator=(const FixUtilConfiguration &rhs)
Definition bdlt_fixutilconfiguration.h:406
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
FixUtilConfiguration()
Definition bdlt_fixutilconfiguration.h:384
void setUseZAbbreviationForUtc(bool value)
static FixUtilConfiguration defaultConfiguration()
Definition bdlt_fixutilconfiguration.h:368
int fractionalSecondPrecision() const
Definition bdlt_fixutilconfiguration.h:416
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
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)
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
ALLOCATOR & lhs
Definition bslstl_string.h:3917
static void setIntRelaxed(AtomicTypes::Int *atomicInt, int value)
Definition bsls_atomicoperations.h:1554
static int getIntRelaxed(AtomicTypes::Int const *atomicInt)
Definition bsls_atomicoperations.h:1536