BDE 4.14.0 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.
545struct FixUtil {
546
547 // TYPES
548
549 /// This enumeration defines fixed lengths for the FIX representations
550 /// of date, time, and datetime values. Note that these constants do
551 /// *not* account for the null terminator that may be produced by the
552 /// `generate` functions taking a `bufferLength` argument.
553 enum {
554 k_DATE_STRLEN = 8, // `bdlt::Date`
555 k_DATETZ_STRLEN = 14, // `bdlt::DateTz`
556
557 k_TIME_STRLEN = 15, // `bdlt::Time`
558 k_TIMETZ_STRLEN = 14, // `bdlt::TimeTz`
559
560 k_DATETIME_STRLEN = 24, // `bdlt::Datetime`
561 k_DATETIMETZ_STRLEN = 30, // `bdlt::DatetimeTz`
562
564 };
565
566 // CLASS METHODS
567
568 static int generate(char *buffer,
569 int bufferLength,
570 const Date& object);
571 static int generate(char *buffer,
572 int bufferLength,
573 const Date& object,
574 const FixUtilConfiguration& configuration);
575 static int generate(char *buffer,
576 int bufferLength,
577 const Time& object);
578 static int generate(char *buffer,
579 int bufferLength,
580 const Time& object,
581 const FixUtilConfiguration& configuration);
582 static int generate(char *buffer,
583 int bufferLength,
584 const Datetime& object);
585 static int generate(char *buffer,
586 int bufferLength,
587 const Datetime& object,
588 const FixUtilConfiguration& configuration);
589 static int generate(char *buffer,
590 int bufferLength,
591 const DateTz& object);
592 static int generate(char *buffer,
593 int bufferLength,
594 const DateTz& object,
595 const FixUtilConfiguration& configuration);
596 static int generate(char *buffer,
597 int bufferLength,
598 const TimeTz& object);
599 static int generate(char *buffer,
600 int bufferLength,
601 const TimeTz& object,
602 const FixUtilConfiguration& configuration);
603 static int generate(char *buffer,
604 int bufferLength,
605 const DatetimeTz& object);
606 static int generate(char *buffer,
607 int bufferLength,
608 const DatetimeTz& object,
609 const FixUtilConfiguration& configuration);
610
611 static int generate(bsl::string *string,
612 const Date& object);
613 static int generate(bsl::string *string,
614 const Date& object,
615 const FixUtilConfiguration& configuration);
616 static int generate(bsl::string *string,
617 const Time& object);
618 static int generate(bsl::string *string,
619 const Time& object,
620 const FixUtilConfiguration& configuration);
621 static int generate(bsl::string *string,
622 const Datetime& object);
623 static int generate(bsl::string *string,
624 const Datetime& object,
625 const FixUtilConfiguration& configuration);
626 static int generate(bsl::string *string,
627 const DateTz& object);
628 static int generate(bsl::string *string,
629 const DateTz& object,
630 const FixUtilConfiguration& configuration);
631 static int generate(bsl::string *string,
632 const TimeTz& object);
633 static int generate(bsl::string *string,
634 const TimeTz& object,
635 const FixUtilConfiguration& configuration);
636 static int generate(bsl::string *string,
637 const DatetimeTz& object);
638 static int generate(bsl::string *string,
639 const DatetimeTz& object,
640 const FixUtilConfiguration& configuration);
641
642 static int generate(std::string *string,
643 const Date& object);
644 static int generate(std::string *string,
645 const Date& object,
646 const FixUtilConfiguration& configuration);
647 static int generate(std::string *string,
648 const Time& object);
649 static int generate(std::string *string,
650 const Time& object,
651 const FixUtilConfiguration& configuration);
652 static int generate(std::string *string,
653 const Datetime& object);
654 static int generate(std::string *string,
655 const Datetime& object,
656 const FixUtilConfiguration& configuration);
657 static int generate(std::string *string,
658 const DateTz& object);
659 static int generate(std::string *string,
660 const DateTz& object,
661 const FixUtilConfiguration& configuration);
662 static int generate(std::string *string,
663 const TimeTz& object);
664 static int generate(std::string *string,
665 const TimeTz& object,
666 const FixUtilConfiguration& configuration);
667 static int generate(std::string *string,
668 const DatetimeTz& object);
669 /// Write the FIX representation of the specified `object` to the
670 /// specified `buffer` of the specified `bufferLength` (in bytes),
671 /// truncating (if necessary) to `bufferLength`. Optionally specify a
672 /// `configuration` to affect the format of the generated string. If
673 /// `configuration` is not supplied, the process-wide default value
674 /// `FixUtilConfiguration::defaultConfiguration()` is used. Return the
675 /// number of characters in the formatted string before truncation (not
676 /// counting a null terminator). If `bufferLength` indicates sufficient
677 /// capacity, `buffer` is null terminated. The behavior is undefined
678 /// unless `0 <= bufferLength`. Note that a buffer of size
679 /// `k_MAX_STRLEN + 1` is large enough to hold any string generated by
680 /// this component (counting a null terminator, if any).
681 static int generate(std::string *string,
682 const DatetimeTz& object,
683 const FixUtilConfiguration& configuration);
684
685#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
686 static int generate(std::pmr::string *string,
687 const Date& object);
688 static int generate(std::pmr::string *string,
689 const Date& object,
690 const FixUtilConfiguration& configuration);
691 static int generate(std::pmr::string *string,
692 const Time& object);
693 static int generate(std::pmr::string *string,
694 const Time& object,
695 const FixUtilConfiguration& configuration);
696 static int generate(std::pmr::string *string,
697 const Datetime& object);
698 static int generate(std::pmr::string *string,
699 const Datetime& object,
700 const FixUtilConfiguration& configuration);
701 static int generate(std::pmr::string *string,
702 const DateTz& object);
703 static int generate(std::pmr::string *string,
704 const DateTz& object,
705 const FixUtilConfiguration& configuration);
706 static int generate(std::pmr::string *string,
707 const TimeTz& object);
708 static int generate(std::pmr::string *string,
709 const TimeTz& object,
710 const FixUtilConfiguration& configuration);
711 static int generate(std::pmr::string *string,
712 const DatetimeTz& object);
713 /// Load the FIX representation of the specified `object` into the
714 /// specified `string`. Optionally specify a `configuration` to affect
715 /// the format of the generated string. If `configuration` is not
716 /// supplied, the process-wide default value
717 /// `FixUtilConfiguration::defaultConfiguration()` is used. Return the
718 /// number of characters in the formatted string. The previous contents
719 /// of `string` (if any) are discarded.
720 static int generate(std::pmr::string *string,
721 const DatetimeTz& object,
722 const FixUtilConfiguration& configuration);
723#endif
724
725 /// Write the FIX representation of the specified `object` to the
726 /// specified `stream`. Optionally specify a `configuration` to affect
727 /// the format of the generated string. If `configuration` is not
728 /// supplied, the process-wide default value
729 /// `FixUtilConfiguration::defaultConfiguration()` is used. Return a
730 /// reference to `stream`. Note that `stream` is not null terminated.
731 static bsl::ostream& generate(bsl::ostream& stream,
732 const Date& object);
733 static bsl::ostream& generate(bsl::ostream& stream,
734 const Date& object,
735 const FixUtilConfiguration& configuration);
736 static bsl::ostream& generate(bsl::ostream& stream,
737 const Time& object);
738 static bsl::ostream& generate(bsl::ostream& stream,
739 const Time& object,
740 const FixUtilConfiguration& configuration);
741 static bsl::ostream& generate(bsl::ostream& stream,
742 const Datetime& object);
743 static bsl::ostream& generate(bsl::ostream& stream,
744 const Datetime& object,
745 const FixUtilConfiguration& configuration);
746 static bsl::ostream& generate(bsl::ostream& stream,
747 const DateTz& object);
748 static bsl::ostream& generate(bsl::ostream& stream,
749 const DateTz& object,
750 const FixUtilConfiguration& configuration);
751 static bsl::ostream& generate(bsl::ostream& stream,
752 const TimeTz& object);
753 static bsl::ostream& generate(bsl::ostream& stream,
754 const TimeTz& object,
755 const FixUtilConfiguration& configuration);
756 static bsl::ostream& generate(bsl::ostream& stream,
757 const DatetimeTz& object);
758 static bsl::ostream& generate(bsl::ostream& stream,
759 const DatetimeTz& object,
760 const FixUtilConfiguration& configuration);
761
762 static int generateRaw(char *buffer,
763 const Date& object);
764 static int generateRaw(char *buffer,
765 const Date& object,
766 const FixUtilConfiguration& configuration);
767 static int generateRaw(char *buffer,
768 const Time& object);
769 static int generateRaw(char *buffer,
770 const Time& object,
771 const FixUtilConfiguration& configuration);
772 static int generateRaw(char *buffer,
773 const Datetime& object);
774 static int generateRaw(char *buffer,
775 const Datetime& object,
776 const FixUtilConfiguration& configuration);
777 static int generateRaw(char *buffer,
778 const DateTz& object);
779 static int generateRaw(char *buffer,
780 const DateTz& object,
781 const FixUtilConfiguration& configuration);
782 static int generateRaw(char *buffer,
783 const TimeTz& object);
784 static int generateRaw(char *buffer,
785 const TimeTz& object,
786 const FixUtilConfiguration& configuration);
787 static int generateRaw(char *buffer,
788 const DatetimeTz& object);
789 /// Write the FIX representation of the specified `object` to the
790 /// specified `buffer`. Optionally specify a `configuration` to affect
791 /// the format of the generated string. If `configuration` is not
792 /// supplied, the process-wide default value
793 /// `FixUtilConfiguration::defaultConfiguration()` is used. Return the
794 /// number of characters in the formatted string. `buffer` is not null
795 /// terminated. The behavior is undefined unless `buffer` has
796 /// sufficient capacity. Note that a buffer of size `k_MAX_STRLEN + 1`
797 /// is large enough to hold any string generated by this component
798 /// (counting a null terminator, if any).
799 static int generateRaw(char *buffer,
800 const DatetimeTz& object,
801 const FixUtilConfiguration& configuration);
802
803 /// Parse the specified initial `length` characters of the specified FIX
804 /// `string` as a `Date` value, and load the value into the specified
805 /// `result`. Return 0 on success, and a non-zero value (with no
806 /// effect) otherwise. `string` is assumed to be of the form:
807 /// @code
808 /// YYYYMMDD{(+|-)hh{:mm}|Z}
809 /// @endcode
810 /// *Exactly* `length` characters are parsed; parsing will fail if a
811 /// proper prefix of `string` matches the expected format, but the
812 /// entire `length` characters do not. If the optional timezone offset
813 /// is present in `string`, it is parsed but ignored. The behavior is
814 /// undefined unless `0 <= length`.
815 static int parse(Date *result, const char *string, int length);
816
817 /// Parse the specified initial `length` characters of the specified FIX
818 /// `string` as a `Time` value, and load the value into the specified
819 /// `result`. Return 0 on success, and a non-zero value (with no
820 /// effect) otherwise. `string` is assumed to be of the form:
821 /// @code
822 /// hh:mm:ss{.s+}{(+|-)hh{:mm}|Z}
823 /// @endcode
824 /// *Exactly* `length` characters are parsed; parsing will fail if a
825 /// proper prefix of `string` matches the expected format, but the
826 /// entire `length` characters do not. If an optional fractional second
827 /// having more than six digits is present in `string`, it is rounded
828 /// to the nearest value in microseconds. If the optional timezone
829 /// offset is present in `string`, the resulting `Time` value is
830 /// converted to the equivalent UTC time; if the timezone offset is
831 /// absent, UTC is assumed. If a leap second is detected (i.e., the
832 /// parsed value of the `second` attribute is 60; see {Leap Seconds}),
833 /// the `second` attribute is taken to be 59, then an additional second
834 /// is added to `result` at the end. The behavior is undefined unless
835 /// `0 <= length`.
836 static int parse(Time *result, const char *string, int length);
837
838 /// Parse the specified initial `length` characters of the specified FIX
839 /// `string` as a `Datetime` value, and load the value into the
840 /// specified `result`. Return 0 on success, and a non-zero value (with
841 /// no effect) otherwise. `string` is assumed to be of the form:
842 /// @code
843 /// YYYYMMDD-hh:mm{:ss{.s+}}{(+|-)hh{:mm}|Z}
844 /// @endcode
845 /// *Exactly* `length` characters are parsed; parsing will fail if a
846 /// proper prefix of `string` matches the expected format, but the
847 /// entire `length` characters do not. If an optional fractional second
848 /// having more than six digits is present in `string`, it is rounded to
849 /// the nearest value in microseconds. If the optional timezone offset
850 /// is present in `string`, the resulting `Datetime` value is converted
851 /// to the equivalent UTC value; if the timezone offset is absent, UTC
852 /// is assumed. If a leap second is detected (i.e., the parsed value of
853 /// the `second` attribute is 60; see {Leap Seconds}), the `second`
854 /// attribute is taken to be 59, then an additional second is added to
855 /// `result` at the end. The behavior is undefined unless
856 /// `0 <= length`.
857 static int parse(Datetime *result, const char *string, int length);
858
859 /// Parse the specified initial `length` characters of the specified FIX
860 /// `string` as a `DateTz` value, and load the value into the specified
861 /// `result`. Return 0 on success, and a non-zero value (with no
862 /// effect) otherwise. `string` is assumed to be of the form:
863 /// @code
864 /// YYYYMMDD{(+|-)hh{:mm}|Z}
865 /// @endcode
866 /// *Exactly* `length` characters are parsed; parsing will fail if a
867 /// proper prefix of `string` matches the expected format, but the
868 /// entire `length` characters do not. If the optional timezone offset
869 /// is not present in `string`, UTC is assumed. The behavior is
870 /// undefined unless `0 <= length`.
871 static int parse(DateTz *result, const char *string, int length);
872
873 /// Parse the specified initial `length` characters of the specified FIX
874 /// `string` as a `TimeTz` value, and load the value into the specified
875 /// `result`. Return 0 on success, and a non-zero value (with no
876 /// effect) otherwise. `string` is assumed to be of the form:
877 /// @code
878 /// hh:mm{:ss{.s+}}{(+|-)hh{:mm}|Z}
879 /// @endcode
880 /// *Exactly* `length` characters are parsed; parsing will fail if a
881 /// proper prefix of `string` matches the expected format, but the
882 /// entire `length` characters do not. If an optional fractional second
883 /// having more than six digits is present in `string`, it is rounded
884 /// to the nearest value in microseconds. If the optional timezone
885 /// offset is not present in `string`, UTC is assumed. If a leap second
886 /// is detected (i.e., the parsed value of the `second` attribute is 60;
887 /// see {Leap Seconds}), the `second` attribute is taken to be 59, then
888 /// an additional second is added to `result` at the end. The behavior
889 /// is undefined unless `0 <= length`.
890 static int parse(TimeTz *result, const char *string, int length);
891
892 /// Parse the specified initial `length` characters of the specified FIX
893 /// `string` as a `DatetimeTz` value, and load the value into the
894 /// specified `result`. Return 0 on success, and a non-zero value (with
895 /// no effect) otherwise. `string` is assumed to be of the form:
896 /// @code
897 /// YYYYMMDD-hh:mm{:ss{.s+}}{(+|-)hh{:mm}|Z}
898 /// @endcode
899 /// *Exactly* `length` characters are parsed; parsing will fail if a
900 /// proper prefix of `string` matches the expected format, but the
901 /// entire `length` characters do not. If an optional fractional second
902 /// having more than six digits is present in `string`, it is rounded to
903 /// the nearest value in microseconds. If the optional timezone offset
904 /// is not present in `string`, UTC is assumed. If a leap second is
905 /// detected (i.e., the parsed value of the `second` attribute is 60;
906 /// see {Leap Seconds}), the `second` attribute is taken to be 59, then
907 /// an additional second is added to `result` at the end. The behavior
908 /// is undefined unless `0 <= length`.
909 static int parse(DatetimeTz *result, const char *string, int length);
910
911 /// Parse the specified FIX `string` as a `Date` value, and load the
912 /// value into the specified `result`. Return 0 on success, and a
913 /// non-zero value (with no effect) otherwise. `string` is assumed to
914 /// be of the form:
915 /// @code
916 /// YYYYMMDD{(+|-)hh{:mm}|Z}
917 /// @endcode
918 /// *Exactly* `string.length()` characters are parsed; parsing will fail
919 /// if a proper prefix of `string` matches the expected format, but the
920 /// entire `string.length()` characters do not. If the optional
921 /// timezone offset is present in `string`, it is parsed but ignored.
922 /// The behavior is undefined unless `string.data()` is non-null.
923 static int parse(Date *result, const bsl::string_view& string);
924
925 /// Parse the specified FIX `string` as a `Time` 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 /// hh:mm{:ss{.s+}}{(+|-)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 an optional
935 /// fractional second having more than six digits is present in
936 /// `string`, it is rounded to the nearest value in microseconds. If
937 /// the optional timezone offset is present in `string`, the resulting
938 /// `Time` value is converted to the equivalent UTC time; if the
939 /// timezone offset is absent, UTC is assumed. If a leap second is
940 /// detected (i.e., the parsed value of the `second` attribute is 60;
941 /// see {Leap Seconds}), the `second` attribute is taken to be 59, then
942 /// an additional second is added to `result` at the end. The behavior
943 /// is undefined unless `string.data()` is non-null.
944 static int parse(Time *result, const bsl::string_view& string);
945
946 /// Parse the specified FIX `string` as a `Datetime` value, and load the
947 /// value into the specified `result`. Return 0 on success, and a
948 /// non-zero value (with no effect) otherwise. `string` is assumed to
949 /// be of the form:
950 /// @code
951 /// YYYYMMDD-hh:mm{:ss{.s+}}{(+|-)hh{:mm}|Z}
952 /// @endcode
953 /// *Exactly* `string.length()` characters are parsed; parsing will fail
954 /// if a proper prefix of `string` matches the expected format, but the
955 /// entire `string.length()` characters do not. If an optional
956 /// fractional second having more than six digits is present in
957 /// `string`, it is rounded to the nearest value in microseconds. If
958 /// the optional timezone offset is present in `string`, the resulting
959 /// `Datetime` value is converted to the equivalent UTC value; if the
960 /// timezone offset is absent, UTC is assumed. If a leap second is
961 /// detected (i.e., the parsed value of the `second` attribute is 60;
962 /// see {Leap Seconds}), the `second` attribute is taken to be 59, then
963 /// an additional second is added to `result` at the end. The behavior
964 /// is undefined unless `string.data()` is non-null.
965 static int parse(Datetime *result, const bsl::string_view& string);
966
967 /// Parse the specified FIX `string` as a `DateTz` value, and load the
968 /// value into the specified `result`. Return 0 on success, and a
969 /// non-zero value (with no effect) otherwise. `string` is assumed to
970 /// be of the form:
971 /// @code
972 /// YYYYMMDD{(+|-)hh{:mm}|Z}
973 /// @endcode
974 /// *Exactly* `string.length()` characters are parsed; parsing will fail
975 /// if a proper prefix of `string` matches the expected format, but the
976 /// entire `string.length()` characters do not. If the optional
977 /// timezone offset is not present in `string`, UTC is assumed. The
978 /// behavior is undefined unless `string.data()` is non-null.
979 static int parse(DateTz *result, const bsl::string_view& string);
980
981 /// Parse the specified FIX `string` as a `TimeTz` value, and load the
982 /// value into the specified `result`. Return 0 on success, and a
983 /// non-zero value (with no effect) otherwise. `string` is assumed to
984 /// be of the form:
985 /// @code
986 /// hh:mm{:ss{.s+}}{(+|-)hh{:mm}|Z}
987 /// @endcode
988 /// *Exactly* `string.length()` characters are parsed; parsing will fail
989 /// if a proper prefix of `string` matches the expected format, but the
990 /// entire `string.length()` characters do not. If an optional
991 /// fractional second having more than six digits is present in
992 /// `string`, it is rounded to the nearest value in microseconds. If
993 /// the optional timezone offset is not present in `string`, UTC is
994 /// assumed. If a leap second is detected (i.e., the parsed value of
995 /// the `second` attribute is 60; see {Leap Seconds}), the `second`
996 /// attribute is taken to be 59, then an additional second is added to
997 /// `result` at the end. The behavior is undefined unless
998 /// `string.data()` is non-null.
999 static int parse(TimeTz *result, const bsl::string_view& string);
1000
1001 /// Parse the specified FIX `string` as a `DatetimeTz` value, and load
1002 /// the value into the specified `result`. Return 0 on success, and a
1003 /// non-zero value (with no effect) otherwise. `string` is assumed to
1004 /// be of the form:
1005 /// @code
1006 /// YYYYMMDD-hh:mm{:ss{.s+}}{(+|-)hh{:mm}|Z}
1007 /// @endcode
1008 /// *Exactly* `string.length()` characters are parsed; parsing will fail
1009 /// if a proper prefix of `string` matches the expected format, but the
1010 /// entire `string.length()` characters do not. If an optional
1011 /// fractional second having more than six digits is present in
1012 /// `string`, it is rounded to the nearest value in microseconds. If
1013 /// the optional timezone offset is not present in `string`, UTC is
1014 /// assumed. If a leap second is detected (i.e., the parsed value of
1015 /// the `second` attribute is 60; see {Leap Seconds}), the `second`
1016 /// attribute is taken to be 59, then an additional second is added to
1017 /// `result` at the end. The behavior is undefined unless
1018 /// `string.data()` is non-null.
1019 static int parse(DatetimeTz *result, const bsl::string_view& string);
1020};
1021
1022// ============================================================================
1023// INLINE DEFINITIONS
1024// ============================================================================
1025
1026 // --------------
1027 // struct FixUtil
1028 // --------------
1029
1030// CLASS METHODS
1031inline
1032int FixUtil::generate(char *buffer, int bufferLength, const Date& object)
1033{
1034 BSLS_ASSERT(buffer);
1035 BSLS_ASSERT(0 <= bufferLength);
1036
1037 return generate(buffer,
1038 bufferLength,
1039 object,
1041}
1042
1043inline
1044int FixUtil::generate(char *buffer, int bufferLength, const Time& object)
1045{
1046 BSLS_ASSERT(buffer);
1047 BSLS_ASSERT(0 <= bufferLength);
1048
1049 return generate(buffer,
1050 bufferLength,
1051 object,
1053}
1054
1055inline
1056int
1057FixUtil::generate(char *buffer, int bufferLength, const Datetime& object)
1058{
1059 BSLS_ASSERT(buffer);
1060 BSLS_ASSERT(0 <= bufferLength);
1061
1062 return generate(buffer,
1063 bufferLength,
1064 object,
1066}
1067
1068inline
1069int FixUtil::generate(char *buffer, int bufferLength, const DateTz& object)
1070{
1071 BSLS_ASSERT(buffer);
1072 BSLS_ASSERT(0 <= bufferLength);
1073
1074 return generate(buffer,
1075 bufferLength,
1076 object,
1078}
1079
1080inline
1081int FixUtil::generate(char *buffer, int bufferLength, const TimeTz& object)
1082{
1083 BSLS_ASSERT(buffer);
1084 BSLS_ASSERT(0 <= bufferLength);
1085
1086 return generate(buffer,
1087 bufferLength,
1088 object,
1090}
1091
1092inline
1093int
1094FixUtil::generate(char *buffer, int bufferLength, const DatetimeTz& object)
1095{
1096 BSLS_ASSERT(buffer);
1097 BSLS_ASSERT(0 <= bufferLength);
1098
1099 return generate(buffer,
1100 bufferLength,
1101 object,
1103}
1104
1105inline
1106int FixUtil::generate(bsl::string *string, const Date& object)
1107{
1108 return generate(string,
1109 object,
1111}
1112
1113inline
1114int FixUtil::generate(bsl::string *string, const Time& object)
1115{
1116 return generate(string,
1117 object,
1119}
1120
1121inline
1122int FixUtil::generate(bsl::string *string, const Datetime& object)
1123{
1124 return generate(string,
1125 object,
1127}
1128
1129inline
1130int FixUtil::generate(bsl::string *string, const DateTz& object)
1131{
1132 return generate(string,
1133 object,
1135}
1136
1137inline
1138int FixUtil::generate(bsl::string *string, const TimeTz& object)
1139{
1140 return generate(string,
1141 object,
1143}
1144
1145inline
1146int FixUtil::generate(bsl::string *string, const DatetimeTz& object)
1147{
1148 return generate(string,
1149 object,
1151}
1152
1153inline
1154int FixUtil::generate(std::string *string, const Date& object)
1155{
1156 return generate(string,
1157 object,
1159}
1160
1161inline
1162int FixUtil::generate(std::string *string, const Time& object)
1163{
1164 return generate(string,
1165 object,
1167}
1168
1169inline
1170int FixUtil::generate(std::string *string, const Datetime& object)
1171{
1172 return generate(string,
1173 object,
1175}
1176
1177inline
1178int FixUtil::generate(std::string *string, const DateTz& object)
1179{
1180 return generate(string,
1181 object,
1183}
1184
1185inline
1186int FixUtil::generate(std::string *string, const TimeTz& object)
1187{
1188 return generate(string,
1189 object,
1191}
1192
1193inline
1194int FixUtil::generate(std::string *string, const DatetimeTz& object)
1195{
1196 return generate(string,
1197 object,
1199}
1200
1201#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
1202inline
1203int FixUtil::generate(std::pmr::string *string, const Date& object)
1204{
1205 return generate(string,
1206 object,
1208}
1209
1210inline
1211int FixUtil::generate(std::pmr::string *string, const Time& object)
1212{
1213 return generate(string,
1214 object,
1216}
1217
1218inline
1219int FixUtil::generate(std::pmr::string *string, const Datetime& object)
1220{
1221 return generate(string,
1222 object,
1224}
1225
1226inline
1227int FixUtil::generate(std::pmr::string *string, const DateTz& object)
1228{
1229 return generate(string,
1230 object,
1232}
1233
1234inline
1235int FixUtil::generate(std::pmr::string *string, const TimeTz& object)
1236{
1237 return generate(string,
1238 object,
1240}
1241
1242inline
1243int FixUtil::generate(std::pmr::string *string, const DatetimeTz& object)
1244{
1245 return generate(string,
1246 object,
1248}
1249#endif
1250
1251inline
1252bsl::ostream& FixUtil::generate(bsl::ostream& stream, const Date& object)
1253{
1254 return generate(stream,
1255 object,
1257}
1258
1259inline
1260bsl::ostream& FixUtil::generate(bsl::ostream& stream,
1261 const Date& object,
1262 const FixUtilConfiguration& configuration)
1263{
1264 char buffer[k_DATE_STRLEN + 1];
1265
1266 const int len = generate(buffer, k_DATE_STRLEN, object, configuration);
1267 BSLS_ASSERT(k_DATE_STRLEN >= len);
1268
1269 return stream.write(buffer, len);
1270}
1271
1272inline
1273bsl::ostream& FixUtil::generate(bsl::ostream& stream, const Time& object)
1274{
1275 return generate(stream,
1276 object,
1278}
1279
1280inline
1281bsl::ostream& FixUtil::generate(bsl::ostream& stream,
1282 const Time& object,
1283 const FixUtilConfiguration& configuration)
1284{
1285 char buffer[k_TIME_STRLEN + 1];
1286
1287 const int len = generate(buffer, k_TIME_STRLEN, object, configuration);
1288 BSLS_ASSERT(k_TIME_STRLEN >= len);
1289
1290 return stream.write(buffer, len);
1291}
1292
1293inline
1294bsl::ostream&
1295FixUtil::generate(bsl::ostream& stream, const Datetime& object)
1296{
1297 return generate(stream,
1298 object,
1300}
1301
1302inline
1303bsl::ostream& FixUtil::generate(bsl::ostream& stream,
1304 const Datetime& object,
1305 const FixUtilConfiguration& configuration)
1306{
1307 char buffer[k_DATETIME_STRLEN + 1];
1308
1309 const int len = generate(buffer, k_DATETIME_STRLEN, object, configuration);
1311
1312 return stream.write(buffer, len);
1313}
1314
1315inline
1316bsl::ostream& FixUtil::generate(bsl::ostream& stream, const DateTz& object)
1317{
1318 return generate(stream,
1319 object,
1321}
1322
1323inline
1324bsl::ostream& FixUtil::generate(bsl::ostream& stream,
1325 const DateTz& object,
1326 const FixUtilConfiguration& configuration)
1327{
1328 char buffer[k_DATETZ_STRLEN + 1];
1329
1330 const int len = generate(buffer, k_DATETZ_STRLEN, object, configuration);
1332
1333 return stream.write(buffer, len);
1334}
1335
1336inline
1337bsl::ostream& FixUtil::generate(bsl::ostream& stream, const TimeTz& object)
1338{
1339 return generate(stream,
1340 object,
1342}
1343
1344inline
1345bsl::ostream& FixUtil::generate(bsl::ostream& stream,
1346 const TimeTz& object,
1347 const FixUtilConfiguration& configuration)
1348{
1349 char buffer[k_TIMETZ_STRLEN + 1];
1350
1351 const int len = generate(buffer, k_TIMETZ_STRLEN, object, configuration);
1353
1354 return stream.write(buffer, len);
1355}
1356
1357inline
1358bsl::ostream&
1359FixUtil::generate(bsl::ostream& stream, const DatetimeTz& object)
1360{
1361 return generate(stream,
1362 object,
1364}
1365
1366inline
1367bsl::ostream& FixUtil::generate(bsl::ostream& stream,
1368 const DatetimeTz& object,
1369 const FixUtilConfiguration& configuration)
1370{
1371 char buffer[k_DATETIMETZ_STRLEN + 1];
1372
1373 const int len = generate(buffer,
1375 object,
1376 configuration);
1378
1379 return stream.write(buffer, len);
1380}
1381
1382inline
1383int FixUtil::generateRaw(char *buffer, const Date& object)
1384{
1385 BSLS_ASSERT(buffer);
1386
1387 return generateRaw(buffer,
1388 object,
1390}
1391
1392inline
1393int FixUtil::generateRaw(char *buffer, const Time& object)
1394{
1395 BSLS_ASSERT(buffer);
1396
1397 return generateRaw(buffer,
1398 object,
1400}
1401
1402inline
1403int FixUtil::generateRaw(char *buffer, const Datetime& object)
1404{
1405 BSLS_ASSERT(buffer);
1406
1407 return generateRaw(buffer,
1408 object,
1410}
1411
1412inline
1413int FixUtil::generateRaw(char *buffer, const DateTz& object)
1414{
1415 BSLS_ASSERT(buffer);
1416
1417 return generateRaw(buffer,
1418 object,
1420}
1421
1422inline
1423int FixUtil::generateRaw(char *buffer, const TimeTz& object)
1424{
1425 BSLS_ASSERT(buffer);
1426
1427 return generateRaw(buffer,
1428 object,
1430}
1431
1432inline
1433int FixUtil::generateRaw(char *buffer, const DatetimeTz& object)
1434{
1435 BSLS_ASSERT(buffer);
1436
1437 return generateRaw(buffer,
1438 object,
1440}
1441
1442inline
1443int FixUtil::parse(Date *result, const bsl::string_view& string)
1444{
1445 BSLS_ASSERT(string.data());
1446
1447 return parse(result, string.data(), static_cast<int>(string.length()));
1448}
1449
1450inline
1451int FixUtil::parse(Time *result, const bsl::string_view& string)
1452{
1453 BSLS_ASSERT(string.data());
1454
1455 return parse(result, string.data(), static_cast<int>(string.length()));
1456}
1457
1458inline
1459int FixUtil::parse(Datetime *result, const bsl::string_view& string)
1460{
1461 BSLS_ASSERT(string.data());
1462
1463 return parse(result, string.data(), static_cast<int>(string.length()));
1464}
1465
1466inline
1467int FixUtil::parse(DateTz *result, const bsl::string_view& string)
1468{
1469 BSLS_ASSERT(string.data());
1470
1471 return parse(result, string.data(), static_cast<int>(string.length()));
1472}
1473
1474inline
1475int FixUtil::parse(TimeTz *result, const bsl::string_view& string)
1476{
1477 BSLS_ASSERT(string.data());
1478
1479 return parse(result, string.data(), static_cast<int>(string.length()));
1480}
1481
1482inline
1483int FixUtil::parse(DatetimeTz *result, const bsl::string_view& string)
1484{
1485 BSLS_ASSERT(string.data());
1486
1487 return parse(result, string.data(), static_cast<int>(string.length()));
1488}
1489
1490} // close package namespace
1491
1492
1493#endif
1494
1495// ----------------------------------------------------------------------------
1496// Copyright 2017 Bloomberg Finance L.P.
1497//
1498// Licensed under the Apache License, Version 2.0 (the "License");
1499// you may not use this file except in compliance with the License.
1500// You may obtain a copy of the License at
1501//
1502// http://www.apache.org/licenses/LICENSE-2.0
1503//
1504// Unless required by applicable law or agreed to in writing, software
1505// distributed under the License is distributed on an "AS IS" BASIS,
1506// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1507// See the License for the specific language governing permissions and
1508// limitations under the License.
1509// ----------------------------- END-OF-FILE ----------------------------------
1510
1511/** @} */
1512/** @} */
1513/** @} */
Definition bdlt_datetz.h:162
Definition bdlt_date.h:294
Definition bdlt_datetimetz.h:308
Definition bdlt_datetime.h:331
Definition bdlt_fixutilconfiguration.h:206
static FixUtilConfiguration defaultConfiguration()
Definition bdlt_fixutilconfiguration.h:363
Definition bdlt_timetz.h:190
Definition bdlt_time.h:196
Definition bslstl_stringview.h:441
Definition bslstl_string.h:1281
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bbldc_basicisma30360.h:112
Definition bdlt_fixutil.h:545
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)
@ k_DATETZ_STRLEN
Definition bdlt_fixutil.h:555
@ k_DATETIMETZ_STRLEN
Definition bdlt_fixutil.h:561
@ k_DATETIME_STRLEN
Definition bdlt_fixutil.h:560
@ k_TIME_STRLEN
Definition bdlt_fixutil.h:557
@ k_TIMETZ_STRLEN
Definition bdlt_fixutil.h:558
@ k_MAX_STRLEN
Definition bdlt_fixutil.h:563
@ k_DATE_STRLEN
Definition bdlt_fixutil.h:554
static int generate(std::string *string, const Date &object, const FixUtilConfiguration &configuration)
static int generateRaw(char *buffer, const Date &object)
Definition bdlt_fixutil.h:1383
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:1032
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)