OpenTTD Source: EndianBufferWriter< Tcont, Titer > Class Template Reference

OpenTTD Source 15.3

Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
EndianBufferWriter< Tcont, Titer > Class Template Reference

Endian-aware buffer adapter that always writes values in little endian order. More...

`#include <endian_buffer.hpp>`

## Public Member Functions
| EndianBufferWriter (Titer buffer)
| EndianBufferWriter (typename Titer::container_type &container)
EndianBufferWriter & | operator<< (const std::string &data)
EndianBufferWriter & | operator<< (const EncodedString &data)
EndianBufferWriter & | operator<< (std::string_view data)
EndianBufferWriter & | operator<< (bool data)
template<typename... Targs>
EndianBufferWriter & | operator<< (const std::tuple< Targs... > &data)
template<typename... Targs>
EndianBufferWriter & | operator<< (const std::variant< Targs... > &variant)
EndianBufferWriter & | operator<< (const std::monostate &)
EndianBufferWriter & | operator<< (const ConvertibleThroughBase auto data)
template<class T > requires (!std::is_class_v<T>)
EndianBufferWriter & | operator<< (const T data)

## Static Public Member Functions
template<typename Tvalue , typename Tbuf = std::vector<uint8_t>>
static Tbuf | FromValue (const Tvalue &data)

## Private Member Functions
template<class Ttuple , size_t... Tindices>
void | WriteTuple (const Ttuple &values, std::index_sequence< Tindices... >)
| Helper function to write a tuple to the buffer.
template<typename T , std::size_t I = 0>
void | WriteVariant (const T &variant)
void | Write (std::string_view value)
| Write overload for string values.
template<class T >
void | Write (T value)
| Fundamental write function.

## Private Attributes
Titer | buffer
| Output iterator for the destination buffer.

## Detailed Description

template<typename Tcont = typename std::vector<uint8_t>, typename Titer = typename std::back_insert_iterator<Tcont>>
class EndianBufferWriter< Tcont, Titer >

Endian-aware buffer adapter that always writes values in little endian order.

Note
  This class uses operator overloading (<<, just like streams) for writing as this allows providing custom operator overloads for more complex types like e.g. structs without needing to modify this class.

Definition at line 24 of file endian_buffer.hpp.

## Constructor & Destructor Documentation

## ◆ EndianBufferWriter() [1/2]

template<typename Tcont = typename std::vector<uint8_t>, typename Titer = typename std::back_insert_iterator<Tcont>>

EndianBufferWriter< Tcont, Titer >::EndianBufferWriter | ( | Titer | buffer | ) |
| inline

Definition at line 29 of file endian_buffer.hpp.

## ◆ EndianBufferWriter() [2/2]

template<typename Tcont = typename std::vector<uint8_t>, typename Titer = typename std::back_insert_iterator<Tcont>>

EndianBufferWriter< Tcont, Titer >::EndianBufferWriter | ( | typename Titer::container_type & | container | ) |
| inline

Definition at line 30 of file endian_buffer.hpp.

## Member Function Documentation

## ◆ FromValue()

template<typename Tcont = typename std::vector<uint8_t>, typename Titer = typename std::back_insert_iterator<Tcont>>
template<typename Tvalue , typename Tbuf = std::vector<uint8_t>>

static Tbuf EndianBufferWriter< Tcont, Titer >::FromValue | ( | const Tvalue & | data | ) |
| inlinestatic

Definition at line 74 of file endian_buffer.hpp.

## ◆ operator<<() [1/9]

template<typename Tcont = typename std::vector<uint8_t>, typename Titer = typename std::back_insert_iterator<Tcont>>

EndianBufferWriter & EndianBufferWriter< Tcont, Titer >::operator<< | ( | bool | data | ) |
| inline

Definition at line 35 of file endian_buffer.hpp.

## ◆ operator<<() [2/9]

template<typename Tcont = typename std::vector<uint8_t>, typename Titer = typename std::back_insert_iterator<Tcont>>

EndianBufferWriter & EndianBufferWriter< Tcont, Titer >::operator<< | ( | const ConvertibleThroughBase auto | data | ) |
| inline

Definition at line 56 of file endian_buffer.hpp.

## ◆ operator<<() [3/9]

template<typename Tcont = typename std::vector<uint8_t>, typename Titer = typename std::back_insert_iterator<Tcont>>

EndianBufferWriter & EndianBufferWriter< Tcont, Titer >::operator<< | ( | const EncodedString & | data | ) |
| inline

Definition at line 33 of file endian_buffer.hpp.

## ◆ operator<<() [4/9]

template<typename Tcont = typename std::vector<uint8_t>, typename Titer = typename std::back_insert_iterator<Tcont>>

EndianBufferWriter & EndianBufferWriter< Tcont, Titer >::operator<< | ( | const std::monostate & |  | ) |
| inline

Definition at line 51 of file endian_buffer.hpp.

## ◆ operator<<() [5/9]

template<typename Tcont = typename std::vector<uint8_t>, typename Titer = typename std::back_insert_iterator<Tcont>>

EndianBufferWriter & EndianBufferWriter< Tcont, Titer >::operator<< | ( | const std::string & | data | ) |
| inline

Definition at line 32 of file endian_buffer.hpp.

## ◆ operator<<() [6/9]

template<typename Tcont = typename std::vector<uint8_t>, typename Titer = typename std::back_insert_iterator<Tcont>>
template<typename... Targs>

EndianBufferWriter & EndianBufferWriter< Tcont, Titer >::operator<< | ( | const std::tuple< Targs... > & | data | ) |
| inline

Definition at line 38 of file endian_buffer.hpp.

## ◆ operator<<() [7/9]

template<typename Tcont = typename std::vector<uint8_t>, typename Titer = typename std::back_insert_iterator<Tcont>>
template<typename... Targs>

EndianBufferWriter & EndianBufferWriter< Tcont, Titer >::operator<< | ( | const std::variant< Targs... > & | variant | ) |
| inline

Definition at line 45 of file endian_buffer.hpp.

## ◆ operator<<() [8/9]

template<typename Tcont = typename std::vector<uint8_t>, typename Titer = typename std::back_insert_iterator<Tcont>>
template<class T >
requires (!std::is_class_v<T>)

EndianBufferWriter & EndianBufferWriter< Tcont, Titer >::operator<< | ( | const T | data | ) |
| inline

Definition at line 63 of file endian_buffer.hpp.

## ◆ operator<<() [9/9]

template<typename Tcont = typename std::vector<uint8_t>, typename Titer = typename std::back_insert_iterator<Tcont>>

EndianBufferWriter & EndianBufferWriter< Tcont, Titer >::operator<< | ( | std::string_view | data | ) |
| inline

Definition at line 34 of file endian_buffer.hpp.

## ◆ Write() [1/2]

template<typename Tcont = typename std::vector<uint8_t>, typename Titer = typename std::back_insert_iterator<Tcont>>

void EndianBufferWriter< Tcont, Titer >::Write | ( | std::string_view | value | ) |
| inlineprivate

Write overload for string values.

Definition at line 106 of file endian_buffer.hpp.

## ◆ Write() [2/2]

template<typename Tcont = typename std::vector<uint8_t>, typename Titer = typename std::back_insert_iterator<Tcont>>
template<class T >

void EndianBufferWriter< Tcont, Titer >::Write | ( | T | value | ) |
| inlineprivate

Fundamental write function.

Definition at line 116 of file endian_buffer.hpp.

References GB().

## ◆ WriteTuple()

template<typename Tcont = typename std::vector<uint8_t>, typename Titer = typename std::back_insert_iterator<Tcont>>
template<class Ttuple , size_t... Tindices>

void EndianBufferWriter< Tcont, Titer >::WriteTuple | ( | const Ttuple & | values,
|  | std::index_sequence< Tindices... > |
| ) |  |
| inlineprivate

Helper function to write a tuple to the buffer.

Definition at line 85 of file endian_buffer.hpp.

## ◆ WriteVariant()

template<typename Tcont = typename std::vector<uint8_t>, typename Titer = typename std::back_insert_iterator<Tcont>>
template<typename T , std::size_t I = 0>

void EndianBufferWriter< Tcont, Titer >::WriteVariant | ( | const T & | variant | ) |
| inlineprivate

Definition at line 91 of file endian_buffer.hpp.

## Field Documentation

## ◆ buffer

template<typename Tcont = typename std::vector<uint8_t>, typename Titer = typename std::back_insert_iterator<Tcont>>

Titer EndianBufferWriter< Tcont, Titer >::buffer
| private

Output iterator for the destination buffer.

Definition at line 26 of file endian_buffer.hpp.

The documentation for this class was generated from the following file:

- src/misc/endian_buffer.hpp