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

Detailed Description

Outline

Purpose

Provide an enumeration of the set of possible byte orders.

Classes

See also
bdlde_charconvertutf16

Description

This component provides a namespace for the enum type bdlde::ByteOrder::Enum, which enumerates the set of possible byte orders.

Enumerators

Name Description
--------------- ---------------------------------------------------
e_LITTLE_ENDIAN little-endian
e_BIG_ENDIAN big-endian
e_NETWORK network byte order (aliased to 'e_BIG_ENDIAN')
e_HOST aliased to 'e_LITTLE_ENDIAN' or 'e_BIG_ENDIAN' (depending
on platform)

Usage

This section illustrates intended use of this component.

Example 1: Basic Syntax

The following snippets of code provide a simple illustration of bdlde::ByteOrder usage.

First, we create a variable value of type bdlde::ByteOrder::Enum and initialize it with the enumerator value bdlde::ByteOrder::e_LITTLE_ENDIAN:

Enum
Definition bdlde_byteorder.h:134
@ e_LITTLE_ENDIAN
Definition bdlde_byteorder.h:135

Next, we store a pointer to its ASCII representation in a variable asciiValue of type const char *:

const char *asciiValue = bdlde::ByteOrder::toAscii(value);
assert(0 == bsl::strcmp(asciiValue, "LITTLE_ENDIAN"));
static const char * toAscii(Enum value)

Then, we try one of the aliased identifiers, and we get a string corresponding to the value it is aliased to:

asciiValue = bdlde::ByteOrder::toAscii(value);
assert(0 == bsl::strcmp(asciiValue, "BIG_ENDIAN"));
@ e_NETWORK
Definition bdlde_byteorder.h:138

Finally, we print value to bsl::cout:

bsl::cout << value << bsl::endl;

This statement produces the following output on stdout:

BIG_ENDIAN