BDE 4.14.0 Production release
Loading...
Searching...
No Matches
baltzo_zoneinfobinaryheader

Detailed Description

Outline

Purpose

Provide an attribute class for Zoneinfo binary-file header data.

Classes

See also
baltzo_zoneinfobinaryreader

Description

This component provides a simply constrained attribute class, baltzo::ZoneinfoBinaryHeader, representing the header data of a Zoneinfo binary data file.

Attributes

Name Type Default Simple Constraints
----------------- ---- ------- ------------------
version char '\0' == '\0' || == '2' || == '3'
numIsGmt int 0 >= 0
numIsStd int 0 >= 0
numLeaps int 0 == 0
numTransitions int 0 >= 0
numLocalTimeTypes int 1 >= 1
abbrevDataSize int 1 >= 1

Usage

This section illustrates intended use of this component.

Example 1: Creating a baltzo::ZoneinfoBinaryHeader from User Input

We define the getNextZoneinfoBinaryHeader helper function, reads data from a stream, validates the data, and constructs a baltzo::ZoneinfoBinaryHeader object.

/// Set to the specified `object` the value extracted from the
/// specified `stream`. Return 0 on success, and a non-zero value
/// otherwise, with no change to `object`. The `stream` contains
/// white-space separated decimal representations of the attributes
/// of `baltzo::ZoneinfoBinaryHeader` in the following order: `version`,
/// `numIsGmt`, `numIsStd`, `numLeaps`, `numTransitions`,
/// `numLocalTimeTypes`, and `abbrevDataSize`.
int getNextZoneinfoBinaryHeader(baltzo::ZoneinfoBinaryHeader *object,
bsl::istream& stream)
{
int version; // not 'char'
int numIsGmt;
int numIsStd;
int numLeaps;
int numTransitions;
int numLocalTimeTypes;
int abbrevDataSize;
if (!(stream >> version
&& stream >> numIsGmt
&& stream >> numIsStd
&& stream >> numLeaps
&& stream >> numTransitions
&& stream >> numLocalTimeTypes
&& stream >> abbrevDataSize)) {
return 1; // RETURN
}
numTransitions)
numLocalTimeTypes)
abbrevDataSize))) {
return 2; // RETURN
}
object->setVersion(version);
object->setNumIsGmt(numIsGmt);
object->setNumIsStd(numIsStd);
object->setNumLeaps(numLeaps);
object->setNumTransitions(numTransitions);
object->setNumLocalTimeTypes(numLocalTimeTypes);
object->setAbbrevDataSize(abbrevDataSize);
return 0;
}
Definition baltzo_zoneinfobinaryheader.h:225
static bool isValidNumLocalTimeTypes(int value)
Definition baltzo_zoneinfobinaryheader.h:478
static bool isValidVersion(char value)
Definition baltzo_zoneinfobinaryheader.h:448
static bool isValidNumIsStd(int value)
Definition baltzo_zoneinfobinaryheader.h:460
static bool isValidNumIsGmt(int value)
Definition baltzo_zoneinfobinaryheader.h:454
static bool isValidNumLeaps(int value)
Definition baltzo_zoneinfobinaryheader.h:466
static bool isValidAbbrevDataSize(int value)
Definition baltzo_zoneinfobinaryheader.h:484
static bool isValidNumTransitions(int value)
Definition baltzo_zoneinfobinaryheader.h:472

To use our helper function, we supply it with a stream of (decimal, whitespace-separated values). The resulting object has the expected value.

bsl::stringstream input("50 1 2 0 3 4 5");
int rc;
rc = getNextZoneinfoBinaryHeader(&header, input);
assert( 0 == rc);
assert('2' == header.version());
assert( 1 == header.numIsGmt());
assert( 2 == header.numIsStd());
assert( 0 == header.numLeaps());
assert( 3 == header.numTransitions());
assert( 4 == header.numLocalTimeTypes());
assert( 5 == header.abbrevDataSize());
char version() const
Return the value of the version attribute of this object.
Definition baltzo_zoneinfobinaryheader.h:636
int numLocalTimeTypes() const
Definition baltzo_zoneinfobinaryheader.h:666
int numIsStd() const
Return the value of the numIsStd attribute of this object.
Definition baltzo_zoneinfobinaryheader.h:648
int numLeaps() const
Return the value of the numLeaps attribute of this object.
Definition baltzo_zoneinfobinaryheader.h:654
int numIsGmt() const
Return the value of the numIsGmt attribute of this object.
Definition baltzo_zoneinfobinaryheader.h:642
int numTransitions() const
Return the value of the numTransitions attribute of this object.
Definition baltzo_zoneinfobinaryheader.h:660
int abbrevDataSize() const
Return the value of the abbrevDataSize attribute of this object.
Definition baltzo_zoneinfobinaryheader.h:672
Definition bslstl_stringstream.h:184

Since all of the data in the stream has now been consumed, another call to the function returns an error and leaves the object unchanged.

header.setVersion(0);
header.setNumIsGmt(10);
header.setNumIsStd(20);
header.setNumLeaps(0);
header.setNumTransitions(30);
header.setAbbrevDataSize(50);
rc = getNextZoneinfoBinaryHeader(&header, input);
assert( 0 != rc);
assert('\0' == header.version());
assert( 10 == header.numIsGmt());
assert( 20 == header.numIsStd());
assert( 0 == header.numLeaps());
assert( 30 == header.numTransitions());
assert( 40 == header.numLocalTimeTypes());
assert( 50 == header.abbrevDataSize());
void setNumIsGmt(int value)
Definition baltzo_zoneinfobinaryheader.h:575
void setNumLeaps(int value)
Definition baltzo_zoneinfobinaryheader.h:591
void setNumLocalTimeTypes(int value)
Definition baltzo_zoneinfobinaryheader.h:607
void setAbbrevDataSize(int value)
Definition baltzo_zoneinfobinaryheader.h:615
void setVersion(char value)
Definition baltzo_zoneinfobinaryheader.h:567
void setNumTransitions(int value)
Definition baltzo_zoneinfobinaryheader.h:599
void setNumIsStd(int value)
Definition baltzo_zoneinfobinaryheader.h:583