libDwm-0.9.45
Dwm::StreamIO Class Reference

This class contains a collection of static functions for reading and writing simple types, in network byte order (MSB first). More...

#include <DwmStreamIO.hh>

Static Public Member Functions

static std::istream & Read (std::istream &is, char &c)
 Reads c from is. Returns is.
 
static std::ostream & Write (std::ostream &os, char c)
 Writes c to os. Returns os.
 
static std::istream & Read (std::istream &is, uint8_t &c)
 Reads c from is. Returns is.
 
static std::ostream & Write (std::ostream &os, uint8_t c)
 Writes c to os. Returns os.
 
static std::istream & Read (std::istream &is, bool &b)
 Reads b from is. Returns is.
 
static std::ostream & Write (std::ostream &os, bool b)
 Writes a bool b to an ostream os. Returns os.
 
static std::istream & Read (std::istream &is, int16_t &val)
 Reads val from is, in network byte order (MSB first).
 
static std::ostream & Write (std::ostream &os, int16_t val)
 Writes val to os, in network byte order (MSB first).
 
static std::istream & Read (std::istream &is, uint16_t &val)
 Reads val from is, in network byte order (MSB first).
 
static std::ostream & Write (std::ostream &os, uint16_t val)
 Writes val to os, in network byte order (MSB first).
 
static std::istream & Read (std::istream &is, int32_t &val)
 Reads val from is, in network byte order (MSB first).
 
static std::ostream & Write (std::ostream &os, int32_t val)
 Writes val to os, in network byte order (MSB first).
 
static std::istream & Read (std::istream &is, uint32_t &val)
 Reads val from is, in network byte order (MSB first).
 
static std::ostream & Write (std::ostream &os, uint32_t val)
 Writes val to os, in network byte order (MSB first).
 
static std::istream & Read (std::istream &is, int64_t &val)
 Reads val from is, in network byte order (MSB first).
 
static std::ostream & Write (std::ostream &os, const int64_t &val)
 Writes val to os, in network byte order (MSB first).
 
static std::istream & Read (std::istream &is, uint64_t &val)
 Reads val from is, in network byte order (MSB first).
 
static std::ostream & Write (std::ostream &os, const uint64_t &val)
 Writes val to os, in network byte order (MSB first).
 
static std::istream & Read (std::istream &is, float &val)
 Reads val from is, in IEEE format (see RFC 1832 and/or ANSI/IEEE Standard 754-1985).
 
static std::ostream & Write (std::ostream &os, float val)
 Writes val to os, in IEEE format (see RFC 1832 and/or ANSI/IEEE Standard 754-1985).
 
static std::istream & Read (std::istream &is, double &val)
 Reads val from is, in IEEE format (see RFC 1832 and/or ANSI/IEEE Standard 754-1985).
 
static std::ostream & Write (std::ostream &os, const double &val)
 Writes val to os, in IEEE format (see RFC 1832 and/or ANSI/IEEE Standard 754-1985).
 
static std::istream & Read (std::istream &is, std::string &s)
 Reads string s from is.
 
static std::ostream & Write (std::ostream &os, const std::string &s)
 Writes s to os.
 
static std::istream & Read (std::istream &is, StreamReadable &val)
 Wrapper function to read a StreamReadable object from an istream.
 
static std::istream & Read (std::istream &is, HasStreamRead auto &t)
 Reads an object t that meets the HasStreamRead requirement from an istream.
 
static std::ostream & Write (std::ostream &os, const StreamWritable &val)
 Wrapper function to write a StreamWritable object to an ostream.
 
static std::ostream & Write (std::ostream &os, const HasStreamWrite auto &t)
 Writes an object that meets the HasStreamWrite requirement to an ostream.
 
template<typename _firstT , typename _secondT >
static std::istream & Read (std::istream &is, std::pair< _firstT, _secondT > &p)
 Reads a pair<_firstT,_secondT> from an istream. Returns the istream.
 
template<typename _firstT , typename _secondT >
static std::ostream & Write (std::ostream &os, const std::pair< _firstT, _secondT > &p)
 Writes a pair<_firstT,_secondT> to an ostream. Returns the ostream.
 
template<typename _keyT , typename _valueT , typename _Compare , typename _Alloc >
static std::istream & Read (std::istream &is, std::map< _keyT, _valueT, _Compare, _Alloc > &m)
 Reads a map<_keyT,_valueT> from an istream. Returns the istream.
 
template<typename _keyT , typename _valueT , typename _Compare , typename _Alloc >
static std::ostream & Write (std::ostream &os, const std::map< _keyT, _valueT, _Compare, _Alloc > &m)
 Writes a map<_keyT,_valueT> to an ostream. Returns the ostream.
 
template<typename _keyT , typename _valueT , typename _Compare , typename _Alloc >
static std::istream & Read (std::istream &is, std::multimap< _keyT, _valueT, _Compare, _Alloc > &m)
 Reads a multimap<_keyT,_valueT> from an istream.
 
template<typename _keyT , typename _valueT , typename _Compare , typename _Alloc >
static std::ostream & Write (std::ostream &os, const std::multimap< _keyT, _valueT, _Compare, _Alloc > &m)
 Writes a multimap<_keyT,_valueT> to an ostream. Returns the ostream.
 
template<typename _valueT , size_t N>
static std::istream & Read (std::istream &is, std::array< _valueT, N > &a)
 Reads an array<_valueT,N> from an istream. Returns the istream.
 
template<typename _valueT , size_t N>
static std::ostream & Write (std::ostream &os, const std::array< _valueT, N > &a)
 Writes an array<_valueT,N> to an ostream. Returns the ostream.
 
template<typename _valueT , typename _Alloc >
static std::istream & Read (std::istream &is, std::vector< _valueT, _Alloc > &v)
 Reads a vector<_valueT> from an istream. Returns the istream.
 
template<typename _valueT , typename _Alloc >
static std::ostream & Write (std::ostream &os, const std::vector< _valueT, _Alloc > &v)
 Writes a vector<_valueT> to an ostream. Returns the ostream.
 
template<typename _valueT , typename _Alloc >
static std::istream & Read (std::istream &is, std::deque< _valueT, _Alloc > &d)
 Reads a deque<_valueT> from an istream. Returns the istream.
 
template<typename _valueT , typename _Alloc >
static std::ostream & Write (std::ostream &os, const std::deque< _valueT, _Alloc > &d)
 Writes a deque<_valueT> to an ostream. Returns the ostream.
 
template<typename _valueT , typename _Alloc >
static std::istream & Read (std::istream &is, std::list< _valueT, _Alloc > &l)
 Reads a list<_valueT> from an istream. Returns the istream.
 
template<typename _valueT , typename _Alloc >
static std::ostream & Write (std::ostream &os, const std::list< _valueT, _Alloc > &l)
 Writes a list<_valueT> to an ostream. Returns the ostream.
 
template<typename _valueT , typename _Compare , typename _Alloc >
static std::istream & Read (std::istream &is, std::set< _valueT, _Compare, _Alloc > &l)
 Reads a set<_valueT> from an istream. Returns the istream.
 
template<typename _valueT , typename _Compare , typename _Alloc >
static std::ostream & Write (std::ostream &os, const std::set< _valueT, _Compare, _Alloc > &l)
 Writes a set<_valueT> to an ostream. Returns the ostream.
 
template<typename _valueT , typename _Compare , typename _Alloc >
static std::istream & Read (std::istream &is, std::multiset< _valueT, _Compare, _Alloc > &l)
 Reads a multiset<_valueT> from an istream. Returns the istream.
 
template<typename _valueT , typename _Compare , typename _Alloc >
static std::ostream & Write (std::ostream &os, const std::multiset< _valueT, _Compare, _Alloc > &l)
 Writes a multiset<_valueT> to an ostream. Returns the ostream.
 
template<typename... Args>
static std::istream & Read (std::istream &is, std::tuple< Args... > &t)
 Reads a tuple from an istream. Returns the istream.
 
template<typename... Args>
static std::ostream & Write (std::ostream &os, const std::tuple< Args... > &t)
 Writes a tuple to an ostream. Returns the ostream.
 
template<typename _keyT , typename _valueT , typename _Hash , typename _Pred , typename _Alloc >
static std::istream & Read (std::istream &is, std::unordered_map< _keyT, _valueT, _Hash, _Pred, _Alloc > &m)
 Reads an unordered_map<_keyT,_valueT> from an istream.
 
template<typename _keyT , typename _valueT , typename _Hash , typename _Pred , typename _Alloc >
static std::ostream & Write (std::ostream &os, const std::unordered_map< _keyT, _valueT, _Hash, _Pred, _Alloc > &m)
 Writes a unordered_map<_keyT,_valueT> to an ostream.
 
template<typename _keyT , typename _valueT , typename _Hash , typename _Pred , typename _Alloc >
static std::istream & Read (std::istream &is, std::unordered_multimap< _keyT, _valueT, _Hash, _Pred, _Alloc > &m)
 Reads an unordered_multimap<_keyT,_valueT> from an istream.
 
template<typename _keyT , typename _valueT , typename _Hash , typename _Pred , typename _Alloc >
static std::ostream & Write (std::ostream &os, const std::unordered_multimap< _keyT, _valueT, _Hash, _Pred, _Alloc > &m)
 Writes a unordered_multimap<_keyT,_valueT> to an ostream.
 
template<typename _valueT , typename _Hash , typename _Pred , typename _Alloc >
static std::istream & Read (std::istream &is, std::unordered_set< _valueT, _Hash, _Pred, _Alloc > &m)
 Reads an unordered_set<_valueT> from an istream.
 
template<typename _valueT , typename _Hash , typename _Pred , typename _Alloc >
static std::ostream & Write (std::ostream &os, const std::unordered_set< _valueT, _Hash, _Pred, _Alloc > &m)
 Writes a unordered_set<_valueT> to an ostream.
 
template<typename _valueT , typename _Hash , typename _Pred , typename _Alloc >
static std::istream & Read (std::istream &is, std::unordered_multiset< _valueT, _Hash, _Pred, _Alloc > &m)
 Reads an unordered_multiset<_valueT> from an istream.
 
template<typename _valueT , typename _Hash , typename _Pred , typename _Alloc >
static std::ostream & Write (std::ostream &os, const std::unordered_multiset< _valueT, _Hash, _Pred, _Alloc > &m)
 Writes a unordered_multiset<_valueT> to an ostream.
 
template<typename... Ts>
static std::istream & Read (std::istream &is, std::variant< Ts... > &v)
 Reads a variant from an istream. Returns the istream.
 
template<typename... Ts>
static std::ostream & Write (std::ostream &os, const std::variant< Ts... > &v)
 Writes a variant to an ostream. Returns the ostream.
 
static std::istream & Read (std::istream &is, std::monostate &sm)
 Just a dummy helper function for std::variant instances that hold a std::monostate.
 
static std::ostream & Write (std::ostream &os, const std::monostate &sm)
 Just a dummy helper function for std::variant instances that hold a std::monostate.
 
template<typename... Args>
static std::istream & ReadV (std::istream &is, Args &...args)
 Reads multiple objects from an istream.
 
template<typename... Args>
static std::ostream & WriteV (std::ostream &os, const Args &...args)
 Writes multiple objects to an ostream.
 

Detailed Description

This class contains a collection of static functions for reading and writing simple types, in network byte order (MSB first).

It also contains functions to read and write strings. It also contains function templates to read and write arrays, deques, lists, vectors, maps, multimaps, sets, multisets, unordered_maps, unordered_multimaps, unordered_sets, unordered_multisets, tuples and variants. We use our member functions to handle reading and writing simple types in the containers, and function templates to handle reading and writing other class types. For a user-defined class, the class must implement the StreamReadable and StreamWritable interfaces, since our function templates simply call out to them. Since templates are static polymorphism, you don't need to inherit from StreamReadable and StreamWritable, but you must implement the interfaces.

Member Function Documentation

◆ Read() [1/15]

static std::istream & Dwm::StreamIO::Read ( std::istream & is,
double & val )
static

Reads val from is, in IEEE format (see RFC 1832 and/or ANSI/IEEE Standard 754-1985).

Returns is.

◆ Read() [2/15]

static std::istream & Dwm::StreamIO::Read ( std::istream & is,
float & val )
static

Reads val from is, in IEEE format (see RFC 1832 and/or ANSI/IEEE Standard 754-1985).

Returns is.

◆ Read() [3/15]

static std::istream & Dwm::StreamIO::Read ( std::istream & is,
int16_t & val )
static

Reads val from is, in network byte order (MSB first).

Returns is.

◆ Read() [4/15]

static std::istream & Dwm::StreamIO::Read ( std::istream & is,
int32_t & val )
static

Reads val from is, in network byte order (MSB first).

Returns is.

◆ Read() [5/15]

static std::istream & Dwm::StreamIO::Read ( std::istream & is,
int64_t & val )
static

Reads val from is, in network byte order (MSB first).

Returns is.

◆ Read() [6/15]

static std::istream & Dwm::StreamIO::Read ( std::istream & is,
std::monostate & sm )
inlinestatic

Just a dummy helper function for std::variant instances that hold a std::monostate.

This should only be called from our Read() for std::variant (via std::visit()), and does nothing. Returns the given istream.

◆ Read() [7/15]

template<typename _keyT , typename _valueT , typename _Compare , typename _Alloc >
static std::istream & Dwm::StreamIO::Read ( std::istream & is,
std::multimap< _keyT, _valueT, _Compare, _Alloc > & m )
inlinestatic

Reads a multimap<_keyT,_valueT> from an istream.

Returns the istream.

◆ Read() [8/15]

static std::istream & Dwm::StreamIO::Read ( std::istream & is,
std::string & s )
static

Reads string s from is.

Since we write strings with a 64-bit length value preceding, and always write the terminating NULL, this function will always read at least 9 bytes on success.

◆ Read() [9/15]

template<typename _keyT , typename _valueT , typename _Hash , typename _Pred , typename _Alloc >
static std::istream & Dwm::StreamIO::Read ( std::istream & is,
std::unordered_map< _keyT, _valueT, _Hash, _Pred, _Alloc > & m )
inlinestatic

Reads an unordered_map<_keyT,_valueT> from an istream.

Returns the istream.

◆ Read() [10/15]

template<typename _keyT , typename _valueT , typename _Hash , typename _Pred , typename _Alloc >
static std::istream & Dwm::StreamIO::Read ( std::istream & is,
std::unordered_multimap< _keyT, _valueT, _Hash, _Pred, _Alloc > & m )
inlinestatic

Reads an unordered_multimap<_keyT,_valueT> from an istream.

Returns the istream.

◆ Read() [11/15]

template<typename _valueT , typename _Hash , typename _Pred , typename _Alloc >
static std::istream & Dwm::StreamIO::Read ( std::istream & is,
std::unordered_multiset< _valueT, _Hash, _Pred, _Alloc > & m )
inlinestatic

Reads an unordered_multiset<_valueT> from an istream.

Returns the istream.

◆ Read() [12/15]

template<typename _valueT , typename _Hash , typename _Pred , typename _Alloc >
static std::istream & Dwm::StreamIO::Read ( std::istream & is,
std::unordered_set< _valueT, _Hash, _Pred, _Alloc > & m )
inlinestatic

Reads an unordered_set<_valueT> from an istream.

Returns the istream.

◆ Read() [13/15]

static std::istream & Dwm::StreamIO::Read ( std::istream & is,
uint16_t & val )
static

Reads val from is, in network byte order (MSB first).

Returns is.

◆ Read() [14/15]

static std::istream & Dwm::StreamIO::Read ( std::istream & is,
uint32_t & val )
static

Reads val from is, in network byte order (MSB first).

Returns is.

◆ Read() [15/15]

static std::istream & Dwm::StreamIO::Read ( std::istream & is,
uint64_t & val )
static

Reads val from is, in network byte order (MSB first).

Returns is.

◆ ReadV()

template<typename... Args>
static std::istream & Dwm::StreamIO::ReadV ( std::istream & is,
Args &... args )
inlinestatic

Reads multiple objects from an istream.

Returns the istream. This is just a convenience function.

Here is the call graph for this function:

◆ Write() [1/14]

static std::ostream & Dwm::StreamIO::Write ( std::ostream & os,
const double & val )
static

Writes val to os, in IEEE format (see RFC 1832 and/or ANSI/IEEE Standard 754-1985).

Returns os.

◆ Write() [2/14]

static std::ostream & Dwm::StreamIO::Write ( std::ostream & os,
const int64_t & val )
static

Writes val to os, in network byte order (MSB first).

Returns os.

◆ Write() [3/14]

static std::ostream & Dwm::StreamIO::Write ( std::ostream & os,
const std::monostate & sm )
inlinestatic

Just a dummy helper function for std::variant instances that hold a std::monostate.

This should only be called from our Write() for std::variant (via std::visit()), and does nothing. Returns the given ostream.

◆ Write() [4/14]

static std::ostream & Dwm::StreamIO::Write ( std::ostream & os,
const std::string & s )
static

Writes s to os.

Note that the length of s is written first, as an unsigned 64-bit number in network byte order (MSB first). Hence at least 9 bytes will always be written; 4 for the length and 1 for the terminating NULL character of an empty string.

◆ Write() [5/14]

template<typename _keyT , typename _valueT , typename _Hash , typename _Pred , typename _Alloc >
static std::ostream & Dwm::StreamIO::Write ( std::ostream & os,
const std::unordered_map< _keyT, _valueT, _Hash, _Pred, _Alloc > & m )
inlinestatic

Writes a unordered_map<_keyT,_valueT> to an ostream.

Returns the ostream.

◆ Write() [6/14]

template<typename _keyT , typename _valueT , typename _Hash , typename _Pred , typename _Alloc >
static std::ostream & Dwm::StreamIO::Write ( std::ostream & os,
const std::unordered_multimap< _keyT, _valueT, _Hash, _Pred, _Alloc > & m )
inlinestatic

Writes a unordered_multimap<_keyT,_valueT> to an ostream.

Returns the ostream.

◆ Write() [7/14]

template<typename _valueT , typename _Hash , typename _Pred , typename _Alloc >
static std::ostream & Dwm::StreamIO::Write ( std::ostream & os,
const std::unordered_multiset< _valueT, _Hash, _Pred, _Alloc > & m )
inlinestatic

Writes a unordered_multiset<_valueT> to an ostream.

Returns the ostream.

◆ Write() [8/14]

template<typename _valueT , typename _Hash , typename _Pred , typename _Alloc >
static std::ostream & Dwm::StreamIO::Write ( std::ostream & os,
const std::unordered_set< _valueT, _Hash, _Pred, _Alloc > & m )
inlinestatic

Writes a unordered_set<_valueT> to an ostream.

Returns the ostream.

◆ Write() [9/14]

static std::ostream & Dwm::StreamIO::Write ( std::ostream & os,
const uint64_t & val )
static

Writes val to os, in network byte order (MSB first).

Returns os.

◆ Write() [10/14]

static std::ostream & Dwm::StreamIO::Write ( std::ostream & os,
float val )
static

Writes val to os, in IEEE format (see RFC 1832 and/or ANSI/IEEE Standard 754-1985).

Returns os.

◆ Write() [11/14]

static std::ostream & Dwm::StreamIO::Write ( std::ostream & os,
int16_t val )
static

Writes val to os, in network byte order (MSB first).

Returns os.

◆ Write() [12/14]

static std::ostream & Dwm::StreamIO::Write ( std::ostream & os,
int32_t val )
static

Writes val to os, in network byte order (MSB first).

Returns os.

◆ Write() [13/14]

static std::ostream & Dwm::StreamIO::Write ( std::ostream & os,
uint16_t val )
static

Writes val to os, in network byte order (MSB first).

Returns os.

◆ Write() [14/14]

static std::ostream & Dwm::StreamIO::Write ( std::ostream & os,
uint32_t val )
static

Writes val to os, in network byte order (MSB first).

Returns os.

◆ WriteV()

template<typename... Args>
static std::ostream & Dwm::StreamIO::WriteV ( std::ostream & os,
const Args &... args )
inlinestatic

Writes multiple objects to an ostream.

Returns the ostream. This is just a convenience function.

Here is the call graph for this function:

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