BDE 4.14.0 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/// @code
51/// Name Type Default
52/// ------------------------- ---- -------
53/// fractionalSecondPrecision int 3
54/// useZAbbreviationForUtc bool false
55/// @endcode
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 Attributes section under
202/// @DESCRIPTION in the component-level documentation for information on the
203/// class attributes.
204///
205/// See @ref bdlt_fixutilconfiguration
207
208 private:
209 // PRIVATE TYPES
210
211 /// This enumeration denotes the distinct bits that define the values of
212 /// each of the two configuration attributes.
213 enum {
214 k_FRACTIONAL_SECOND_PRECISION_MASK = 0x07,
215 k_USE_Z_ABBREVIATION_FOR_UTC_BIT = 0x08
216 };
217
218 // CLASS DATA
219 static bsls::AtomicOperations::AtomicTypes::Int
220 s_defaultConfiguration; // process-wide configuration
221
222 // DATA
223 int d_configurationMask; // bitmask defining configuration
224
225 // FRIENDS
227 const FixUtilConfiguration&);
229 const FixUtilConfiguration&);
230
231 private:
232 // PRIVATE CREATORS
233
234 /// Create a `FixUtilConfiguration` object having the value indicated by
235 /// the specified `configurationMask`. 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
247 /// specified `configuration`. Note that the expected usage is that the
248 /// process-wide configuration will be established *once*, early in
249 /// `main`, and not changed throughout the lifetime of a process.
250 static void setDefaultConfiguration(
251 const FixUtilConfiguration& configuration);
252
253 // CREATORS
254
255 /// Create a `FixUtilConfiguration` object having the (default)
256 /// attribute values:
257 /// @code
258 /// fractionalSecondPrecision() == 3
259 /// useZAbbreviationForUtc() == false
260 /// @endcode
262
263 /// Create a `FixUtilConfiguration` object having the value of the
264 /// specified `original` configuration.
266
267 /// Destroy this object.
269
270 // MANIPULATORS
271
272 /// Assign to this object the value of the specified `rhs`
273 /// configuration, and return a reference providing modifiable access to
274 /// this object.
276
277 /// Set the `fractionalSecondPrecision` attribute of this object to the
278 /// specified `value`. The behavior is undefined unless `0 <= value`
279 /// and `6 >= value`. Note that the FIX protocol allows for much higher
280 /// precision.
282
283 /// Set the `useZAbbreviationForUtc` attribute of this object to the
284 /// specified `value`.
286
287 // ACCESSORS
288
289 /// Return the value of the `fractionalSecondPrecision` attribute of
290 /// this object.
291 int fractionalSecondPrecision() const;
292
293 /// Return the value of the `useZAbbreviationForUtc` attribute of this
294 /// object.
295 bool useZAbbreviationForUtc() const;
296
297 // Aspects
298
299 /// Write the value of this object to the specified output `stream` in a
300 /// human-readable format, and return a reference to `stream`.
301 /// Optionally specify an initial indentation `level`, whose absolute
302 /// value is incremented recursively for nested objects. If `level` is
303 /// specified, optionally specify `spacesPerLevel`, whose absolute value
304 /// indicates the number of spaces per indentation level for this and
305 /// all of its nested objects. If `level` is negative, suppress
306 /// indentation of the first line. If `spacesPerLevel` is negative,
307 /// format the entire output on one line, suppressing all but the
308 /// initial indentation (as governed by `level`). If `stream` is not
309 /// valid on entry, this operation has no effect. Note that this
310 /// human-readable format is not fully specified, and can change without
311 /// notice.
312 bsl::ostream& print(bsl::ostream& stream,
313 int level = 0,
314 int spacesPerLevel = 4) const;
315};
316
317// FREE OPERATORS
318
319/// Return `true` if the specified `lhs` and `rhs` objects have the same
320/// value, and `false` otherwise. Two `FixUtilConfiguration` objects have
321/// the same value if each of their `fractionalSecondPrecision` and
322/// `useZAbbreviationForUtc` attributes (respectively) have the same value.
323bool operator==(const FixUtilConfiguration& lhs,
324 const FixUtilConfiguration& rhs);
325
326/// Return `true` if the specified `lhs` and `rhs` objects do not have the
327/// same value, and `false` otherwise. Two `FixUtilConfiguration` objects
328/// do not have the same value if any of their `fractionalSecondPrecision`
329/// or `useZAbbreviationForUtc` attributes (respectively) do not have the
330/// same value.
331bool operator!=(const FixUtilConfiguration& lhs,
332 const FixUtilConfiguration& rhs);
333
334/// Write the value of the specified `object` to the specified output
335/// `stream` in a single-line format, and return a reference to `stream`.
336/// If `stream` is not valid on entry, this operation has no effect. Note
337/// that this human-readable format is not fully specified and can change
338/// without notice. Also note that this method has the same behavior as
339/// `object.print(stream, 0, -1)`, but with the attribute names elided.
340bsl::ostream& operator<<(bsl::ostream& stream,
341 const FixUtilConfiguration& object);
342
343// ============================================================================
344// INLINE DEFINITIONS
345// ============================================================================
346
347 // --------------------------
348 // class FixUtilConfiguration
349 // --------------------------
350
351// PRIVATE CREATORS
352inline
354: d_configurationMask(configurationMask)
355{
356 BSLS_ASSERT(0 == (configurationMask
357 & ~(k_FRACTIONAL_SECOND_PRECISION_MASK
358 | k_USE_Z_ABBREVIATION_FOR_UTC_BIT)));
359}
360
361// CLASS METHODS
362inline
363FixUtilConfiguration FixUtilConfiguration::defaultConfiguration()
364{
366 bsls::AtomicOperations::getIntRelaxed(&s_defaultConfiguration));
367}
368
369inline
370void FixUtilConfiguration::setDefaultConfiguration(
371 const FixUtilConfiguration& configuration)
372{
373 bsls::AtomicOperations::setIntRelaxed(&s_defaultConfiguration,
374 configuration.d_configurationMask);
375}
376
377// CREATORS
378inline
379FixUtilConfiguration::FixUtilConfiguration()
380: d_configurationMask(3)
381{
382}
383
384inline
386 const FixUtilConfiguration& original)
387: d_configurationMask(original.d_configurationMask)
388{
389}
390
391inline
393{
394 BSLS_ASSERT(0 == (d_configurationMask
395 & ~(k_FRACTIONAL_SECOND_PRECISION_MASK
396 | k_USE_Z_ABBREVIATION_FOR_UTC_BIT)));
397}
398
399// MANIPULATORS
400inline
402 const FixUtilConfiguration& rhs)
403{
404 d_configurationMask = rhs.d_configurationMask;
405
406 return *this;
407}
408
409// ACCESSORS
410inline
412{
413 return d_configurationMask & k_FRACTIONAL_SECOND_PRECISION_MASK;
414}
415
416inline
418{
419 return d_configurationMask & k_USE_Z_ABBREVIATION_FOR_UTC_BIT;
420}
421
422} // close package namespace
423
424// FREE OPERATORS
425inline
426bool bdlt::operator==(const FixUtilConfiguration& lhs,
427 const FixUtilConfiguration& rhs)
428{
429 return lhs.d_configurationMask == rhs.d_configurationMask;
430}
431
432inline
433bool bdlt::operator!=(const FixUtilConfiguration& lhs,
434 const FixUtilConfiguration& rhs)
435{
436 return lhs.d_configurationMask != rhs.d_configurationMask;
437}
438
439
440
441#endif
442
443// ----------------------------------------------------------------------------
444// Copyright 2016 Bloomberg Finance L.P.
445//
446// Licensed under the Apache License, Version 2.0 (the "License");
447// you may not use this file except in compliance with the License.
448// You may obtain a copy of the License at
449//
450// http://www.apache.org/licenses/LICENSE-2.0
451//
452// Unless required by applicable law or agreed to in writing, software
453// distributed under the License is distributed on an "AS IS" BASIS,
454// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
455// See the License for the specific language governing permissions and
456// limitations under the License.
457// ----------------------------- END-OF-FILE ----------------------------------
458
459/** @} */
460/** @} */
461/** @} */
Definition bdlt_fixutilconfiguration.h:206
bool useZAbbreviationForUtc() const
Definition bdlt_fixutilconfiguration.h:417
void setFractionalSecondPrecision(int value)
static void setDefaultConfiguration(const FixUtilConfiguration &configuration)
Definition bdlt_fixutilconfiguration.h:370
friend bool operator!=(const FixUtilConfiguration &, const FixUtilConfiguration &)
~FixUtilConfiguration()
Destroy this object.
Definition bdlt_fixutilconfiguration.h:392
friend bool operator==(const FixUtilConfiguration &, const FixUtilConfiguration &)
FixUtilConfiguration & operator=(const FixUtilConfiguration &rhs)
Definition bdlt_fixutilconfiguration.h:401
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
FixUtilConfiguration()
Definition bdlt_fixutilconfiguration.h:379
void setUseZAbbreviationForUtc(bool value)
static FixUtilConfiguration defaultConfiguration()
Definition bdlt_fixutilconfiguration.h:363
int fractionalSecondPrecision() const
Definition bdlt_fixutilconfiguration.h:411
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#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)
static void setIntRelaxed(AtomicTypes::Int *atomicInt, int value)
Definition bsls_atomicoperations.h:1552
static int getIntRelaxed(AtomicTypes::Int const *atomicInt)
Definition bsls_atomicoperations.h:1534