Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
Binary Little Endianness Generators
Description

The little native endianness generators described in this section are used to emit binary byte streams laid out conforming to the little endianness byte order.

Header
// forwards to <boost/spirit/home/karma/binary.hpp>
#include <boost/spirit/include/karma_binary.hpp>

Also, see Include Structure.

Namespace

Name

boost::spirit::little_word // alias: boost::spirit::karma::little_word

boost::spirit::little_dword // alias: boost::spirit::karma::little_dword

boost::spirit::little_qword // alias: boost::spirit::karma::little_qword

boost::spirit::little_bin_float // alias: boost::spirit::karma::little_bin_float

boost::spirit::little_bin_double // alias: boost::spirit::karma::little_bin_double

[Note] Note

The generators little_qword and little_qword(qw) are only available on platforms where the preprocessor constant BOOST_HAS_LONG_LONG is defined (i.e. on platforms having native support for unsigned long long (64 bit) integer types).

Model of

PrimitiveGenerator

Notation

w

A 16 bit binary value or a Lazy Argument that evaluates to a 16 bit binary value. This value is always interpreted using native endianness.

dw

A 32 bit binary value or a Lazy Argument that evaluates to a 32 bit binary value. This value is always interpreted using native endianness.

qw

A 64 bit binary value or a Lazy Argument that evaluates to a 64 bit binary value. This value is always interpreted using native endianness.

f

A float binary value or a Lazy Argument that evaluates to a float binary value. This value is always interpreted using native endianness.

d

A double binary value or a Lazy Argument that evaluates to a double binary value. This value is always interpreted using native endianness.

Expression Semantics

Semantics of an expression is defined only where it differs from, or is not defined in PrimitiveGenerator.

Expression

Description

little_word

Output the binary representation of the least significant 16 bits of the mandatory attribute in little endian representation. This generator never fails (unless the underlying output stream reports an error).

little_dword

Output the binary representation of the least significant 32 bits of the mandatory attribute in little endian representation. This generator never fails (unless the underlying output stream reports an error).

little_qword

Output the binary representation of the least significant 64 bits of the mandatory attribute in little endian representation. This generator never fails (unless the underlying output stream reports an error).

little_bin_float

Output the binary representation of the mandatory float attribute in little endian representation. This generator never fails (unless the underlying output stream reports an error).

little_bin_double

Output the binary representation of the mandatory double attribute in little endian representation. This generator never fails (unless the underlying output stream reports an error).

little_word(w)

Output the binary representation of the least significant 16 bits of the immediate parameter in little endian representation. This generator never fails (unless the underlying output stream reports an error).

little_dword(dw)

Output the binary representation of the least significant 32 bits of the immediate parameter in little endian representation. This generator never fails (unless the underlying output stream reports an error).

little_qword(qw)

Output the binary representation of the least significant 64 bits of the immediate parameter in little endian representation. This generator never fails (unless the underlying output stream reports an error).

little_bin_float(f)

Output the binary representation of the immediate float parameter in little endian representation. This generator never fails (unless the underlying output stream reports an error).

little_bin_double(d)

Output the binary representation of the immediate double parameter in little endian representation. This generator never fails (unless the underlying output stream reports an error).

Attributes

Expression

Attribute

little_word

boost::uint_least16_t, attribute is mandatory (otherwise compilation will fail)

little_dword

boost::uint_least32_t, attribute is mandatory (otherwise compilation will fail)

little_qword

boost::uint_least64_t, attribute is mandatory (otherwise compilation will fail)

little_bin_float

float, attribute is mandatory (otherwise compilation will fail)

little_bin_double

double, attribute is mandatory (otherwise compilation will fail)

little_word(w)

unused

little_dword(dw)

unused

little_qword(qw)

unused

little_bin_float(f)

unused

little_bin_double(d)

unused

Complexity

O(N), where N is the number of bytes emitted by the binary generator

Example
[Note] Note

The test harness for the example(s) below is presented in the Basics Examples section.

Some includes:

#include <boost/spirit/include/karma.hpp>
#include <boost/spirit/include/support_utree.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/fusion/include/std_pair.hpp>
#include <iostream>
#include <string>

Some using declarations:

using boost::spirit::karma::little_word;
using boost::spirit::karma::little_dword;
using boost::spirit::karma::little_qword;

Basic usage of the little binary generators:

test_binary_generator("\x01\x02", 2, little_word(0x0201));
test_binary_generator("\x01\x02\x03\x04", 4, little_dword(0x04030201));
test_binary_generator("\x01\x02\x03\x04\x05\x06\x07\x08", 8, little_qword(0x0807060504030201LL));

test_binary_generator_attr("\x01\x02", 2, little_word, 0x0201);
test_binary_generator_attr("\x01\x02\x03\x04", 4, little_dword, 0x04030201);
test_binary_generator_attr("\x01\x02\x03\x04\x05\x06\x07\x08", 8, little_qword, 0x0807060504030201LL);


PrevUpHomeNext