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

Macros

#define BSLS_PLATFORMUTIL_IS_BIG_ENDIAN   BSLS_PLATFORM_IS_BIG_ENDIAN
 
#define BSLS_PLATFORMUTIL_HTONL(x)   (x)
 
#define BSLS_PLATFORMUTIL_HTONS(x)   (x)
 
#define BSLS_PLATFORMUTIL_NTOHL(x)   (x)
 
#define BSLS_PLATFORMUTIL_NTOHS(x)   (x)
 
#define BSLS_PLATFORMUTIL__IS_BIG_ENDIAN   BSLS_PLATFORMUTIL_IS_BIG_ENDIAN
 
#define BSLS_PLATFORMUTIL__HTONL(x)   BSLS_PLATFORMUTIL_HTONL(x)
 
#define BSLS_PLATFORMUTIL__HTONS(x)   BSLS_PLATFORMUTIL_HTONS(x)
 
#define BSLS_PLATFORMUTIL__NTOHL(x)   BSLS_PLATFORMUTIL_NTOHL(x)
 
#define BSLS_PLATFORMUTIL__NTOHS(x)   BSLS_PLATFORMUTIL_NTOHS(x)
 

Typedefs

typedef bsls::PlatformUtil bsls_PlatformUtil
 This alias is defined for backward compatibility.
 

Detailed Description

Outline

Purpose

Provide consistent interface for platform-dependent functionality.

Deprecated:
Use bsls_alignmentutil , bsls_byteorder , bsls_platform , and bsls_types instead.

Classes

Macros

See also
bsls_platform, bsls_types

Description

This component provides a namespace for a set of typedefs and functions that provide a stable, portable interface to platform-dependent functionality. In particular, this component supplies portable typenames for signed and unsigned 64-bit integers, and provides compile-time preprocessor macros that characterize the "endian-ness" of the underlying processor on the current platform. Runtime functionality to return the "endian-ness", and to round up to a multiple of the maximum required alignment for the processor, are also provided.

Usage

The following illustrates how some of the types and functions supplied by this component might be used.

Types

bsls::PlatformUtil::Int64 and bsls::PlatformUtil::Uint64 identify the preferred fundamental types denoting signed and unsigned 64-bit integers, respectively:

bsls::PlatformUtil::Uint64 stimulus = 787000000000ULL;
Types::Uint64 Uint64
Definition bsls_platformutil.h:201

Clients can use these types in the same way as an int. Clients can also mix usage with other fundamental integral types:

bsls::PlatformUtil::Uint64 nationalDebt = 1000000000000ULL;
nationalDebt += stimulus;
unsigned int deficitReduction = 1000000000;
nationalDebt -= deficitReduction;
std::cout << "National Debt Level: " << nationalDebt << std::endl;

bsls::PlatformUtil::size_type identifies the preferred integral type denoting the number of elements in a container, and the number of bytes in a single block of memory supplied by an allocator. For example, a typical use is as a typedef in an STL container:

class vector {
// ...
public:
typedef bsls::PlatformUtil::size_type size_type;
// ...
};
Types::size_type size_type
Definition bsls_platformutil.h:185

Functions and Macros

The functions:

static bool isLittleEndian()
Definition bsls_platformutil.h:315
static bool isBigEndian()
Definition bsls_platformutil.h:325

encapsulate the capability of determining whether a machine is big- or little-endian across all supported platforms. In addition, certain compile-time constants are also provided as preprocessor macros to facilitate conditional compilation:

BSLS_PLATFORMUTIL_IS_LITTLE_ENDIAN
#define BSLS_PLATFORMUTIL_IS_BIG_ENDIAN
Definition bsls_platformutil.h:272

These functions and macros are useful for writing platform-independent code, such as a function that converts the bytes in a short to network byte order (which is consistent with big-endian):

short convertToNetworkByteOrder(short input)
// Return the specified 'input' in network byte order.
{
#ifdef BSLS_PLATFORMUTIL_IS_BIG_ENDIAN
return input;
#else
return static_cast<short>(
((input >> 8) & 0xFF) | ((input & 0xFF) << 8));
#endif
}

Note that in the above usage example, either the macros or the functions can be used to test whether a platform is big- or little-endian.

Macro Definition Documentation

◆ BSLS_PLATFORMUTIL__HTONL

#define BSLS_PLATFORMUTIL__HTONL (   x)    BSLS_PLATFORMUTIL_HTONL(x)

◆ BSLS_PLATFORMUTIL__HTONS

#define BSLS_PLATFORMUTIL__HTONS (   x)    BSLS_PLATFORMUTIL_HTONS(x)

◆ BSLS_PLATFORMUTIL__IS_BIG_ENDIAN

#define BSLS_PLATFORMUTIL__IS_BIG_ENDIAN   BSLS_PLATFORMUTIL_IS_BIG_ENDIAN

◆ BSLS_PLATFORMUTIL__NTOHL

#define BSLS_PLATFORMUTIL__NTOHL (   x)    BSLS_PLATFORMUTIL_NTOHL(x)

◆ BSLS_PLATFORMUTIL__NTOHS

#define BSLS_PLATFORMUTIL__NTOHS (   x)    BSLS_PLATFORMUTIL_NTOHS(x)

◆ BSLS_PLATFORMUTIL_HTONL

#define BSLS_PLATFORMUTIL_HTONL (   x)    (x)

◆ BSLS_PLATFORMUTIL_HTONS

#define BSLS_PLATFORMUTIL_HTONS (   x)    (x)

◆ BSLS_PLATFORMUTIL_IS_BIG_ENDIAN

#define BSLS_PLATFORMUTIL_IS_BIG_ENDIAN   BSLS_PLATFORM_IS_BIG_ENDIAN
Deprecated:
Use preprocessor macro BSLS_PLATFORM_IS_BIG_ENDIAN defined in bsls_platform instead.

◆ BSLS_PLATFORMUTIL_NTOHL

#define BSLS_PLATFORMUTIL_NTOHL (   x)    (x)

◆ BSLS_PLATFORMUTIL_NTOHS

#define BSLS_PLATFORMUTIL_NTOHS (   x)    (x)

Typedef Documentation

◆ bsls_PlatformUtil