class output_stream


template <
    typename OutputResource
>
class output_stream

Description

An output stream is an object that writes data to an output resource.

There are two kinds of output streams in CCL: data output streams, which write binary data to its output resource, and text output streams, which write text to its output resource.

The output_stream class template serves as the foundation for both data output streams and text output streams.

Public Aliases

using referenced_resource_type = OutputResource

The type of the referenced output resource.

Public Member Functions

explicit
output_stream (
    referenced_resource_type& resource,
    std::endian endianness = std::endian::native
)
noexcept

Constructs an output stream with the given output resource and endianness.

Parameters:
  • resource:

    The output resource this stream will write to.

  • endianness:

    The endianness to write the data in.

output_stream (
    const output_stream& other
)

Copy-constructs an output_stream from an existing one.

Parameters:
  • other:

    The output_stream to copy from.

output_stream&
operator = (
    const output_stream& other
)

Copy-assigns an output_stream into this one.

Parameters:
  • other:

    The output_stream to copy from.

output_stream (
    output_stream&& other
)
noexcept

Move-constructs an output_stream from an existing one.

Parameters:
  • other:

    The output_stream to move from.

output_stream&
operator = (
    output_stream&& other
)
noexcept

Move-assigns an output_stream into this one.

Parameters:
  • other:

    The output_stream to move from.

referenced_resource_type&
grab_resource ()
noexcept

Returns a non-constant reference to the referenced output resource.

const referenced_resource_type&
grab_resource ()
const noexcept

Returns a constant reference to the referenced output resource.

std::endian
get_endianness ()
const noexcept

Returns the endianness associated with this output stream.

void
set_endianness (
    std::endian new_endianness
)
noexcept

Sets the endianness associated with this output stream.

Parameters:
  • new_endianness:

    The new endianness to use with this output stream.

bool
is_at_end ()
const noexcept

Tells whether this stream's output resource is at its end.

std::size_t
write (
    const std::byte* data,
    std::size_t byte_count
)

Writes byte_count bytes from the data array to this stream's output resource.

Parameters:
  • data:

    The array of bytes that will be written to this stream's output resource.

  • byte_count:

    The number of bytes to write to this stream's output resource.

std::size_t
reverse_write (
    std::byte* data,
    std::size_t byte_count
)

Reverses the order of the bytes in the data array and then writes them to this stream's output resource.

Parameters:
  • data:

    The bytes that will be reversed and written to this stream's output resource.

  • byte_count:

    The number of bytes to reverse and write to this stream's output resource.

void
flush ()

Flushes the stream's output resource, ensuring that any data that has previously been requested to be written out actually gets written out.

referenced_resource_type*
operator -> ()
const noexcept

Returns a pointer to the referenced output resource, enabling use of the arrow operator.



Copyright © 2022-2025 Daniel T. McGinnis

CCL was first published in 2022, and is still actively maintained.

This website was first published in 2022, and is still actively maintained.

This specific web page was first published in 2023.