56#include <unordered_map>
57#include <unordered_set>
88 static int BZRead(BZFILE *bzf,
char & c);
100 static int BZRead(BZFILE *bzf, uint8_t & c);
112 static int BZRead(BZFILE *bzf,
bool & b);
124 static int BZRead(BZFILE *bzf, int16_t & val);
137 static int BZRead(BZFILE *bzf, uint16_t & val);
144 static int BZWrite(BZFILE *bzf, uint16_t val);
150 static int BZRead(BZFILE *bzf, int32_t & val);
163 static int BZRead(BZFILE *bzf, uint32_t & val);
170 static int BZWrite(BZFILE *bzf, uint32_t val);
176 static int BZRead(BZFILE *bzf, int64_t & val);
183 static int BZWrite(BZFILE *bzf,
const int64_t & val);
189 static int BZRead(BZFILE *bzf, uint64_t & val);
196 static int BZWrite(BZFILE *bzf,
const uint64_t & val);
203 static int BZRead(BZFILE *bzf,
float & val);
217 static int BZRead(BZFILE *bzf,
double & val);
224 static int BZWrite(BZFILE *bzf,
const double & val);
232 static int BZRead(BZFILE *bzf, std::string & s);
241 static int BZWrite(BZFILE *bzf,
const std::string & s);
247 {
return(val.
BZRead(bzf)); }
254 {
return val.BZRead(bzf); }
267 {
return val.BZWrite(bzf); }
273 template <
typename _firstT,
typename _secondT>
274 static int BZRead(BZFILE *bzf, std::pair<_firstT, _secondT> & p)
278 int bytesRead =
BZRead(bzf, p.first);
281 bytesRead =
BZRead(bzf, p.second);
295 template <
typename _firstT,
typename _secondT>
296 static int BZWrite(BZFILE *bzf,
const std::pair<_firstT,_secondT> & p)
300 int bytesWritten =
BZWrite(bzf, p.first);
301 if (bytesWritten > 0) {
303 bytesWritten =
BZWrite(bzf, p.second);
304 if (bytesWritten > 0) {
319 template <
typename _keyT,
typename _valueT,
320 typename _Compare,
typename _Alloc>
321 static int BZRead(BZFILE *bzf, std::map<_keyT, _valueT, _Compare, _Alloc> & m)
323 return(PairAssocContBZRead<std::map<_keyT, _valueT, _Compare, _Alloc> >(bzf, m));
330 template<
typename _keyT,
typename _valueT,
331 typename _Compare,
typename _Alloc>
333 BZWrite(BZFILE *bzf,
const std::map<_keyT,_valueT,_Compare,_Alloc> & m)
335 return(ContainerBZWrite<std::map<_keyT,_valueT,_Compare,_Alloc> >(bzf, m));
342 template <
typename _keyT,
typename _valueT,
343 typename _Compare,
typename _Alloc>
345 BZRead(BZFILE *bzf, std::multimap<_keyT, _valueT, _Compare, _Alloc> & m)
347 return(PairAssocContBZRead<std::multimap<_keyT,_valueT,_Compare,_Alloc> >(bzf, m));
354 template <
typename _keyT,
typename _valueT,
355 typename _Compare,
typename _Alloc>
357 BZWrite(BZFILE *bzf,
const std::multimap<_keyT,_valueT, _Compare, _Alloc> & m)
359 return(ContainerBZWrite<std::multimap<_keyT,_valueT,_Compare,_Alloc> >(bzf, m));
366 template <
typename _valueT,
size_t N>
367 static int BZRead(BZFILE *bzf, std::array<_valueT, N> & a)
370 for (
size_t i = 0; i < N; ++i) {
371 int bytesRead =
BZRead(bzf, a[i]);
387 template <
typename _valueT,
size_t N>
388 static int BZWrite(BZFILE *bzf,
const std::array<_valueT, N> & a)
391 for (
size_t i = 0; i < N; ++i) {
392 int bytesWritten =
BZWrite(bzf, a[i]);
393 if (bytesWritten > 0) {
408 template <
typename _valueT,
typename _Alloc>
409 static int BZRead(BZFILE *bzf, std::vector<_valueT, _Alloc> & v)
411 return(ContainerBZRead<std::vector<_valueT, _Alloc> >(bzf, v));
418 template <
typename _valueT,
typename _Alloc>
419 static int BZWrite(BZFILE *bzf,
const std::vector<_valueT, _Alloc> & v)
421 return(ContainerBZWrite<std::vector<_valueT, _Alloc> >(bzf, v));
428 template <
typename _valueT,
typename _Alloc>
429 static int BZRead(BZFILE *bzf, std::deque<_valueT, _Alloc> & d)
431 return(ContainerBZRead<std::deque<_valueT, _Alloc> >(bzf, d));
438 template <
typename _valueT,
typename _Alloc>
439 static int BZWrite(BZFILE *bzf,
const std::deque<_valueT, _Alloc> & d)
441 return(ContainerBZWrite<std::deque<_valueT, _Alloc> >(bzf, d));
448 template <
typename _valueT,
typename _Alloc>
449 static int BZRead(BZFILE *bzf, std::list<_valueT, _Alloc> & l)
451 return(ContainerBZRead<std::list<_valueT, _Alloc> >(bzf, l));
458 template <
typename _valueT,
typename _Alloc>
459 static int BZWrite(BZFILE *bzf,
const std::list<_valueT, _Alloc> & l)
461 return(ContainerBZWrite<std::list<_valueT, _Alloc> >(bzf, l));
468 template <
typename _valueT,
typename _Compare,
typename _Alloc>
469 static int BZRead(BZFILE *bzf, std::set<_valueT, _Compare, _Alloc> & l)
471 return(ContainerBZRead<std::set<_valueT, _Compare, _Alloc> >(bzf, l));
478 template <
typename _valueT,
typename _Compare,
typename _Alloc>
479 static int BZWrite(BZFILE *bzf,
const std::set<_valueT, _Compare, _Alloc> & l)
481 return(ContainerBZWrite<std::set<_valueT, _Compare, _Alloc> >(bzf, l));
488 template <
typename _valueT,
typename _Compare,
typename _Alloc>
489 static int BZRead(BZFILE *bzf, std::multiset<_valueT, _Compare, _Alloc> & l)
491 return(ContainerBZRead<std::multiset<_valueT, _Compare, _Alloc> >(bzf, l));
498 template <
typename _valueT,
typename _Compare,
typename _Alloc>
500 BZWrite(BZFILE *bzf,
const std::multiset<_valueT, _Compare, _Alloc> & l)
502 return(ContainerBZWrite<std::multiset<_valueT, _Compare, _Alloc> >(bzf, l));
508 template <
typename... Args>
509 static int BZWrite(BZFILE *bzf,
const std::tuple<Args...> & t)
511 return(std::apply([&bzf](
auto&&...args)
514 auto read_tuple_mem = [&bzf,&rc](
auto&& x) {
515 int bytesWritten =
BZWrite(bzf, x);
516 if (bytesWritten > 0) { rc += bytesWritten;
return true; }
517 else {
return false; }
519 if ((read_tuple_mem(args) && ...)) {
531 template <
typename... Args>
532 static int BZRead(BZFILE *bzf, std::tuple<Args...> & t)
534 return(std::apply([&bzf](
auto&&...args)
537 auto read_tuple_mem = [&bzf,&rc](
auto&& x) {
538 int bytesRead =
BZRead(bzf, x);
539 if (bytesRead > 0) { rc += bytesRead;
return true; }
540 else {
return false; }
542 if ((read_tuple_mem(args) && ...)) {
555 template<
typename _keyT,
typename _valueT,
typename _Hash,
556 typename _Pred,
typename _Alloc>
559 std::unordered_map<_keyT,_valueT,_Hash,_Pred,_Alloc> & hm)
561 return(PairAssocContBZRead<std::unordered_map<_keyT,_valueT,_Hash,_Pred,_Alloc> >(bzf, hm));
568 template<
typename _keyT,
typename _valueT,
typename _Hash,
569 typename _Pred,
typename _Alloc>
572 const std::unordered_map<_keyT,_valueT,_Hash,_Pred,_Alloc> & hm)
574 return(ContainerBZWrite<std::unordered_map<_keyT,_valueT,_Hash,_Pred,_Alloc> >(bzf, hm));
581 template<
typename _valueT,
typename _Hash,
582 typename _Pred,
typename _Alloc>
585 std::unordered_set<_valueT,_Hash,_Pred,_Alloc> & hm)
587 return(ContainerBZRead<std::unordered_set<_valueT,_Hash,_Pred,_Alloc> >(bzf, hm));
594 template<
typename _valueT,
typename _Hash,
595 typename _Pred,
typename _Alloc>
598 const std::unordered_set<_valueT,_Hash,_Pred,_Alloc> & hm)
600 return(ContainerBZWrite<std::unordered_set<_valueT,_Hash,_Pred,_Alloc> >(bzf, hm));
607 template<
typename _keyT,
typename _valueT,
typename _Hash,
608 typename _Pred,
typename _Alloc>
611 std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc> & hm)
613 return(PairAssocContBZRead<std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc> >(bzf, hm));
620 template<
typename _keyT,
typename _valueT,
typename _Hash,
621 typename _Pred,
typename _Alloc>
624 const std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc> & hm)
626 return(ContainerBZWrite<std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc> >(bzf, hm));
633 template<
typename _valueT,
typename _Hash,
634 typename _Pred,
typename _Alloc>
637 std::unordered_multiset<_valueT,_Hash,_Pred,_Alloc> & hm)
639 return(ContainerBZRead<std::unordered_multiset<_valueT,_Hash,_Pred,_Alloc> >(bzf, hm));
646 template<
typename _valueT,
typename _Hash,
647 typename _Pred,
typename _Alloc>
650 const std::unordered_multiset<_valueT,_Hash,_Pred,_Alloc> & hm)
652 return(ContainerBZWrite<std::unordered_multiset<_valueT,_Hash,_Pred,_Alloc> >(bzf, hm));
660 static int BZRead(BZFILE *bzf, std::monostate & sm)
670 static int BZWrite(BZFILE *bzf,
const std::monostate & sm)
679 template <
typename... Ts>
680 static int BZRead(BZFILE *bzf, std::variant<Ts...> & v)
684 int bytesRead =
BZRead(bzf, index);
687 if (index < std::variant_size_v<std::variant<Ts...>>) {
689 std::visit([&] (
auto && arg) { rc =
BZRead(bzf, arg); }, v);
690 if (bytesRead >= 0) {
704 template <
typename... Ts>
705 static int BZWrite(BZFILE *bzf,
const std::variant<Ts...> & v)
708 uint64_t index = v.index();
709 int bytesWritten =
BZWrite(bzf, index);
710 if (bytesWritten > 0) {
712 std::visit([&] (
const auto & arg)
713 { bytesWritten =
BZWrite(bzf, arg); }, v);
714 if (bytesWritten >= 0) {
728 template <
typename ...Args>
729 static int BZReadV(BZFILE *bzf, Args & ...args)
734 auto readOne = [&] (
auto & arg) {
736 int bytesRead =
BZRead(bzf, arg);
746 (readOne(args) && ...);
754 template <
typename ...Args>
755 static int BZWriteV(BZFILE *bzf,
const Args & ...args)
760 auto writeOne = [&] (
auto & arg) {
762 int bytesWritten =
BZWrite(bzf, arg);
763 if (bytesWritten > 0) {
772 (writeOne(args) && ...);
780 template <
typename _inputIteratorT>
781 static int BZWrite(BZFILE *bzf, _inputIteratorT f, _inputIteratorT l)
785 for ( ; f != l; ++f) {
786 int bytesWritten =
BZWrite(bzf, *f);
787 if (bytesWritten > 0) {
804 template <
typename _containerT>
805 static int ContainerBZRead(BZFILE *bzf, _containerT & c)
812 int bytesRead =
BZRead(bzf, numEntries);
813 if (bytesRead ==
sizeof(numEntries)) {
815 for (uint64_t i = 0; i < numEntries; ++i) {
816 typename _containerT::value_type val;
817 bytesRead =
BZRead(bzf, val);
820 c.insert(c.end(), std::move(val));
837 template <
typename _containerT>
838 static int ContainerBZWrite(BZFILE *bzf,
const _containerT & c)
842 uint64_t numEntries = c.size();
843 uint64_t bytesWritten =
BZWrite(bzf, numEntries);
844 if (bytesWritten ==
sizeof(numEntries)) {
851 if (bytesWritten > 0)
866 template <
typename _containerT>
867 static int PairAssocContBZRead(BZFILE *bzf, _containerT & m)
874 int bytesRead =
BZRead(bzf, numEntries);
875 if (bytesRead ==
sizeof(numEntries)) {
877 for (uint64_t i = 0; i < numEntries; ++i) {
878 typename _containerT::key_type key;
879 bytesRead =
BZRead(bzf, key);
882 typename _containerT::mapped_type val;
883 bytesRead =
BZRead(bzf, val);
886 m.insert(
typename _containerT::value_type(std::move(key),
Dwm::HasBZRead and Dwm::HasBZWrite concepts. Dwm::BZ2Readable, Dwm::BZ2Writable and Dwm::BZ2IOCapable...
A configure target for dealing with OS differences.
Dwm::VariantFromIndex function template.
std::variant< Ts... > VariantFromIndex(size_t index)
Returns a variant type V whose contents are set to a default constructed value of the type at index i...
Definition DwmVariantFromIndex.hh:57
This class contains a collection of static functions for reading and writing simple types in network ...
Definition DwmBZ2IO.hh:82
static int BZWrite(BZFILE *bzf, const std::unordered_set< _valueT, _Hash, _Pred, _Alloc > &hm)
Writes an unordered_set to a BZFILE pointer.
Definition DwmBZ2IO.hh:597
static int BZWrite(BZFILE *bzf, const std::unordered_map< _keyT, _valueT, _Hash, _Pred, _Alloc > &hm)
Writes an unordered_map to a BZFILE pointer.
Definition DwmBZ2IO.hh:571
static int BZRead(BZFILE *bzf, int64_t &val)
Reads val from bzf, in network byte order (MSB first).
static int BZRead(BZFILE *bzf, std::unordered_multiset< _valueT, _Hash, _Pred, _Alloc > &hm)
Reads an unordered_multiset from a BZFILE pointer.
Definition DwmBZ2IO.hh:636
static int BZWrite(BZFILE *bzf, const BZ2Writable &val)
Wrapper function to write a BZ2Writable object to a BZFILE pointer.
Definition DwmBZ2IO.hh:259
static int BZWrite(BZFILE *bzf, int32_t val)
Writes val to bzf, in network byte order (MSB first).
static int BZRead(BZFILE *bzf, bool &b)
Reads b from bzf.
static int BZRead(BZFILE *bzf, HasBZRead auto &val)
Reads val from bzf, where val meets the requirements of the HasBZRead concept.
Definition DwmBZ2IO.hh:253
static int BZWrite(BZFILE *bzf, const HasBZWrite auto &val)
Writes val to bzf, where val meets the requirements of the HasBZWrite concept.
Definition DwmBZ2IO.hh:266
static int BZRead(BZFILE *bzf, uint64_t &val)
Reads val from bzf, in network byte order (MSB first).
static int BZRead(BZFILE *bzf, int32_t &val)
Reads val from bzf, in network byte order (MSB first).
static int BZRead(BZFILE *bzf, std::unordered_map< _keyT, _valueT, _Hash, _Pred, _Alloc > &hm)
Reads an unordered_map from a BZFILE pointer.
Definition DwmBZ2IO.hh:558
static int BZRead(BZFILE *bzf, int16_t &val)
Reads val from bzf, in network byte order (MSB first).
static int BZWrite(BZFILE *bzf, const std::set< _valueT, _Compare, _Alloc > &l)
Writes a set<_valueT> to a BZFILE pointer.
Definition DwmBZ2IO.hh:479
static int BZWrite(BZFILE *bzf, const std::deque< _valueT, _Alloc > &d)
Writes a deque<_valueT> to a BZFILE pointer.
Definition DwmBZ2IO.hh:439
static int BZWrite(BZFILE *bzf, const std::multiset< _valueT, _Compare, _Alloc > &l)
Writes a multiset<_valueT> to a BZFILE pointer.
Definition DwmBZ2IO.hh:500
static int BZWrite(BZFILE *bzf, const std::pair< _firstT, _secondT > &p)
Writes a pair<_firstT,_secondT> to a BZFILE pointer.
Definition DwmBZ2IO.hh:296
static int BZWrite(BZFILE *bzf, float val)
Writes val tp bzf, in IEEE format (see RFC 1832 and/or ANSI/IEEE Standard 754-1985).
static int BZRead(BZFILE *bzf, std::string &s)
Reads s from bzf.
static int BZWrite(BZFILE *bzf, const std::vector< _valueT, _Alloc > &v)
Writes a vector<_valueT> to a BZFILE pointer.
Definition DwmBZ2IO.hh:419
static int BZRead(BZFILE *bzf, double &val)
Reads val from bzf, in IEEE format (see RFC 1832 and/or ANSI/IEEE Standard 754-1985).
static int BZRead(BZFILE *bzf, std::pair< _firstT, _secondT > &p)
Reads a pair<_firstT,_secondT> from a BZFILE pointer.
Definition DwmBZ2IO.hh:274
static int BZWrite(BZFILE *bzf, uint16_t val)
Writes val to bzf, in network byte order (MSB first).
static int BZRead(BZFILE *bzf, char &c)
Reads from bzf.
static int BZRead(BZFILE *bzf, std::multiset< _valueT, _Compare, _Alloc > &l)
Reads a multiset<_valueT> from a BZFILE pointer.
Definition DwmBZ2IO.hh:489
static int BZWrite(BZFILE *bzf, uint32_t val)
Writes val to bzf, in network byte order (MSB first).
static int BZWrite(BZFILE *bzf, const std::multimap< _keyT, _valueT, _Compare, _Alloc > &m)
Writes a multimap<_keyT,_valueT> to a BZFILE pointer.
Definition DwmBZ2IO.hh:357
static int BZWrite(BZFILE *bzf, const double &val)
Writes val tp bzf, in IEEE format (see RFC 1832 and/or ANSI/IEEE Standard 754-1985).
static int BZWrite(BZFILE *bzf, char c)
Writes c to bzf.
static int BZWrite(BZFILE *bzf, int16_t val)
Writes val to bzf, in network byte order (MSB first).
static int BZWrite(BZFILE *bzf, const uint64_t &val)
Writes val to bzf, in network byte order (MSB first).
static int BZRead(BZFILE *bzf, std::vector< _valueT, _Alloc > &v)
Reads a vector<_valueT> from a BZFILE pointer.
Definition DwmBZ2IO.hh:409
static int BZWrite(BZFILE *bzf, const std::list< _valueT, _Alloc > &l)
Writes a list<_valueT> to a BZFILE pointer.
Definition DwmBZ2IO.hh:459
static int BZWriteV(BZFILE *bzf, const Args &...args)
Writes args to bzf.
Definition DwmBZ2IO.hh:755
static int BZRead(BZFILE *bzf, std::deque< _valueT, _Alloc > &d)
Reads a deque<_valueT> from a BZFILE pointer.
Definition DwmBZ2IO.hh:429
static int BZRead(BZFILE *bzf, float &val)
Reads val from bzf, in IEEE format (see RFC 1832 and/or ANSI/IEEE Standard 754-1985).
static int BZRead(BZFILE *bzf, std::array< _valueT, N > &a)
Reads an array<_valueT,N> from a BZFILE pointer.
Definition DwmBZ2IO.hh:367
static int BZRead(BZFILE *bzf, uint16_t &val)
Reads val from bzf, in network byte order (MSB first).
static int BZWrite(BZFILE *bzf, const std::unordered_multimap< _keyT, _valueT, _Hash, _Pred, _Alloc > &hm)
Writes an unordered_multimap to a BZFILE pointer.
Definition DwmBZ2IO.hh:623
static int BZRead(BZFILE *bzf, uint8_t &c)
Reads c from bzf.
static int BZRead(BZFILE *bzf, std::unordered_multimap< _keyT, _valueT, _Hash, _Pred, _Alloc > &hm)
Reads an unordered_multimap from a BZFILE pointer.
Definition DwmBZ2IO.hh:610
static int BZWrite(BZFILE *bzf, const std::monostate &sm)
Just a dummy helper function for std::variant instances that hold a std::monostate.
Definition DwmBZ2IO.hh:670
static int BZWrite(BZFILE *bzf, uint8_t c)
Writes c to bzf.
static int BZWrite(BZFILE *bzf, const std::string &s)
Writes s to bzf.
static int BZRead(BZFILE *bzf, std::list< _valueT, _Alloc > &l)
Reads a list<_valueT> from a BZFILE pointer.
Definition DwmBZ2IO.hh:449
static int BZReadV(BZFILE *bzf, Args &...args)
Reads args from bzf.
Definition DwmBZ2IO.hh:729
static int BZRead(BZFILE *bzf, std::monostate &sm)
Just a dummy helper function for std::variant instances that hold a std::monostate.
Definition DwmBZ2IO.hh:660
static int BZRead(BZFILE *bzf, std::map< _keyT, _valueT, _Compare, _Alloc > &m)
Reads a map<_keyT,_valueT> from a BZFILE pointer.
Definition DwmBZ2IO.hh:321
static int BZRead(BZFILE *bzf, std::unordered_set< _valueT, _Hash, _Pred, _Alloc > &hm)
Reads an unordered_set from a BZFILE pointer.
Definition DwmBZ2IO.hh:584
static int BZWrite(BZFILE *bzf, const int64_t &val)
Writes val to bzf, in network byte order (MSB first).
static int BZRead(BZFILE *bzf, std::set< _valueT, _Compare, _Alloc > &l)
Reads a set<_valueT> from a BZFILE pointer.
Definition DwmBZ2IO.hh:469
static int BZWrite(BZFILE *bzf, bool b)
Writes b to bzf.
static int BZRead(BZFILE *bzf, uint32_t &val)
Reads val from bzf, in network byte order (MSB first).
static int BZRead(BZFILE *bzf, std::multimap< _keyT, _valueT, _Compare, _Alloc > &m)
Reads a multimap<_keyT,_valueT> from a BZFILE pointer.
Definition DwmBZ2IO.hh:345
static int BZWrite(BZFILE *bzf, const std::array< _valueT, N > &a)
Writes an array<_valueT,N> to a BZFILE pointer.
Definition DwmBZ2IO.hh:388
static int BZRead(BZFILE *bzf, BZ2Readable &val)
Wrapper function to read a BZ2Readable object from a BZFILE pointer.
Definition DwmBZ2IO.hh:246
static int BZWrite(BZFILE *bzf, const std::map< _keyT, _valueT, _Compare, _Alloc > &m)
Writes a map<_keyT,_valueT> to a BZFILE pointer.
Definition DwmBZ2IO.hh:333
static int BZWrite(BZFILE *bzf, const std::unordered_multiset< _valueT, _Hash, _Pred, _Alloc > &hm)
Writes an unordered_multiset to a BZFILE pointer.
Definition DwmBZ2IO.hh:649
static int BZRead(BZFILE *bzf, std::variant< Ts... > &v)
Reads a variant from a BZFILE.
Definition DwmBZ2IO.hh:680
This class is a pure virtual class, defining an interface for classes that can read their contents fr...
Definition DwmBZ2IOCapable.hh:79
virtual int BZRead(BZFILE *bzf)=0
Read from a BZFILE pointer.
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition DwmBZ2IOCapable.hh:95
virtual int BZWrite(BZFILE *bzf) const =0
Write to a BZFILE pointer.
T has a BZRead(BZFILE *) member that returns int (return value of BZ2_bzread() on success,...
Definition DwmBZ2IOCapable.hh:61
T has a BZWrite(BZFILE *) const member that returns int (return value of BZ2_bzwrite() on success,...
Definition DwmBZ2IOCapable.hh:70