BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlt_fixutil.h
Go to the documentation of this file.
1/// @file bdlt_fixutil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlt_fixutil.h -*-C++-*-
8
9#ifndef INCLUDED_BDLT_FIXUTIL
10#define INCLUDED_BDLT_FIXUTIL
11
12#include <bsls_ident.h>
13BSLS_IDENT("$Id: $")
14
15/// @defgroup bdlt_fixutil bdlt_fixutil
16/// @brief Provide conversions between date/time objects and FIX strings.
17/// @addtogroup bdl
18/// @{
19/// @addtogroup bdlt
20/// @{
21/// @addtogroup bdlt_fixutil
22/// @{
23///
24/// <h1> Outline </h1>
25/// * <a href="#bdlt_fixutil-purpose"> Purpose</a>
26/// * <a href="#bdlt_fixutil-classes"> Classes </a>
27/// * <a href="#bdlt_fixutil-description"> Description </a>
28/// * <a href="#bdlt_fixutil-terminology"> Terminology </a>
29/// * <a href="#bdlt_fixutil-fix-string-generation"> FIX String Generation </a>
30/// * <a href="#bdlt_fixutil-configuration"> Configuration </a>
31/// * <a href="#bdlt_fixutil-fix-string-parsing"> FIX String Parsing </a>
32/// * <a href="#bdlt_fixutil-timezone-offsets"> Timezone Offsets </a>
33/// * <a href="#bdlt_fixutil-fractional-seconds"> Fractional Seconds </a>
34/// * <a href="#bdlt_fixutil-leap-seconds"> Leap Seconds </a>
35/// * <a href="#bdlt_fixutil-the-time-24-00"> The Time 24:00 </a>
36/// * <a href="#bdlt_fixutil-summary-of-supported-fix-representations"> Summary of Supported FIX Representations </a>
37/// * <a href="#bdlt_fixutil-usage"> Usage </a>
38/// * <a href="#bdlt_fixutil-example-1-basic-bdlt-fixutil-usage"> Example 1: Basic bdlt::FixUtil Usage </a>
39/// * <a href="#bdlt_fixutil-example-2-configuring-fix-string-generation"> Example 2: Configuring FIX String Generation </a>
40///
41/// # Purpose {#bdlt_fixutil-purpose}
42/// Provide conversions between date/time objects and FIX strings.
43///
44/// # Classes {#bdlt_fixutil-classes}
45///
46/// - bdlt::FixUtil: namespace for FIX date/time conversion functions
47///
48/// @see bdlt_fixutilconfiguration
49///
50/// # Description {#bdlt_fixutil-description}
51/// This component provides a namespace, `bdlt::FixUtil`,
52/// containing functions that convert `bdlt` date, time, and datetime objects to
53/// and from ("generate" and "parse", respectively) corresponding string
54/// representations that are compliant with the FIX standard. The version of
55/// the FIX standard that is the basis for this component can be found at:
56/// @code
57/// http://www.fixtradingcommunity.org/FIXimate/FIXimate3.0/latestEP/en/
58/// FIX.5.0SP2_EP208/fix_datatypes.html
59/// @endcode
60/// In general terms, `FixUtil` functions support what FIX refers to as
61/// *complete* *representations* in *extended* *format*. We first present a
62/// brief overview before delving into the details of the FIX representations
63/// that are supported for each of the relevant `bdlt` vocabulary types.
64///
65/// Each function that *generates* FIX strings (named `generate` and
66/// `generateRaw`) takes a `bdlt` object and a `char *` buffer, `bsl::string`,
67/// or `bsl::ostream`, and writes a FIX representation of the object to the
68/// buffer, string, or stream. The "raw" functions are distinguished from their
69/// non-"raw" counterparts in three respects:
70///
71/// * The length of the `char *` buffer is not supplied to the `generateRaw`
72/// functions.
73/// * The `generateRaw` functions do not output a null terminator.
74/// * The `generate` functions that provide an `int bufferLength` parameter
75/// truncate the generated output to `bufferLength` characters. (Neither the
76/// `generateRaw` functions nor the `generate` functions taking `bsl::string`
77/// or `bsl::ostream` do any truncation of their generated output.)
78///
79/// Since the generate functions always succeed, no status value is returned.
80/// Instead, either the number of characters output to the `char *` buffer or
81/// string, or a reference to the stream, is returned. (Note that the
82/// generating functions also take an optional `bdlt::FixUtilConfiguration`
83/// object, which is discussed shortly.)
84///
85/// Each function that *parses* FIX strings (named `parse`) take the address of
86/// a target `bdlt` object and a `const char *` (paired with a `length`
87/// argument) or `bsl::string_view`, and loads the object with the result of
88/// parsing the character string. Since parsing can fail, the parse functions
89/// return an `int` status value (0 for success and a non-zero value for
90/// failure). Note that, besides elementary syntactical considerations, the
91/// validity of parsed strings are subject to the semantic constraints imposed
92/// by the various `isValid*` class methods (i.e., `Date::isValidYearMonthDay`,
93/// `Time::isValid`, etc.).
94///
95/// ## Terminology {#bdlt_fixutil-terminology}
96///
97///
98/// As this component concerns FIX, some terms from that specification are used
99/// liberally in what follows. Two FIX terms of particular note are *timezone*
100/// *offset* and *fractional* *second*.
101///
102/// A FIX *timezone* *offset* corresponds to what other `bdlt` components
103/// commonly refer to as a timezone offset (or simply as an offset; e.g., see
104/// @ref bdlt_datetimetz ). For example, the FIX string `20020317-15:46:00+04:00`
105/// has a timezone offset of `+04:00`, indicating a timezone 4 hours ahead of
106/// UTC.
107///
108/// A FIX *fractional* *second* corresponds to, for example, combined
109/// `millisecond` and `microsecond` attributes of a `bdlt::Datetime` or
110/// `bdlt::Time` object. For example, the `Time` value (and FIX string)
111/// `15:46:09.330` has a `millisecond` attribute value of 330; i.e., a
112/// fractional second of .33.
113///
114/// ## FIX String Generation {#bdlt_fixutil-fix-string-generation}
115///
116///
117/// Strings produced by the `generate` and `generateRaw` functions are a
118/// straightforward transposition of the attributes of the source `bdlt` value
119/// into an appropriate FIX format, and are best illustrated by a few examples.
120/// Note that for `Datetime`, `DatetimeTz`, and `Time`, the fractional second is
121/// generated with the precision specified in the configuration. Also note that
122/// for `TimeTz`, no fractional second is generated (as per the FIX
123/// specification for "TZTimeOnly").
124/// @code
125/// +--------------------------------------+---------------------------------+
126/// | Object Value | Generated FIX String |
127/// | | (using default configuration) |
128/// +======================================+=================================+
129/// | Date(2002, 03, 17) | 20020317 |
130/// +--------------------------------------+---------------------------------+
131/// | Time(15, 46, 09, 330) | 15:46:09.330 |
132/// +--------------------------------------+---------------------------------+
133/// | Datetime(Date(2002, 03, 17) | |
134/// | Time(15, 46, 09, 330)) | 20020317-15:46:09.330 |
135/// +--------------------------------------+---------------------------------+
136/// | DateTz(Date(2002, 03, 17), -120) | 20020317-02:00 |
137/// +--------------------------------------+---------------------------------+
138/// | TimeTz(Time(15, 46, 09, 330), 270) | 15:46:09+04:30 |
139/// +--------------------------------------+---------------------------------+
140/// | DatetimeTz(Datetime( | |
141/// | Date(2002, 03, 17), | |
142/// | Time(15, 46, 09, 330)), | |
143/// | 0) | 20020317-15:46:09.330+00:00 |
144/// +--------------------------------------+---------------------------------+
145/// @endcode
146/// Note that the FIX specification does not have an equivalent to
147/// `bdlt::DateTz`.
148///
149/// ### Configuration {#bdlt_fixutil-configuration}
150///
151///
152/// The `generate` and `generateRaw` functions provide an optional configuration
153/// parameter. This optional parameter, of type `FixUtilConfiguration`, enables
154/// configuration of two aspects of FIX string generation:
155///
156/// * The precision of the fractional seconds.
157/// * Whether `Z` is output for the timezone offset instead of `+00:00` (UTC).
158///
159/// `FixUtilConfiguration` has two attributes that directly correspond to these
160/// aspects. In addition, for generate methods that are not supplied with a
161/// configuration argument, a process-wide configuration takes effect. See
162/// @ref bdlt_fixutilconfiguration for details.
163///
164/// ## FIX String Parsing {#bdlt_fixutil-fix-string-parsing}
165///
166///
167/// The parse functions accept *all* strings that are produced by the generate
168/// functions. In addition, the parse functions accept some variation in the
169/// generated strings, the details of which are discussed next. Note that the
170/// parse methods are not configurable like the generate methods (i.e., via an
171/// optional `FixUtilConfiguration` argument). Moreover, the process-wide
172/// configuration has no effect on parsing either. Instead, the parse methods
173/// automatically treat `+00:00` and `Z` as equivalent timezone offsets (both
174/// denoting UTC). Finally, the parsing allows seconds to be optionally
175/// specified in all types, which is in contradiction to some of the types in
176/// the referenced FIX protocol specification.
177///
178/// ### Timezone Offsets {#bdlt_fixutil-timezone-offsets}
179///
180///
181/// The timezone offset is optional, and can be present when parsing for *any*
182/// type, i.e., even for `Date`, `Time`, and `Datetime`. If a timezone offset
183/// is parsed for a `Date`, it must be valid, so it can affect the status value
184/// that is returned in that case, but it is otherwise ignored. For `Time` and
185/// `Datetime`, any timezone offset present in the parsed string will affect the
186/// resulting object value (unless the timezone offset denotes UTC) because the
187/// result is converted to UTC. If the timezone offset is absent, it is treated
188/// as if `+00:00` were specified:
189/// @code
190/// +------------------------------------+-----------------------------------+
191/// | Parsed FIX String | Result Object Value |
192/// +====================================+===================================+
193/// | 20020317-02:00 | Date(2002, 03, 17) |
194/// | | # timezone offset ignored |
195/// +------------------------------------+-----------------------------------+
196/// | 20020317-02:65 | Date: parsing fails |
197/// | | # invalid timezone offset |
198/// +------------------------------------+-----------------------------------+
199/// | 15:46:09.330+04:30 | Time(11, 16, 09, 330) |
200/// | | # converted to UTC |
201/// +------------------------------------+-----------------------------------+
202/// | 15:46:09.330+04:30 | TimeTz(Time(15, 46, 09, 330), |
203/// | | 270) |
204/// +------------------------------------+-----------------------------------+
205/// | 15:46:09.330 | TimeTz(Time(15, 46, 09, 330), |
206/// | | 0) |
207/// | | # implied '+00:00' |
208/// +------------------------------------+-----------------------------------+
209/// | 20020317-23:46:09.222-05:00 | Datetime(Date(2002, 03, 18), |
210/// | | Time(04, 46, 09, 222)) |
211/// | | # carry into 'day' attribute |
212/// | | # when converted to UTC |
213/// +------------------------------------+-----------------------------------+
214/// @endcode
215/// In the last example above, the conversion to UTC incurs a carry into the
216/// `day` attribute of the `Date` component of the resulting `Datetime` value.
217/// Note that if such a carry causes an underflow or overflow at the extreme
218/// ends of the valid range of dates (0001/01/01 and 9999/12/31), then parsing
219/// for `Datetime` fails.
220///
221/// ### Fractional Seconds {#bdlt_fixutil-fractional-seconds}
222///
223///
224/// The fractional second is optional. When the fractional second is absent, it
225/// is treated as if `.0` were specified. When the fractional second is
226/// present, it can have one or more digits (in divergence with the referenced
227/// FIX protocol document, which indicates the fractional second may be
228/// unspecified or have a positive multiple of three digits). Although FIX has
229/// provision for picosecond (or finer) time resolution, be aware that `bdlt` is
230/// limited to microsecond resolution. If more than six digits are included in
231/// the fractional second, values are rounded to a full microsecond; i.e.,
232/// values greater than or equal to .5 microseconds are rounded up. These
233/// roundings may incur a carry of one second into the `second` attribute:
234/// @code
235/// +--------------------------------------+---------------------------------+
236/// | Parsed FIX String | Result Object Value |
237/// +======================================+=================================+
238/// | 15:46:09.1 | Time(15, 46, 09, 100) |
239/// +--------------------------------------+---------------------------------+
240/// | 15:46:09-05:00 | TimeTz(Time(15, 46, 09), -300) |
241/// | | # implied '.0' |
242/// +--------------------------------------+---------------------------------+
243/// | 15:46:09.99999949 | Time(15, 46, 09, 999, 999) |
244/// | | # truncate last two digits |
245/// +--------------------------------------+---------------------------------+
246/// | 15:46:09.9999995 | Time(15, 46, 10, 000) |
247/// | | # round up and carry |
248/// +--------------------------------------+---------------------------------+
249/// @endcode
250/// Note that, for `Datetime` and `DatetimeTz`, if a carry due to rounding of
251/// the fractional second causes an overflow at the extreme upper end of the
252/// valid range of dates (i.e., 9999/12/31), then parsing fails.
253///
254/// ### Leap Seconds {#bdlt_fixutil-leap-seconds}
255///
256///
257/// Leap seconds are not representable by `bdlt::Time` or `bdlt::Datetime`.
258/// Hence, they are not produced by any of the `FixUtil` generate functions.
259/// However, positive leap seconds *are* supported by the parse functions. A
260/// leap second is recognized when the value parsed for the `second` attribute
261/// of a `Time` is 60 -- regardless of the values parsed for the `hour`,
262/// `minute`, and `millisecond` attributes. Note that this behavior is more
263/// generous than that afforded by the FIX specification (which indicates that a
264/// positive leap second can only be represented as "23:59:60Z").
265///
266/// When a leap second is detected during parsing of a FIX string, the `second`
267/// attribute is taken to be 59, so that the value of the `Time` object can be
268/// validly set; then an additional second is added to the object. Note that
269/// the possible carry incurred by a leap second (i.e., when loading the result
270/// of parsing into a `Datetime` or `DatetimeTz` object) has the same potential
271/// for overflow as may occur with fractional seconds that are rounded up
272/// (although in admittedly pathological cases).
273///
274/// ### The Time 24:00 {#bdlt_fixutil-the-time-24-00}
275///
276///
277/// Although 24:00 is *representable* by `bdlt`, i.e., as the default value for
278/// `bdlt::Time`, "24:00:00.000" is *not* a valid string in the FIX protocol.
279/// As per other methods acting upon 24:00 within `bdlt`, an `hour` attribute
280/// value of 24 is mapped to 0 by the generate functions provided by this
281/// component:
282/// @code
283/// +------------------------------------+-----------------------------------+
284/// | Source Object Value | Generated FIX String |
285/// +====================================+===================================+
286/// | Time(24, 0, 0, 0) | 00:00:00.000 |
287/// +------------------------------------+-----------------------------------+
288/// | Datetime(Date(2002, 03, 17), | 20020317-00:00:00.000 |
289/// | Time(24, 0, 0, 0)) | |
290/// +------------------------------------+-----------------------------------+
291/// @endcode
292/// Finally, a string representing 24:00 is rejected by the `bdlt::FixUtil`
293/// parse methods.
294///
295/// ### Summary of Supported FIX Representations {#bdlt_fixutil-summary-of-supported-fix-representations}
296///
297///
298/// The syntax description below summarizes the FIX string representations
299/// supported by this component. Although not quoted (for readability),
300/// `[+-:.Z]` are literal characters that can occur in FIX strings. The
301/// characters `[YMDhms]` each denote a decimal digit, `{}` brackets optional
302/// elements, `()` is used for grouping, and `|` separates alternatives:
303/// @code
304/// <Generated Date> ::= <DATE>
305///
306/// <Parsed Date> ::= <Parsed DateTz>
307///
308/// <Generated DateTz> ::= <DATE><ZONE>
309///
310/// <Parsed DateTz> ::= <DATE>{<ZONE>}
311///
312/// <Generated Time> ::= <TIME FLEXIBLE>
313///
314/// <Parsed Time> ::= <Parsed TimeTz>
315///
316/// <Generated TimeTz> ::= <TIME FIXED><ZONE>
317///
318/// <Parsed TimeTz> ::= <TIME FLEXIBLE>{<ZONE>}
319///
320/// <Generated Datetime> ::= <DATE>-<TIME FLEXIBLE>
321///
322/// <Parsed Datetime> ::= <Parsed DatetimeTz>
323///
324/// <Generated DatetimeTz> ::= <DATE>-<TIME FLEXIBLE><ZONE>
325///
326/// <Parsed DatetimeTz> ::= <DATE>-<TIME FLEXIBLE>{<ZONE>}
327///
328/// <DATE> ::= YYYYMMDD
329///
330/// <TIME FIXED> ::= hh:mm:ss
331///
332/// <TIME FLEXIBLE> ::= hh:mm{:ss{.s+}}
333///
334/// <ZONE> ::= ((+|-)hh{:mm})|Z # timezone offset, the colon
335/// # and minute attribute are
336/// # optional during parsing
337/// @endcode
338///
339/// ## Usage {#bdlt_fixutil-usage}
340///
341///
342/// This section illustrates intended use of this component.
343///
344/// ### Example 1: Basic bdlt::FixUtil Usage {#bdlt_fixutil-example-1-basic-bdlt-fixutil-usage}
345///
346///
347/// This example demonstrates basic use of one `generate` function and two
348/// `parse` functions.
349///
350/// First, we construct a few objects that are prerequisites for this and the
351/// following example:
352/// @code
353/// const bdlt::Date date(2005, 1, 31); // 2005/01/31
354/// const bdlt::Time time(8, 59, 59, 123); // 08:59:59.123
355/// const int tzOffset = 240; // +04:00 (four hours west of UTC)
356/// @endcode
357/// Then, we construct a `bdlt::DatetimeTz` object for which a corresponding
358/// FIX-compliant string will be generated shortly:
359/// @code
360/// const bdlt::DatetimeTz sourceDatetimeTz(bdlt::Datetime(date, time),
361/// tzOffset);
362/// @endcode
363/// For comparison with the FIX string generated below, note that streaming the
364/// value of `sourceDatetimeTz` to `stdout`:
365/// @code
366/// bsl::cout << sourceDatetimeTz << bsl::endl;
367/// @endcode
368/// produces:
369/// @code
370/// 31JAN2005_08:59:59.123000+0400
371/// @endcode
372/// Next, we use a `generate` function to produce a FIX-compliant string for
373/// `sourceDatetimeTz`, writing the output to a `bsl::ostringstream`, and assert
374/// that both the return value and the string that is produced are as expected:
375/// @code
376/// bsl::ostringstream oss;
377/// const bsl::ostream& ret = bdlt::FixUtil::generate(oss, sourceDatetimeTz);
378/// assert(&oss == &ret);
379///
380/// const bsl::string fix = oss.str();
381/// assert(fix == "20050131-08:59:59.123+04:00");
382/// @endcode
383/// For comparison, see the output that was produced by the streaming operator
384/// above.
385///
386/// Now, we parse the string that was just produced, loading the result of the
387/// parse into a second `bdlt::DatetimeTz` object, and assert that the parse was
388/// successful and that the target object has the same value as that of the
389/// original (i.e., `sourceDatetimeTz`):
390/// @code
391/// bdlt::DatetimeTz targetDatetimeTz;
392///
393/// int rc = bdlt::FixUtil::parse(&targetDatetimeTz,
394/// fix.c_str(),
395/// static_cast<int>(fix.length()));
396/// assert( 0 == rc);
397/// assert(sourceDatetimeTz == targetDatetimeTz);
398/// @endcode
399/// Finally, we parse the `fix` string a second time, this time loading the
400/// result into a `bdlt::Datetime` object (instead of a `bdlt::DatetimeTz`):
401/// @code
402/// bdlt::Datetime targetDatetime;
403///
404/// rc = bdlt::FixUtil::parse(&targetDatetime,
405/// fix.c_str(),
406/// static_cast<int>(fix.length()));
407/// assert( 0 == rc);
408/// assert(sourceDatetimeTz.utcDatetime() == targetDatetime);
409/// @endcode
410/// Note that this time the value of the target object has been converted to
411/// UTC.
412///
413/// ### Example 2: Configuring FIX String Generation {#bdlt_fixutil-example-2-configuring-fix-string-generation}
414///
415///
416/// This example demonstrates use of a `bdlt::FixUtilConfiguration` object to
417/// influence the format of the FIX strings that are generated by this component
418/// by passing that configuration object to `generate`. We also take this
419/// opportunity to illustrate the flavor of the `generate` functions that
420/// outputs to a `char *` buffer of a specified length.
421///
422/// First, we construct the `bdlt::FixUtilConfiguration` object that indicates
423/// how we would like to affect the generated output FIX string. In this case,
424/// we want to have microsecond precision displayed:
425/// @code
426/// bdlt::FixUtilConfiguration configuration;
427///
428/// configuration.setFractionalSecondPrecision(6);
429/// @endcode
430/// Then, we define the `char *` buffer that will be used to stored the
431/// generated string. A buffer of size `bdlt::FixUtil::k_DATETIMETZ_STRLEN + 1`
432/// is large enough to hold any string generated by this component for a
433/// `bdlt::DatetimeTz` object, including a null terminator:
434/// @code
435/// const int BUFLEN = bdlt::FixUtil::k_DATETIMETZ_STRLEN + 1;
436/// char buffer[BUFLEN];
437/// @endcode
438/// Next, we use a `generate` function that accepts our `configuration` to
439/// produce a FIX-compliant string for `sourceDatetimeTz`, this time writing the
440/// output to a `char *` buffer, and assert that both the return value and the
441/// string that is produced are as expected. Note that in comparing the return
442/// value against `BUFLEN - 1` we account for the fact that, although a null
443/// terminator was generated, it is not included in the character count returned
444/// by `generate`. Also note that we use `bsl::strcmp` to compare the resulting
445/// string knowing that we supplied a buffer having sufficient capacity to
446/// accommodate a null terminator:
447/// @code
448/// rc = bdlt::FixUtil::generate(buffer,
449/// BUFLEN,
450/// sourceDatetimeTz,
451/// configuration);
452/// assert(BUFLEN - 1 == rc);
453/// assert( 0 == bsl::strcmp(buffer,
454/// "20050131-08:59:59.123000+04:00"));
455/// @endcode
456/// For comparison, see the output that was produced by the streaming operator
457/// above.
458///
459/// Next, we parse the string that was just produced, loading the result of the
460/// parse into a second `bdlt::DatetimeTz` object, and assert that the parse was
461/// successful and that the target object has the same value as that of the
462/// original (i.e., `sourceDatetimeTz`). Note that `BUFLEN - 1` is passed and
463/// *not* `BUFLEN` because the former indicates the correct number of characters
464/// in `buffer` that we wish to parse:
465/// @code
466/// rc = bdlt::FixUtil::parse(&targetDatetimeTz, buffer, BUFLEN - 1);
467///
468/// assert( 0 == rc);
469/// assert(sourceDatetimeTz == targetDatetimeTz);
470/// @endcode
471/// Then, we parse the string in `buffer` a second time, this time loading the
472/// result into a `bdlt::Datetime` object (instead of a `bdlt::DatetimeTz`):
473/// @code
474/// rc = bdlt::FixUtil::parse(&targetDatetime, buffer, BUFLEN - 1);
475///
476/// assert( 0 == rc);
477/// assert(sourceDatetimeTz.utcDatetime() == targetDatetime);
478/// @endcode
479/// Note that this time the value of the target object has been converted to
480/// UTC.
481///
482/// Finally, we modify the `configuration` to display the `bdlt::DatetimeTz`
483/// without fractional seconds:
484/// @code
485/// configuration.setFractionalSecondPrecision(0);
486/// rc = bdlt::FixUtil::generate(buffer,
487/// BUFLEN,
488/// sourceDatetimeTz,
489/// configuration);
490/// assert(BUFLEN - 8 == rc);
491/// assert( 0 == bsl::strcmp(buffer, "20050131-08:59:59+04:00"));
492/// @endcode
493/// @}
494/** @} */
495/** @} */
496
497/** @addtogroup bdl
498 * @{
499 */
500/** @addtogroup bdlt
501 * @{
502 */
503/** @addtogroup bdlt_fixutil
504 * @{
505 */
506
507#include <bdlscm_version.h>
508
510
511#include <bslmf_assert.h>
512#include <bslmf_issame.h>
513
514#include <bsls_assert.h>
515#include <bsls_libraryfeatures.h>
516#include <bsls_review.h>
517
518#include <bsl_ostream.h>
519#include <bsl_string.h>
520
521
522namespace bdlt {
523
524class Date;
525class DateTz;
526class Datetime;
527class DatetimeTz;
528class Time;
529class TimeTz;
530
531class FixUtilConfiguration;
532
533 // ==============
534 // struct FixUtil
535 // ==============
536
537/// This `struct` provides a namespace for a suite of pure functions that
538/// perform conversions between objects of `bdlt` vocabulary type and their
539/// FIX representations. Each `generate` and `generateRaw` method takes a
540/// `bdlt` object (of type `Date`, `DateTz`, `Time`, `TimeTz`, `Datetime`,
541/// or `DatetimeTz`) and outputs its corresponding FIX representation to a
542/// user-supplied character buffer or `bsl::ostream`. The `parse` methods
543/// effect the opposite conversion in that they populate a `bdlt` object
544/// from the result of parsing a FIX representation.
545///
546/// See @ref bdlt_fixutil
547struct FixUtil {
548
549 // TYPES
550
551 /// This enumeration defines fixed lengths for the FIX representations of date, time, and datetime values.
552 ///
553 /// \note Note that these constants do
554 /// *not* account for the null terminator that may be produced by the
555 /// `generate` functions taking a `bufferLength` argument.
556 enum {
557 k_DATE_STRLEN = 8, // `bdlt::Date`
558 k_DATETZ_STRLEN = 14, // `bdlt::DateTz`
559
560 k_TIME_STRLEN = 15, // `bdlt::Time`
561 k_TIMETZ_STRLEN = 14, // `bdlt::TimeTz`
562
563 k_DATETIME_STRLEN = 24, // `bdlt::Datetime`
564 k_DATETIMETZ_STRLEN = 30, // `bdlt::DatetimeTz`
565
567 };
568
569 // CLASS METHODS
570
571 /// Write the FIX representation of the specified `object` to the
572 /// specified `buffer` of the specified `bufferLength` (in bytes),
573 /// truncating (if necessary) to `bufferLength`. Optionally specify a
574 /// `configuration` to affect the format of the generated string. If
575 /// `configuration` is not supplied, the process-wide default value
576 /// `FixUtilConfiguration::defaultConfiguration()` is used. Return the
577 /// number of characters in the formatted string before truncation (not
578 /// counting a null terminator). If `bufferLength` indicates sufficient
579 /// capacity, `buffer` is null terminated.
580 ///
581 /// \pre The behavior is undefined unless `0 <= bufferLength`.
582 /// \note Note that a buffer of size
583 /// `k_MAX_STRLEN + 1` is large enough to hold any string generated by
584 /// this component (counting a null terminator, if any).
585 static int generate(char *buffer,
586 int bufferLength,
587 const Date& object);
588 static int generate(char *buffer,
589 int bufferLength,
590 const Date& object,
591 const FixUtilConfiguration& configuration);
592 static int generate(char *buffer,
593 int bufferLength,
594 const Time& object);
595 static int generate(char *buffer,
596 int bufferLength,
597 const Time& object,
598 const FixUtilConfiguration& configuration);
599 static int generate(char *buffer,
600 int bufferLength,
601 const Datetime& object);
602 static int generate(char *buffer,
603 int bufferLength,
604 const Datetime& object,
605 const FixUtilConfiguration& configuration);
606 static int generate(char *buffer,
607 int bufferLength,
608 const DateTz& object);
609 static int generate(char *buffer,
610 int bufferLength,
611 const DateTz& object,
612 const FixUtilConfiguration& configuration);
613 static int generate(char *buffer,
614 int bufferLength,
615 const TimeTz& object);
616 static int generate(char *buffer,
617 int bufferLength,
618 const TimeTz& object,
619 const FixUtilConfiguration& configuration);
620 static int generate(char *buffer,
621 int bufferLength,
622 const DatetimeTz& object);
623 static int generate(char *buffer,
624 int bufferLength,
625 const DatetimeTz& object,
626 const FixUtilConfiguration& configuration);
627
628 static int generate(bsl::string *string,
629 const Date& object);
630 static int generate(bsl::string *string,
631 const Date& object,
632 const FixUtilConfiguration& configuration);
633 static int generate(bsl::string *string,
634 const Time& object);
635 static int generate(bsl::string *string,
636 const Time& object,
637 const FixUtilConfiguration& configuration);
638 static int generate(bsl::string *string,
639 const Datetime& object);
640 static int generate(bsl::string *string,
641 const Datetime& object,
642 const FixUtilConfiguration& configuration);
643 static int generate(bsl::string *string,
644 const DateTz& object);
645 static int generate(bsl::string *string,
646 const DateTz& object,
647 const FixUtilConfiguration& configuration);
648 static int generate(bsl::string *string,
649 const TimeTz& object);
650 static int generate(bsl::string *string,
651 const TimeTz& object,
652 const FixUtilConfiguration& configuration);
653 static int generate(bsl::string *string,
654 const DatetimeTz& object);
655 static int generate(bsl::string *string,
656 const DatetimeTz& object,
657 const FixUtilConfiguration& configuration);
658
659 static int generate(std::string *string,
660 const Date& object);
661 static int generate(std::string *string,
662 const Date& object,
663 const FixUtilConfiguration& configuration);
664 static int generate(std::string *string,
665 const Time& object);
666 static int generate(std::string *string,
667 const Time& object,
668 const FixUtilConfiguration& configuration);
669 static int generate(std::string *string,
670 const Datetime& object);
671 static int generate(std::string *string,
672 const Datetime& object,
673 const FixUtilConfiguration& configuration);
674 static int generate(std::string *string,
675 const DateTz& object);
676 static int generate(std::string *string,
677 const DateTz& object,
678 const FixUtilConfiguration& configuration);
679 static int generate(std::string *string,
680 const TimeTz& object);
681 static int generate(std::string *string,
682 const TimeTz& object,
683 const FixUtilConfiguration& configuration);
684 static int generate(std::string *string,
685 const DatetimeTz& object);
686 static int generate(std::string *string,
687 const DatetimeTz& object,
688 const FixUtilConfiguration& configuration);
689
690#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
691 /// Load the FIX representation of the specified `object` into the
692 /// specified `string`. Optionally specify a `configuration` to affect
693 /// the format of the generated string. If `configuration` is not
694 /// supplied, the process-wide default value
695 /// `FixUtilConfiguration::defaultConfiguration()` is used. Return the
696 /// number of characters in the formatted string. The previous contents
697 /// of `string` (if any) are discarded.
698 static int generate(std::pmr::string *string,
699 const Date& object);
700 static int generate(std::pmr::string *string,
701 const Date& object,
702 const FixUtilConfiguration& configuration);
703 static int generate(std::pmr::string *string,
704 const Time& object);
705 static int generate(std::pmr::string *string,
706 const Time& object,
707 const FixUtilConfiguration& configuration);
708 static int generate(std::pmr::string *string,
709 const Datetime& object);
710 static int generate(std::pmr::string *string,
711 const Datetime& object,
712 const FixUtilConfiguration& configuration);
713 static int generate(std::pmr::string *string,
714 const DateTz& object);
715 static int generate(std::pmr::string *string,
716 const DateTz& object,
717 const FixUtilConfiguration& configuration);
718 static int generate(std::pmr::string *string,
719 const TimeTz& object);
720 static int generate(std::pmr::string *string,
721 const TimeTz& object,
722 const FixUtilConfiguration& configuration);
723 static int generate(std::pmr::string *string,
724 const DatetimeTz& object);
725 static int generate(std::pmr::string *string,
726 const DatetimeTz& object,
727 const FixUtilConfiguration& configuration);
728#endif
729
730 /// Write the FIX representation of the specified `object` to the
731 /// specified `stream`. Optionally specify a `configuration` to affect
732 /// the format of the generated string. If `configuration` is not
733 /// supplied, the process-wide default value
734 /// `FixUtilConfiguration::defaultConfiguration()` is used. Return a reference to `stream`.
735 ///
736 /// \note Note that `stream` is not null terminated.
737 static bsl::ostream& generate(bsl::ostream& stream,
738 const Date& object);
739 static bsl::ostream& generate(bsl::ostream& stream,
740 const Date& object,
741 const FixUtilConfiguration& configuration);
742 static bsl::ostream& generate(bsl::ostream& stream,
743 const Time& object);
744 static bsl::ostream& generate(bsl::ostream& stream,
745 const Time& object,
746 const FixUtilConfiguration& configuration);
747 static bsl::ostream& generate(bsl::ostream& stream,
748 const Datetime& object);
749 static bsl::ostream& generate(bsl::ostream& stream,
750 const Datetime& object,
751 const FixUtilConfiguration& configuration);
752 static bsl::ostream& generate(bsl::ostream& stream,
753 const DateTz& object);
754 static bsl::ostream& generate(bsl::ostream& stream,
755 const DateTz& object,
756 const FixUtilConfiguration& configuration);
757 static bsl::ostream& generate(bsl::ostream& stream,
758 const TimeTz& object);
759 static bsl::ostream& generate(bsl::ostream& stream,
760 const TimeTz& object,
761 const FixUtilConfiguration& configuration);
762 static bsl::ostream& generate(bsl::ostream& stream,
763 const DatetimeTz& object);
764 static bsl::ostream& generate(bsl::ostream& stream,
765 const DatetimeTz& object,
766 const FixUtilConfiguration& configuration);
767
768 /// Write the FIX representation of the specified `object` to the
769 /// specified `buffer`. Optionally specify a `configuration` to affect
770 /// the format of the generated string. If `configuration` is not
771 /// supplied, the process-wide default value
772 /// `FixUtilConfiguration::defaultConfiguration()` is used. Return the
773 /// number of characters in the formatted string. `buffer` is not null terminated.
774 ///
775 /// \pre The behavior is undefined unless `buffer` has sufficient capacity.
776 ///
777 /// \note Note that a buffer of size `k_MAX_STRLEN + 1`
778 /// is large enough to hold any string generated by this component
779 /// (counting a null terminator, if any).
780 static int generateRaw(char *buffer,
781 const Date& object);
782 static int generateRaw(char *buffer,
783 const Date& object,
784 const FixUtilConfiguration& configuration);
785 static int generateRaw(char *buffer,
786 const Time& object);
787 static int generateRaw(char *buffer,
788 const Time& object,
789 const FixUtilConfiguration& configuration);
790 static int generateRaw(char *buffer,
791 const Datetime& object);
792 static int generateRaw(char *buffer,
793 const Datetime& object,
794 const FixUtilConfiguration& configuration);
795 static int generateRaw(char *buffer,
796 const DateTz& object);
797 static int generateRaw(char *buffer,
798 const DateTz& object,
799 const FixUtilConfiguration& configuration);
800 static int generateRaw(char *buffer,
801 const TimeTz& object);
802 static int generateRaw(char *buffer,
803 const TimeTz& object,
804 const FixUtilConfiguration& configuration);
805 static int generateRaw(char *buffer,
806 const DatetimeTz& object);
807 static int generateRaw(char *buffer,
808 const DatetimeTz& object,
809 const FixUtilConfiguration& configuration);
810
811 /// Parse the specified initial `length` characters of the specified FIX
812 /// `string` as a `Date` value, and load the value into the specified
813 /// `result`. Return 0 on success, and a non-zero value (with no
814 /// effect) otherwise. `string` is assumed to be of the form:
815 /// @code
816 /// YYYYMMDD{(+|-)hh{:mm}|Z}
817 /// @endcode
818 /// *Exactly* `length` characters are parsed; parsing will fail if a
819 /// proper prefix of `string` matches the expected format, but the
820 /// entire `length` characters do not. If the optional timezone offset
821 /// is present in `string`, it is parsed but ignored.
822 ///
823 /// \pre The behavior is undefined unless `0 <= length`.
824 static int parse(Date *result, const char *string, int length);
825
826 /// Parse the specified initial `length` characters of the specified FIX
827 /// `string` as a `Time` value, and load the value into the specified
828 /// `result`. Return 0 on success, and a non-zero value (with no
829 /// effect) otherwise. `string` is assumed to be of the form:
830 /// @code
831 /// hh:mm:ss{.s+}{(+|-)hh{:mm}|Z}
832 /// @endcode
833 /// *Exactly* `length` characters are parsed; parsing will fail if a
834 /// proper prefix of `string` matches the expected format, but the
835 /// entire `length` characters do not. If an optional fractional second
836 /// having more than six digits is present in `string`, it is rounded
837 /// to the nearest value in microseconds. If the optional timezone
838 /// offset is present in `string`, the resulting `Time` value is
839 /// converted to the equivalent UTC time; if the timezone offset is
840 /// absent, UTC is assumed. If a leap second is detected (i.e., the
841 /// parsed value of the `second` attribute is 60; see {Leap Seconds}),
842 /// the `second` attribute is taken to be 59, then an additional second is added to `result` at the end.
843 ///
844 /// \pre The behavior is undefined unless
845 /// `0 <= length`.
846 static int parse(Time *result, const char *string, int length);
847
848 /// Parse the specified initial `length` characters of the specified FIX
849 /// `string` as a `Datetime` value, and load the value into the
850 /// specified `result`. Return 0 on success, and a non-zero value (with
851 /// no effect) otherwise. `string` is assumed to be of the form:
852 /// @code
853 /// YYYYMMDD-hh:mm{:ss{.s+}}{(+|-)hh{:mm}|Z}
854 /// @endcode
855 /// *Exactly* `length` characters are parsed; parsing will fail if a
856 /// proper prefix of `string` matches the expected format, but the
857 /// entire `length` characters do not. If an optional fractional second
858 /// having more than six digits is present in `string`, it is rounded to
859 /// the nearest value in microseconds. If the optional timezone offset
860 /// is present in `string`, the resulting `Datetime` value is converted
861 /// to the equivalent UTC value; if the timezone offset is absent, UTC
862 /// is assumed. If a leap second is detected (i.e., the parsed value of
863 /// the `second` attribute is 60; see {Leap Seconds}), the `second`
864 /// attribute is taken to be 59, then an additional second is added to `result` at the end.
865 ///
866 /// \pre The behavior is undefined unless
867 /// `0 <= length`.
868 static int parse(Datetime *result, const char *string, int length);
869
870 /// Parse the specified initial `length` characters of the specified FIX
871 /// `string` as a `DateTz` value, and load the value into the specified
872 /// `result`. Return 0 on success, and a non-zero value (with no
873 /// effect) otherwise. `string` is assumed to be of the form:
874 /// @code
875 /// YYYYMMDD{(+|-)hh{:mm}|Z}
876 /// @endcode
877 /// *Exactly* `length` characters are parsed; parsing will fail if a
878 /// proper prefix of `string` matches the expected format, but the
879 /// entire `length` characters do not. If the optional timezone offset
880 /// is not present in `string`, UTC is assumed.
881 ///
882 /// \pre The behavior is undefined unless `0 <= length`.
883 static int parse(DateTz *result, const char *string, int length);
884
885 /// Parse the specified initial `length` characters of the specified FIX
886 /// `string` as a `TimeTz` value, and load the value into the specified
887 /// `result`. Return 0 on success, and a non-zero value (with no
888 /// effect) otherwise. `string` is assumed to be of the form:
889 /// @code
890 /// hh:mm{:ss{.s+}}{(+|-)hh{:mm}|Z}
891 /// @endcode
892 /// *Exactly* `length` characters are parsed; parsing will fail if a
893 /// proper prefix of `string` matches the expected format, but the
894 /// entire `length` characters do not. If an optional fractional second
895 /// having more than six digits is present in `string`, it is rounded
896 /// to the nearest value in microseconds. If the optional timezone
897 /// offset is not present in `string`, UTC is assumed. If a leap second
898 /// is detected (i.e., the parsed value of the `second` attribute is 60;
899 /// see {Leap Seconds}), the `second` attribute is taken to be 59, then
900 /// an additional second is added to `result` at the end.
901 ///
902 /// \pre The behavior is undefined unless `0 <= length`.
903 static int parse(TimeTz *result, const char *string, int length);
904
905 /// Parse the specified initial `length` characters of the specified FIX
906 /// `string` as a `DatetimeTz` value, and load the value into the
907 /// specified `result`. Return 0 on success, and a non-zero value (with
908 /// no effect) otherwise. `string` is assumed to be of the form:
909 /// @code
910 /// YYYYMMDD-hh:mm{:ss{.s+}}{(+|-)hh{:mm}|Z}
911 /// @endcode
912 /// *Exactly* `length` characters are parsed; parsing will fail if a
913 /// proper prefix of `string` matches the expected format, but the
914 /// entire `length` characters do not. If an optional fractional second
915 /// having more than six digits is present in `string`, it is rounded to
916 /// the nearest value in microseconds. If the optional timezone offset
917 /// is not present in `string`, UTC is assumed. If a leap second is
918 /// detected (i.e., the parsed value of the `second` attribute is 60;
919 /// see {Leap Seconds}), the `second` attribute is taken to be 59, then
920 /// an additional second is added to `result` at the end.
921 ///
922 /// \pre The behavior is undefined unless `0 <= length`.
923 static int parse(DatetimeTz *result, const char *string, int length);
924
925 /// Parse the specified FIX `string` as a `Date` value, and load the
926 /// value into the specified `result`. Return 0 on success, and a
927 /// non-zero value (with no effect) otherwise. `string` is assumed to
928 /// be of the form:
929 /// @code
930 /// YYYYMMDD{(+|-)hh{:mm}|Z}
931 /// @endcode
932 /// *Exactly* `string.length()` characters are parsed; parsing will fail
933 /// if a proper prefix of `string` matches the expected format, but the
934 /// entire `string.length()` characters do not. If the optional
935 /// timezone offset is present in `string`, it is parsed but ignored.
936 ///
937 /// \pre The behavior is undefined unless `string.data()` is non-null.
938 static int parse(Date *result, const bsl::string_view& string);
939
940 /// Parse the specified FIX `string` as a `Time` value, and load the
941 /// value into the specified `result`. Return 0 on success, and a
942 /// non-zero value (with no effect) otherwise. `string` is assumed to
943 /// be of the form:
944 /// @code
945 /// hh:mm{:ss{.s+}}{(+|-)hh{:mm}|Z}
946 /// @endcode
947 /// *Exactly* `string.length()` characters are parsed; parsing will fail
948 /// if a proper prefix of `string` matches the expected format, but the
949 /// entire `string.length()` characters do not. If an optional
950 /// fractional second having more than six digits is present in
951 /// `string`, it is rounded to the nearest value in microseconds. If
952 /// the optional timezone offset is present in `string`, the resulting
953 /// `Time` value is converted to the equivalent UTC time; if the
954 /// timezone offset is absent, UTC is assumed. If a leap second is
955 /// detected (i.e., the parsed value of the `second` attribute is 60;
956 /// see {Leap Seconds}), the `second` attribute is taken to be 59, then
957 /// an additional second is added to `result` at the end.
958 ///
959 /// \pre The behavior is undefined unless `string.data()` is non-null.
960 static int parse(Time *result, const bsl::string_view& string);
961
962 /// Parse the specified FIX `string` as a `Datetime` value, and load the
963 /// value into the specified `result`. Return 0 on success, and a
964 /// non-zero value (with no effect) otherwise. `string` is assumed to
965 /// be of the form:
966 /// @code
967 /// YYYYMMDD-hh:mm{:ss{.s+}}{(+|-)hh{:mm}|Z}
968 /// @endcode
969 /// *Exactly* `string.length()` characters are parsed; parsing will fail
970 /// if a proper prefix of `string` matches the expected format, but the
971 /// entire `string.length()` characters do not. If an optional
972 /// fractional second having more than six digits is present in
973 /// `string`, it is rounded to the nearest value in microseconds. If
974 /// the optional timezone offset is present in `string`, the resulting
975 /// `Datetime` value is converted to the equivalent UTC value; if the
976 /// timezone offset is absent, UTC is assumed. If a leap second is
977 /// detected (i.e., the parsed value of the `second` attribute is 60;
978 /// see {Leap Seconds}), the `second` attribute is taken to be 59, then
979 /// an additional second is added to `result` at the end.
980 ///
981 /// \pre The behavior is undefined unless `string.data()` is non-null.
982 static int parse(Datetime *result, const bsl::string_view& string);
983
984 /// Parse the specified FIX `string` as a `DateTz` value, and load the
985 /// value into the specified `result`. Return 0 on success, and a
986 /// non-zero value (with no effect) otherwise. `string` is assumed to
987 /// be of the form:
988 /// @code
989 /// YYYYMMDD{(+|-)hh{:mm}|Z}
990 /// @endcode
991 /// *Exactly* `string.length()` characters are parsed; parsing will fail
992 /// if a proper prefix of `string` matches the expected format, but the
993 /// entire `string.length()` characters do not. If the optional
994 /// timezone offset is not present in `string`, UTC is assumed.
995 ///
996 /// \pre The behavior is undefined unless `string.data()` is non-null.
997 static int parse(DateTz *result, const bsl::string_view& string);
998
999 /// Parse the specified FIX `string` as a `TimeTz` value, and load the
1000 /// value into the specified `result`. Return 0 on success, and a
1001 /// non-zero value (with no effect) otherwise. `string` is assumed to
1002 /// be of the form:
1003 /// @code
1004 /// hh:mm{:ss{.s+}}{(+|-)hh{:mm}|Z}
1005 /// @endcode
1006 /// *Exactly* `string.length()` characters are parsed; parsing will fail
1007 /// if a proper prefix of `string` matches the expected format, but the
1008 /// entire `string.length()` characters do not. If an optional
1009 /// fractional second having more than six digits is present in
1010 /// `string`, it is rounded to the nearest value in microseconds. If
1011 /// the optional timezone offset is not present in `string`, UTC is
1012 /// assumed. If a leap second is detected (i.e., the parsed value of
1013 /// the `second` attribute is 60; see {Leap Seconds}), the `second`
1014 /// attribute is taken to be 59, then an additional second is added to `result` at the end.
1015 ///
1016 /// \pre The behavior is undefined unless
1017 /// `string.data()` is non-null.
1018 static int parse(TimeTz *result, const bsl::string_view& string);
1019
1020 /// Parse the specified FIX `string` as a `DatetimeTz` value, and load
1021 /// the value into the specified `result`. Return 0 on success, and a
1022 /// non-zero value (with no effect) otherwise. `string` is assumed to
1023 /// be of the form:
1024 /// @code
1025 /// YYYYMMDD-hh:mm{:ss{.s+}}{(+|-)hh{:mm}|Z}
1026 /// @endcode
1027 /// *Exactly* `string.length()` characters are parsed; parsing will fail
1028 /// if a proper prefix of `string` matches the expected format, but the
1029 /// entire `string.length()` characters do not. If an optional
1030 /// fractional second having more than six digits is present in
1031 /// `string`, it is rounded to the nearest value in microseconds. If
1032 /// the optional timezone offset is not present in `string`, UTC is
1033 /// assumed. If a leap second is detected (i.e., the parsed value of
1034 /// the `second` attribute is 60; see {Leap Seconds}), the `second`
1035 /// attribute is taken to be 59, then an additional second is added to `result` at the end.
1036 ///
1037 /// \pre The behavior is undefined unless
1038 /// `string.data()` is non-null.
1039 static int parse(DatetimeTz *result, const bsl::string_view& string);
1040};
1041
1042// ============================================================================
1043// INLINE DEFINITIONS
1044// ============================================================================
1045
1046 // --------------
1047 // struct FixUtil
1048 // --------------
1049
1050// CLASS METHODS
1051inline
1052int FixUtil::generate(char *buffer, int bufferLength, const Date& object)
1053{
1054 BSLS_ASSERT(buffer);
1055 BSLS_ASSERT(0 <= bufferLength);
1056
1057 return generate(buffer,
1058 bufferLength,
1059 object,
1061}
1062
1063inline
1064int FixUtil::generate(char *buffer, int bufferLength, const Time& object)
1065{
1066 BSLS_ASSERT(buffer);
1067 BSLS_ASSERT(0 <= bufferLength);
1068
1069 return generate(buffer,
1070 bufferLength,
1071 object,
1073}
1074
1075inline
1076int
1077FixUtil::generate(char *buffer, int bufferLength, const Datetime& object)
1078{
1079 BSLS_ASSERT(buffer);
1080 BSLS_ASSERT(0 <= bufferLength);
1081
1082 return generate(buffer,
1083 bufferLength,
1084 object,
1086}
1087
1088inline
1089int FixUtil::generate(char *buffer, int bufferLength, const DateTz& object)
1090{
1091 BSLS_ASSERT(buffer);
1092 BSLS_ASSERT(0 <= bufferLength);
1093
1094 return generate(buffer,
1095 bufferLength,
1096 object,
1098}
1099
1100inline
1101int FixUtil::generate(char *buffer, int bufferLength, const TimeTz& object)
1102{
1103 BSLS_ASSERT(buffer);
1104 BSLS_ASSERT(0 <= bufferLength);
1105
1106 return generate(buffer,
1107 bufferLength,
1108 object,
1110}
1111
1112inline
1113int
1114FixUtil::generate(char *buffer, int bufferLength, const DatetimeTz& object)
1115{
1116 BSLS_ASSERT(buffer);
1117 BSLS_ASSERT(0 <= bufferLength);
1118
1119 return generate(buffer,
1120 bufferLength,
1121 object,
1123}
1124
1125inline
1126int FixUtil::generate(bsl::string *string, const Date& object)
1127{
1128 return generate(string,
1129 object,
1131}
1132
1133inline
1134int FixUtil::generate(bsl::string *string, const Time& object)
1135{
1136 return generate(string,
1137 object,
1139}
1140
1141inline
1142int FixUtil::generate(bsl::string *string, const Datetime& object)
1143{
1144 return generate(string,
1145 object,
1147}
1148
1149inline
1150int FixUtil::generate(bsl::string *string, const DateTz& object)
1151{
1152 return generate(string,
1153 object,
1155}
1156
1157inline
1158int FixUtil::generate(bsl::string *string, const TimeTz& object)
1159{
1160 return generate(string,
1161 object,
1163}
1164
1165inline
1166int FixUtil::generate(bsl::string *string, const DatetimeTz& object)
1167{
1168 return generate(string,
1169 object,
1171}
1172
1173inline
1174int FixUtil::generate(std::string *string, const Date& object)
1175{
1176 return generate(string,
1177 object,
1179}
1180
1181inline
1182int FixUtil::generate(std::string *string, const Time& object)
1183{
1184 return generate(string,
1185 object,
1187}
1188
1189inline
1190int FixUtil::generate(std::string *string, const Datetime& object)
1191{
1192 return generate(string,
1193 object,
1195}
1196
1197inline
1198int FixUtil::generate(std::string *string, const DateTz& object)
1199{
1200 return generate(string,
1201 object,
1203}
1204
1205inline
1206int FixUtil::generate(std::string *string, const TimeTz& object)
1207{
1208 return generate(string,
1209 object,
1211}
1212
1213inline
1214int FixUtil::generate(std::string *string, const DatetimeTz& object)
1215{
1216 return generate(string,
1217 object,
1219}
1220
1221#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
1222inline
1223int FixUtil::generate(std::pmr::string *string, const Date& object)
1224{
1225 return generate(string,
1226 object,
1228}
1229
1230inline
1231int FixUtil::generate(std::pmr::string *string, const Time& object)
1232{
1233 return generate(string,
1234 object,
1236}
1237
1238inline
1239int FixUtil::generate(std::pmr::string *string, const Datetime& object)
1240{
1241 return generate(string,
1242 object,
1244}
1245
1246inline
1247int FixUtil::generate(std::pmr::string *string, const DateTz& object)
1248{
1249 return generate(string,
1250 object,
1252}
1253
1254inline
1255int FixUtil::generate(std::pmr::string *string, const TimeTz& object)
1256{
1257 return generate(string,
1258 object,
1260}
1261
1262inline
1263int FixUtil::generate(std::pmr::string *string, const DatetimeTz& object)
1264{
1265 return generate(string,
1266 object,
1268}
1269#endif
1270
1271inline
1272bsl::ostream& FixUtil::generate(bsl::ostream& stream, const Date& object)
1273{
1274 return generate(stream,
1275 object,
1277}
1278
1279inline
1280bsl::ostream& FixUtil::generate(bsl::ostream& stream,
1281 const Date& object,
1282 const FixUtilConfiguration& configuration)
1283{
1284 char buffer[k_DATE_STRLEN + 1];
1285
1286 const int len = generate(buffer, k_DATE_STRLEN, object, configuration);
1287 BSLS_ASSERT(k_DATE_STRLEN >= len);
1288
1289 return stream.write(buffer, len);
1290}
1291
1292inline
1293bsl::ostream& FixUtil::generate(bsl::ostream& stream, const Time& object)
1294{
1295 return generate(stream,
1296 object,
1298}
1299
1300inline
1301bsl::ostream& FixUtil::generate(bsl::ostream& stream,
1302 const Time& object,
1303 const FixUtilConfiguration& configuration)
1304{
1305 char buffer[k_TIME_STRLEN + 1];
1306
1307 const int len = generate(buffer, k_TIME_STRLEN, object, configuration);
1308 BSLS_ASSERT(k_TIME_STRLEN >= len);
1309
1310 return stream.write(buffer, len);
1311}
1312
1313inline
1314bsl::ostream&
1315FixUtil::generate(bsl::ostream& stream, const Datetime& object)
1316{
1317 return generate(stream,
1318 object,
1320}
1321
1322inline
1323bsl::ostream& FixUtil::generate(bsl::ostream& stream,
1324 const Datetime& object,
1325 const FixUtilConfiguration& configuration)
1326{
1327 char buffer[k_DATETIME_STRLEN + 1];
1328
1329 const int len = generate(buffer, k_DATETIME_STRLEN, object, configuration);
1331
1332 return stream.write(buffer, len);
1333}
1334
1335inline
1336bsl::ostream& FixUtil::generate(bsl::ostream& stream, const DateTz& object)
1337{
1338 return generate(stream,
1339 object,
1341}
1342
1343inline
1344bsl::ostream& FixUtil::generate(bsl::ostream& stream,
1345 const DateTz& object,
1346 const FixUtilConfiguration& configuration)
1347{
1348 char buffer[k_DATETZ_STRLEN + 1];
1349
1350 const int len = generate(buffer, k_DATETZ_STRLEN, object, configuration);
1352
1353 return stream.write(buffer, len);
1354}
1355
1356inline
1357bsl::ostream& FixUtil::generate(bsl::ostream& stream, const TimeTz& object)
1358{
1359 return generate(stream,
1360 object,
1362}
1363
1364inline
1365bsl::ostream& FixUtil::generate(bsl::ostream& stream,
1366 const TimeTz& object,
1367 const FixUtilConfiguration& configuration)
1368{
1369 char buffer[k_TIMETZ_STRLEN + 1];
1370
1371 const int len = generate(buffer, k_TIMETZ_STRLEN, object, configuration);
1373
1374 return stream.write(buffer, len);
1375}
1376
1377inline
1378bsl::ostream&
1379FixUtil::generate(bsl::ostream& stream, const DatetimeTz& object)
1380{
1381 return generate(stream,
1382 object,
1384}
1385
1386inline
1387bsl::ostream& FixUtil::generate(bsl::ostream& stream,
1388 const DatetimeTz& object,
1389 const FixUtilConfiguration& configuration)
1390{
1391 char buffer[k_DATETIMETZ_STRLEN + 1];
1392
1393 const int len = generate(buffer,
1395 object,
1396 configuration);
1398
1399 return stream.write(buffer, len);
1400}
1401
1402inline
1403int FixUtil::generateRaw(char *buffer, const Date& object)
1404{
1405 BSLS_ASSERT(buffer);
1406
1407 return generateRaw(buffer,
1408 object,
1410}
1411
1412inline
1413int FixUtil::generateRaw(char *buffer, const Time& object)
1414{
1415 BSLS_ASSERT(buffer);
1416
1417 return generateRaw(buffer,
1418 object,
1420}
1421
1422inline
1423int FixUtil::generateRaw(char *buffer, const Datetime& object)
1424{
1425 BSLS_ASSERT(buffer);
1426
1427 return generateRaw(buffer,
1428 object,
1430}
1431
1432inline
1433int FixUtil::generateRaw(char *buffer, const DateTz& object)
1434{
1435 BSLS_ASSERT(buffer);
1436
1437 return generateRaw(buffer,
1438 object,
1440}
1441
1442inline
1443int FixUtil::generateRaw(char *buffer, const TimeTz& object)
1444{
1445 BSLS_ASSERT(buffer);
1446
1447 return generateRaw(buffer,
1448 object,
1450}
1451
1452inline
1453int FixUtil::generateRaw(char *buffer, const DatetimeTz& object)
1454{
1455 BSLS_ASSERT(buffer);
1456
1457 return generateRaw(buffer,
1458 object,
1460}
1461
1462inline
1463int FixUtil::parse(Date *result, const bsl::string_view& string)
1464{
1465 BSLS_ASSERT(string.data());
1466
1467 return parse(result, string.data(), static_cast<int>(string.length()));
1468}
1469
1470inline
1471int FixUtil::parse(Time *result, const bsl::string_view& string)
1472{
1473 BSLS_ASSERT(string.data());
1474
1475 return parse(result, string.data(), static_cast<int>(string.length()));
1476}
1477
1478inline
1479int FixUtil::parse(Datetime *result, const bsl::string_view& string)
1480{
1481 BSLS_ASSERT(string.data());
1482
1483 return parse(result, string.data(), static_cast<int>(string.length()));
1484}
1485
1486inline
1487int FixUtil::parse(DateTz *result, const bsl::string_view& string)
1488{
1489 BSLS_ASSERT(string.data());
1490
1491 return parse(result, string.data(), static_cast<int>(string.length()));
1492}
1493
1494inline
1495int FixUtil::parse(TimeTz *result, const bsl::string_view& string)
1496{
1497 BSLS_ASSERT(string.data());
1498
1499 return parse(result, string.data(), static_cast<int>(string.length()));
1500}
1501
1502inline
1503int FixUtil::parse(DatetimeTz *result, const bsl::string_view& string)
1504{
1505 BSLS_ASSERT(string.data());
1506
1507 return parse(result, string.data(), static_cast<int>(string.length()));
1508}
1509
1510} // close package namespace
1511
1512
1513#endif
1514
1515// ----------------------------------------------------------------------------
1516// Copyright 2017 Bloomberg Finance L.P.
1517//
1518// Licensed under the Apache License, Version 2.0 (the "License");
1519// you may not use this file except in compliance with the License.
1520// You may obtain a copy of the License at
1521//
1522// http://www.apache.org/licenses/LICENSE-2.0
1523//
1524// Unless required by applicable law or agreed to in writing, software
1525// distributed under the License is distributed on an "AS IS" BASIS,
1526// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1527// See the License for the specific language governing permissions and
1528// limitations under the License.
1529// ----------------------------- END-OF-FILE ----------------------------------
1530
1531/** @} */
1532/** @} */
1533/** @} */
Definition bdlt_datetz.h:161
Definition bdlt_date.h:294
Definition bdlt_datetimetz.h:308
Definition bdlt_datetime.h:330
Definition bdlt_fixutilconfiguration.h:205
static FixUtilConfiguration defaultConfiguration()
Definition bdlt_fixutilconfiguration.h:368
Definition bdlt_timetz.h:190
Definition bdlt_time.h:195
Definition bslstl_stringview.h:471
Definition bslstl_string.h:1252
#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
Definition bdlt_fixutil.h:547
static int generate(bsl::string *string, const Time &object, const FixUtilConfiguration &configuration)
static int generate(char *buffer, int bufferLength, const Time &object, const FixUtilConfiguration &configuration)
static int generate(char *buffer, int bufferLength, const DatetimeTz &object, const FixUtilConfiguration &configuration)
static int parse(Time *result, const char *string, int length)
static int generateRaw(char *buffer, const Date &object, const FixUtilConfiguration &configuration)
static int parse(Date *result, const char *string, int length)
static int generate(std::string *string, const Datetime &object, const FixUtilConfiguration &configuration)
static int generate(std::string *string, const Date &object, const FixUtilConfiguration &configuration)
static int generateRaw(char *buffer, const Date &object)
Definition bdlt_fixutil.h:1403
@ k_DATETZ_STRLEN
Definition bdlt_fixutil.h:558
@ k_DATETIMETZ_STRLEN
Definition bdlt_fixutil.h:564
@ k_DATETIME_STRLEN
Definition bdlt_fixutil.h:563
@ k_TIME_STRLEN
Definition bdlt_fixutil.h:560
@ k_TIMETZ_STRLEN
Definition bdlt_fixutil.h:561
@ k_MAX_STRLEN
Definition bdlt_fixutil.h:566
@ k_DATE_STRLEN
Definition bdlt_fixutil.h:557
static int generate(std::string *string, const DateTz &object, const FixUtilConfiguration &configuration)
static int generate(char *buffer, int bufferLength, const Datetime &object, const FixUtilConfiguration &configuration)
static int parse(DateTz *result, const char *string, int length)
static int generate(std::string *string, const TimeTz &object, const FixUtilConfiguration &configuration)
static int generate(std::string *string, const DatetimeTz &object, const FixUtilConfiguration &configuration)
static int generate(bsl::string *string, const Date &object, const FixUtilConfiguration &configuration)
static int parse(Datetime *result, const char *string, int length)
static int generateRaw(char *buffer, const Datetime &object, const FixUtilConfiguration &configuration)
static int generateRaw(char *buffer, const DatetimeTz &object, const FixUtilConfiguration &configuration)
static int generate(bsl::string *string, const TimeTz &object, const FixUtilConfiguration &configuration)
static int generate(bsl::string *string, const Datetime &object, const FixUtilConfiguration &configuration)
static int parse(DatetimeTz *result, const char *string, int length)
static int generate(bsl::string *string, const DateTz &object, const FixUtilConfiguration &configuration)
static int generate(char *buffer, int bufferLength, const Date &object)
Definition bdlt_fixutil.h:1052
static int parse(TimeTz *result, const char *string, int length)
static int generate(std::string *string, const Time &object, const FixUtilConfiguration &configuration)
static int generateRaw(char *buffer, const TimeTz &object, const FixUtilConfiguration &configuration)
static int generateRaw(char *buffer, const DateTz &object, const FixUtilConfiguration &configuration)
static int generateRaw(char *buffer, const Time &object, const FixUtilConfiguration &configuration)
static int generate(bsl::string *string, const DatetimeTz &object, const FixUtilConfiguration &configuration)
static int generate(char *buffer, int bufferLength, const Date &object, const FixUtilConfiguration &configuration)
static int generate(char *buffer, int bufferLength, const DateTz &object, const FixUtilConfiguration &configuration)
static int generate(char *buffer, int bufferLength, const TimeTz &object, const FixUtilConfiguration &configuration)