42#ifndef _DWMIOUTILS_HH_
43#define _DWMIOUTILS_HH_
56#include <unordered_map>
57#include <unordered_set>
186 return(
sizeof(uint64_t) + s.size());
193 template <
typename _firstT,
typename _secondT>
203 template <
typename _keyT,
typename _valueT,
204 typename _Compare,
typename _Alloc>
208 return(ContainerStreamedLength<std::map<_keyT, _valueT, _Compare, _Alloc> >(m));
215 template <
typename _keyT,
typename _valueT,
216 typename _Compare,
typename _Alloc>
220 return(ContainerStreamedLength<std::multimap<_keyT,_valueT,_Compare,_Alloc> >(m));
227 template <
typename _valueT,
size_t N>
231 for (
size_t i = 0; i < N; ++i) {
241 template <
typename _valueT,
typename _Alloc>
244 return(ContainerStreamedLength<std::vector<_valueT, _Alloc> >(v));
251 template <
typename _valueT,
typename _Alloc>
254 return(ContainerStreamedLength<std::deque<_valueT, _Alloc> >(d));
261 template <
typename _valueT,
typename _Alloc>
264 return(ContainerStreamedLength<std::list<_valueT, _Alloc> >(l));
271 template <
typename _valueT,
typename _Compare,
typename _Alloc>
275 return(ContainerStreamedLength<std::set<_valueT, _Compare, _Alloc> >(l));
282 template <
typename _valueT,
typename _Compare,
typename _Alloc>
286 return(ContainerStreamedLength<std::multiset<_valueT, _Compare, _Alloc> >(l));
292 template <
typename T,
typename... Args>
293 static uint64_t VarStreamedLength(
const T & t, Args... args)
296 if (
sizeof...(Args) > 0)
297 rc += VarStreamedLength(args...);
305 template <
typename T,
typename... Args>
314 template <
typename T>
331 template <
typename... Ts>
334 uint64_t rc =
sizeof(uint64_t);
335 std::visit([&] (
const auto & arg)
343 template <
typename _keyT,
typename _valueT,
344 typename _Hash,
typename _Pred,
typename _Alloc>
346 StreamedLength(
const std::unordered_map<_keyT, _valueT, _Hash, _Pred, _Alloc> & m)
348 using myType = std::unordered_map<_keyT, _valueT, _Hash, _Pred, _Alloc>;
350 return(ContainerStreamedLength<myType>(m));
356 template <
typename _keyT,
typename _valueT,
357 typename _Hash,
typename _Pred,
typename _Alloc>
359 StreamedLength(
const std::unordered_multimap<_keyT, _valueT, _Hash, _Pred, _Alloc> & m)
361 using myType = std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc>;
362 return(ContainerStreamedLength<myType>(m));
368 template <
typename _valueT,
typename _Hash,
369 typename _Pred,
typename _Alloc>
371 StreamedLength(
const std::unordered_set<_valueT, _Hash, _Pred, _Alloc> & m)
373 using myType = std::unordered_set<_valueT, _Hash, _Pred, _Alloc>;
374 return(ContainerStreamedLength<myType>(m));
380 template <
typename _valueT,
typename _Hash,
381 typename _Pred,
typename _Alloc>
383 StreamedLength(
const std::unordered_multiset<_valueT, _Hash, _Pred, _Alloc> & m)
385 using myType = std::unordered_multiset<_valueT, _Hash, _Pred, _Alloc>;
386 return(ContainerStreamedLength<myType>(m));
393 {
return sl.StreamedLength(); }
399 {
return sl.StreamedLength(); }
404 template <
typename... Args>
405 static uint64_t StreamedLengthV(
const Args & ...args)
414 template <
typename _inputIteratorT>
415 static uint64_t
StreamedLength(_inputIteratorT f, _inputIteratorT l)
426 template <
typename _containerT>
427 static uint64_t ContainerStreamedLength(
const _containerT & c)
429 uint64_t rc =
sizeof(uint64_t);
440 template <
typename T,
size_t elt>
446 template <
typename T>
447 class TupleIOHelper<T, 0>
454 static uint64_t StreamedLength(
const T & t)
463 template <
typename T,
size_t elt>
471 static uint64_t StreamedLength(
const T & t)
473 uint64_t rc = TupleIOHelper<T,elt-1>::StreamedLength(t);
A configure target for dealing with OS differences.
Dwm::StreamedLengthCapable pure virtual class declaration.
This class contains a collection of static functions for calculating the streamed length of simple ty...
Definition DwmIOUtils.hh:79
static uint64_t StreamedLength(const std::string &s)
Returns the number of bytes that should be written if we call Write() for a string.
Definition DwmIOUtils.hh:184
static uint64_t StreamedLength(const std::list< _valueT, _Alloc > &l)
Returns the number of bytes that should be written if we call Write() for a list<_valueT>
Definition DwmIOUtils.hh:262
static uint64_t TupleStreamedLength(const T &t)
T must be a tuple.
Definition DwmIOUtils.hh:315
static uint64_t StreamedLength(const std::set< _valueT, _Compare, _Alloc > &l)
Returns the number of bytes that should be written if we call Write() for a set<_valueT>
Definition DwmIOUtils.hh:273
static uint64_t StreamedLength(const std::map< _keyT, _valueT, _Compare, _Alloc > &m)
Returns the number of bytes that should be written if we call Write() for a map<_keyT,...
Definition DwmIOUtils.hh:206
static uint64_t StreamedLength(bool b)
Returns the number of bytes that would be written if we called Write() member for a bool.
Definition DwmIOUtils.hh:103
static uint64_t StreamedLength(float val)
Returns the number of bytes that should be written if we call Write() for a float.
Definition DwmIOUtils.hh:166
static uint64_t StreamedLength(int16_t val)
Returns the number of bytes that would be written if we called Write() for an int16_t.
Definition DwmIOUtils.hh:112
static uint64_t StreamedLength(int64_t val)
Returns the number of bytes that would be written if we called Write() for an int64_t.
Definition DwmIOUtils.hh:148
static uint64_t StreamedLength(uint16_t val)
Returns the number of bytes that would be written if we called Write() for a uint16_t.
Definition DwmIOUtils.hh:121
static uint64_t StreamedLength(const std::array< _valueT, N > &a)
Returns the number of bytes that should be written if we call Write() for an array<_valueT,...
Definition DwmIOUtils.hh:228
static uint64_t StreamedLength(uint32_t val)
Returns the number of bytes that would be written if we called Write() for a uint32_t.
Definition DwmIOUtils.hh:139
static uint64_t StreamedLength(const std::multimap< _keyT, _valueT, _Compare, _Alloc > &m)
Returns the number of bytes that should be written if we call Write() for a multimap<_keyT,...
Definition DwmIOUtils.hh:218
static uint64_t StreamedLength(char c)
Returns the number of bytes that would be written if we called Write() for a char.
Definition DwmIOUtils.hh:85
static uint64_t StreamedLength(const std::vector< _valueT, _Alloc > &v)
Returns the number of bytes that should be written if we call Write() for a vector<_valueT>
Definition DwmIOUtils.hh:242
static uint64_t StreamedLength(uint64_t val)
Returns the number of bytes that would be written if we called Write() for a uint64_t.
Definition DwmIOUtils.hh:157
static uint64_t StreamedLength(double val)
Returns the number of bytes that should be written if we call Write() for a double.
Definition DwmIOUtils.hh:175
static uint64_t StreamedLength(const std::multiset< _valueT, _Compare, _Alloc > &l)
Returns the number of bytes that should be written if we call Write() for a multiset<_valueT>
Definition DwmIOUtils.hh:284
static uint64_t StreamedLength(const std::deque< _valueT, _Alloc > &d)
Returns the number of bytes that should be written if we call Write() for a deque<_valueT>
Definition DwmIOUtils.hh:252
static uint64_t StreamedLength(uint8_t c)
Returns the number of bytes that would be written if we called Write() for a uint8_t.
Definition DwmIOUtils.hh:94
static uint64_t StreamedLength(const std::pair< _firstT, _secondT > &p)
Returns the number of bytes that should be written if we call Write() for a pair<_firstT,...
Definition DwmIOUtils.hh:194
static uint64_t StreamedLength(const std::tuple< T, Args... > &t)
Returns the number of bytes that should be written if we call Write() for a tuple.
Definition DwmIOUtils.hh:306
static uint64_t StreamedLength(int32_t val)
Returns the number of bytes that would be written if we called Write() for an int32_t.
Definition DwmIOUtils.hh:130