xentara-utils v1.2.1
Xentara utilities library
Loading...
Searching...
No Matches
xentara::utils::io::MemoryOutputStream< Element, StorageElement > Class Template Referencefinal

A stream that writes data to a memory region. More...

#include <io/MemoryOutputStream.hpp>

+ Inheritance diagram for xentara::utils::io::MemoryOutputStream< Element, StorageElement >:

Public Types

using value_type = StorageElement
 The element type.
 
using reference = value_type &
 A reference to an element.
 
using const_reference = const value_type &
 A const reference to an element.
 
using pointer = value_type *
 A pointer to an element.
 
using const_pointer = const value_type *
 A const pointer to an element.
 
using const_iterator = core::ContiguousIterator< const_pointer, MemoryOutputStream >
 A const iterator.
 
using iterator = const_iterator
 An iterator.
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 A const iterator for iterating in reverse order.
 
using reverse_iterator = const_reverse_iterator
 An iterator for iterating in reverse order.
 
- Public Types inherited from xentara::utils::io::MemoryOutputStreamBase< Element >
using size_type = std::size_t
 The type used for sizes.
 
using difference_type = std::ptrdiff_t
 The type used for distances.
 
- Public Types inherited from xentara::utils::io::OutputStream< Element >
using element_type = Element
 The element type.
 

Public Member Functions

Constructors
template<std::contiguous_iterator Iterator>
requires std::is_same_v<std::iter_value_t<Iterator>, StorageElement>
 MemoryOutputStream (Iterator begin, Iterator end)
 Constructs a stream that writes to a memory region defined by a pair of iterators.
 
template<std::contiguous_iterator Iterator>
requires std::is_same_v<std::iter_value_t<Iterator>, StorageElement>
 MemoryOutputStream (Iterator begin, std::iter_difference_t< Iterator > size)
 Constructs a stream that writes to a memory region defined by an iterator and a size.
 
template<std::ranges::contiguous_range Region>
requires std::is_same_v<std::ranges::range_value_t<Region>, StorageElement>
 MemoryOutputStream (Region &region)
 Constructs a stream that writes to a memory region.
 
Access to the written data
auto at (size_type index) const -> const_reference
 Accesses the element at a certain index.
 
auto operator[] (size_type index) const noexcept -> const_reference
 Subscript operator.
 
auto front () const noexcept -> const_reference
 Returns the first element.
 
auto back () const noexcept -> const_reference
 Returns the last element.
 
auto data () const noexcept -> const value_type *
 Raw access to the data.
 
template<typename CharTraits = std::char_traits<StorageElement>>
requires tools::CharType<StorageElement>
 operator std::basic_string_view< StorageElement, CharTraits > () const
 Returns the data written so far as a string view.
 
Iterators
auto begin () const noexcept -> const_iterator
 Creates a begin iterator.
 
auto cbegin () const noexcept -> const_iterator
 Creates a begin iterator.
 
auto end () const noexcept -> const_iterator
 Creates an end iterator.
 
auto cend () const noexcept -> const_iterator
 Creates an end iterator.
 
auto rbegin () const noexcept -> const_reverse_iterator
 Creates a reverse begin iterator.
 
auto crbegin () const noexcept -> const_reverse_iterator
 Creates a reverse begin iterator.
 
auto rend () const noexcept -> const_reverse_iterator
 Creates a reverse end iterator.
 
auto crend () const noexcept -> const_reverse_iterator
 Creates a reverse end iterator.
 
- Public Member Functions inherited from xentara::utils::io::MemoryOutputStreamBase< Element >
auto empty () const noexcept -> bool
 Determines whether the data is empty.
 
auto size () const noexcept -> size_type
 Gets the size of the data.
 
auto capacity () const noexcept -> size_type
 Gets the capacity of the data.
 
- Public Member Functions inherited from xentara::utils::io::OutputStream< Element >
virtual ~OutputStream () noexcept(false)=0
 Virtual, throwing destructor.
 
auto write (Element element) -> void
 Write a single element to the stream.
 
template<std::ranges::contiguous_range Data>
requires std::same_as<std::remove_cv_t<std::ranges::range_value_t<Data>>, Element>
auto write (const Data &data) -> void
 Write a block of data.
 
template<std::size_t kDataSize>
auto write (const Element(&data)[kDataSize]) -> void
 Write a block of data contained in an array.
 
template<std::contiguous_iterator Iterator, std::sized_sentinel_for< Iterator > Sentinel>
requires std::same_as<std::remove_cv_t<std::iter_value_t<Iterator>>, Element>
auto write (Iterator first, Sentinel last) -> void
 Write a block of data contained in an iterator range.
 
auto write (const Element *data, std::size_t size) -> void
 Write a block of data contained in a region of memory.
 
auto write (const Element *nullTerminatedString) -> void
 Write a NULL-teminated string.
 
auto flush () -> void
 Flushes the buffer.
 
- Public Member Functions inherited from xentara::utils::io::StreamBase
virtual ~StreamBase () noexcept(false)=0
 Virtual, throwing destructor.
 
auto streamDescription () const -> std::string
 Get a description of the device.
 

Additional Inherited Members

- Protected Member Functions inherited from xentara::utils::io::OutputStream< Element >
 OutputStream () noexcept=default
 Default constructor.
 
 OutputStream (Element *bufferBegin, Element *bufferEnd) noexcept
 Constructor that sets an initially empty buffer.
 
 OutputStream (Element *bufferBegin, Element *bufferEnd, Element *dataEnd) noexcept
 Constructor that sets a buffer that possibly already contains some data.
 
 OutputStream (OutputStream &&other) noexcept
 Move constructor.
 
auto operator= (OutputStream &&rhs) noexcept -> OutputStream &
 Move assignemnt operator.
 
auto setWriteBuffer (Element *bufferBegin, Element *bufferEnd) noexcept -> void
 Sets a new empty buffer.
 
auto setWriteBuffer (Element *bufferBegin, Element *bufferEnd, Element *dataEnd) noexcept -> void
 Sets the buffer.
 
auto setWriteDataEnd (Element *dataEnd) noexcept -> void
 Sets the end of the data within the buffer.
 
auto writeBufferBegin () const -> Element *
 Writes back the buffer start position.
 
auto writeBufferEnd () const -> Element *
 Writes back the buffer end position.
 
auto writeBufferSize () const -> std::size_t
 Gets the buffer size.
 
auto writeDataBegin () const -> Element *
 Returns the beginning of data in the buffer.
 
auto writeDataEnd () const -> Element *
 Returns the end of the data in the buffer.
 
auto writeDataSize () const -> std::size_t
 Returns the size of the unwritten data in the buffer.
 
auto freeBufferBegin () const -> Element *
 Returns the beginning of the free region of the buffer.
 
auto freeBufferSize () const -> std::size_t
 Returns the size of the unwritten data in the buffer.
 
virtual auto doFlushWriteBuffer () -> void
 Called by the framework to write the buffered data to the underlying device once it is full.
 
virtual auto doWrite (const Element *data, std::size_t size) -> std::size_t=0
 Called by the framework to write data from a memory region to the underlying device.
 
- Protected Member Functions inherited from xentara::utils::io::StreamBase
virtual auto doGetStreamDescription () const -> std::string=0
 Called by the framework to get a description of the stream.
 

Detailed Description

template<StreamElement Element, typename StorageElement = Element>
class xentara::utils::io::MemoryOutputStream< Element, StorageElement >

A stream that writes data to a memory region.

Template Parameters
ElementThe type of elements that will be written to the stream.
StorageElementThe type for the elements actually contained in the memory region. Must be the same as Element, or another trivial type that is the same size as Element. Common types for byte oriented streams include char, unsigned char.
See also
MemoryOutputStream<Element, void>

Member Typedef Documentation

◆ const_iterator

template<StreamElement Element, typename StorageElement = Element>
using xentara::utils::io::MemoryOutputStream< Element, StorageElement >::const_iterator = core::ContiguousIterator<const_pointer, MemoryOutputStream>

A const iterator.

◆ const_pointer

template<StreamElement Element, typename StorageElement = Element>
using xentara::utils::io::MemoryOutputStream< Element, StorageElement >::const_pointer = const value_type *

A const pointer to an element.

◆ const_reference

template<StreamElement Element, typename StorageElement = Element>
using xentara::utils::io::MemoryOutputStream< Element, StorageElement >::const_reference = const value_type &

A const reference to an element.

◆ const_reverse_iterator

template<StreamElement Element, typename StorageElement = Element>
using xentara::utils::io::MemoryOutputStream< Element, StorageElement >::const_reverse_iterator = std::reverse_iterator<const_iterator>

A const iterator for iterating in reverse order.

◆ iterator

template<StreamElement Element, typename StorageElement = Element>
using xentara::utils::io::MemoryOutputStream< Element, StorageElement >::iterator = const_iterator

An iterator.

◆ pointer

template<StreamElement Element, typename StorageElement = Element>
using xentara::utils::io::MemoryOutputStream< Element, StorageElement >::pointer = value_type *

A pointer to an element.

◆ reference

template<StreamElement Element, typename StorageElement = Element>
using xentara::utils::io::MemoryOutputStream< Element, StorageElement >::reference = value_type &

A reference to an element.

◆ reverse_iterator

template<StreamElement Element, typename StorageElement = Element>
using xentara::utils::io::MemoryOutputStream< Element, StorageElement >::reverse_iterator = const_reverse_iterator

An iterator for iterating in reverse order.

◆ value_type

template<StreamElement Element, typename StorageElement = Element>
using xentara::utils::io::MemoryOutputStream< Element, StorageElement >::value_type = StorageElement

The element type.

Constructor & Destructor Documentation

◆ MemoryOutputStream() [1/3]

template<StreamElement Element, typename StorageElement = Element>
template<std::contiguous_iterator Iterator>
requires std::is_same_v<std::iter_value_t<Iterator>, StorageElement>
xentara::utils::io::MemoryOutputStream< Element, StorageElement >::MemoryOutputStream ( Iterator  begin,
Iterator  end 
)

Constructs a stream that writes to a memory region defined by a pair of iterators.

Parameters
beginAn iterator that points at the beginning of the memory region
endAn iterator that points at the end of the memory region

◆ MemoryOutputStream() [2/3]

template<StreamElement Element, typename StorageElement = Element>
template<std::contiguous_iterator Iterator>
requires std::is_same_v<std::iter_value_t<Iterator>, StorageElement>
xentara::utils::io::MemoryOutputStream< Element, StorageElement >::MemoryOutputStream ( Iterator  begin,
std::iter_difference_t< Iterator >  size 
)

Constructs a stream that writes to a memory region defined by an iterator and a size.

Parameters
beginAn iterator that points at the beginning of the memory region
sizeThe size of the memory region

◆ MemoryOutputStream() [3/3]

template<StreamElement Element, typename StorageElement = Element>
template<std::ranges::contiguous_range Region>
requires std::is_same_v<std::ranges::range_value_t<Region>, StorageElement>
xentara::utils::io::MemoryOutputStream< Element, StorageElement >::MemoryOutputStream ( Region &  region)

Constructs a stream that writes to a memory region.

Parameters
regionThe memory region

Member Function Documentation

◆ at()

template<StreamElement Element, typename StorageElement = Element>
auto xentara::utils::io::MemoryOutputStream< Element, StorageElement >::at ( size_type  index) const -> const_reference

Accesses the element at a certain index.

Parameters
indexThe index
Returns
A reference to the element at the given index
Exceptions
std::out_of_rangeindex is out of range

◆ back()

template<StreamElement Element, typename StorageElement = Element>
auto xentara::utils::io::MemoryOutputStream< Element, StorageElement >::back ( ) const -> const_reference
noexcept

Returns the last element.

Note
Must not be called on an empty vector
Returns
A reference to last element

◆ begin()

template<StreamElement Element, typename StorageElement = Element>
auto xentara::utils::io::MemoryOutputStream< Element, StorageElement >::begin ( ) const -> const_iterator
noexcept

Creates a begin iterator.

Returns
An iterator pointing at the first element, or end(), if the data is empty

◆ cbegin()

template<StreamElement Element, typename StorageElement = Element>
auto xentara::utils::io::MemoryOutputStream< Element, StorageElement >::cbegin ( ) const -> const_iterator
noexcept

Creates a begin iterator.

Returns
An iterator pointing at the first element, or end(), if the data is empty

◆ cend()

template<StreamElement Element, typename StorageElement = Element>
auto xentara::utils::io::MemoryOutputStream< Element, StorageElement >::cend ( ) const -> const_iterator
noexcept

Creates an end iterator.

Returns
An iterator pointing at the position past the last element

◆ crbegin()

template<StreamElement Element, typename StorageElement = Element>
auto xentara::utils::io::MemoryOutputStream< Element, StorageElement >::crbegin ( ) const -> const_reverse_iterator
noexcept

Creates a reverse begin iterator.

Returns
A reverse iterator pointing at the last element, or rend(), if the data is empty

◆ crend()

template<StreamElement Element, typename StorageElement = Element>
auto xentara::utils::io::MemoryOutputStream< Element, StorageElement >::crend ( ) const -> const_reverse_iterator
noexcept

Creates a reverse end iterator.

Returns
A reverse iterator pointing at the position before the first element

◆ data()

template<StreamElement Element, typename StorageElement = Element>
auto xentara::utils::io::MemoryOutputStream< Element, StorageElement >::data ( ) const -> const value_type *
noexcept

Raw access to the data.

Returns
A pointer to the begining of the written data.

◆ end()

template<StreamElement Element, typename StorageElement = Element>
auto xentara::utils::io::MemoryOutputStream< Element, StorageElement >::end ( ) const -> const_iterator
noexcept

Creates an end iterator.

Returns
An iterator pointing at the position past the last element

◆ front()

template<StreamElement Element, typename StorageElement = Element>
auto xentara::utils::io::MemoryOutputStream< Element, StorageElement >::front ( ) const -> const_reference
noexcept

Returns the first element.

Note
Must not be called on an empty vector
Returns
A reference to first element

◆ operator std::basic_string_view< StorageElement, CharTraits >()

template<StreamElement Element, typename StorageElement = Element>
template<typename CharTraits = std::char_traits<StorageElement>>
requires tools::CharType<StorageElement>
xentara::utils::io::MemoryOutputStream< Element, StorageElement >::operator std::basic_string_view< StorageElement, CharTraits > ( ) const

Returns the data written so far as a string view.

Requirements
This operator is only available for the element types char and char8_t.
Returns
The data as a string view

◆ operator[]()

template<StreamElement Element, typename StorageElement = Element>
auto xentara::utils::io::MemoryOutputStream< Element, StorageElement >::operator[] ( size_type  index) const -> const_reference
noexcept

Subscript operator.

Returns a reference to the element at a certain index

Parameters
indexThe index
Returns
A reference to the value at the given offset

◆ rbegin()

template<StreamElement Element, typename StorageElement = Element>
auto xentara::utils::io::MemoryOutputStream< Element, StorageElement >::rbegin ( ) const -> const_reverse_iterator
noexcept

Creates a reverse begin iterator.

Returns
A reverse iterator pointing at the last element, or rend(), if the data is empty

◆ rend()

template<StreamElement Element, typename StorageElement = Element>
auto xentara::utils::io::MemoryOutputStream< Element, StorageElement >::rend ( ) const -> const_reverse_iterator
noexcept

Creates a reverse end iterator.

Returns
A reverse iterator pointing at the position before the first element