libDwm-0.9.45
DwmGZIO.hh
Go to the documentation of this file.
1//===========================================================================
2// @(#) $DwmPath$
3//===========================================================================
4// Copyright (c) Daniel W. McRobb 2004, 2016, 2020, 2024
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions
9// are met:
10//
11// 1. Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// 2. Redistributions in binary form must reproduce the above copyright
14// notice, this list of conditions and the following disclaimer in the
15// documentation and/or other materials provided with the distribution.
16// 3. The names of the authors and copyright holders may not be used to
17// endorse or promote products derived from this software without
18// specific prior written permission.
19//
20// IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
21// DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
22// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
23// EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
24// DAMAGE.
25//
26// THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
27// DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
28// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
29// REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
30// IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31// WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
32// PURPOSE, OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
33// TRADEMARK OR OTHER RIGHTS.
34//===========================================================================
35
36//---------------------------------------------------------------------------
40//---------------------------------------------------------------------------
41
42#ifndef _DWMGZIO_HH_
43#define _DWMGZIO_HH_
44
45extern "C" {
46 #include <inttypes.h>
47 #include <sys/types.h>
48}
49
50#include <array>
51#include <cstdio>
52#include <deque>
53#include <iostream>
54#include <list>
55#include <map>
56#include <set>
57#include <string>
58#include <tuple>
59#include <unordered_map>
60#include <unordered_set>
61#include <variant>
62#include <vector>
63
64#include "DwmPortability.hh"
65#include "DwmGZIOCapable.hh"
67
68namespace Dwm {
69
70 //--------------------------------------------------------------------------
83 //--------------------------------------------------------------------------
84 class GZIO
85 {
86 public:
87 //------------------------------------------------------------------------
90 //------------------------------------------------------------------------
91 static int Read(gzFile gzf, char & c);
92
93 //------------------------------------------------------------------------
96 //------------------------------------------------------------------------
97 static int Write(gzFile gzf, char c);
98
99 //------------------------------------------------------------------------
102 //------------------------------------------------------------------------
103 static int Read(gzFile gzf, uint8_t & c);
104
105 //------------------------------------------------------------------------
108 //------------------------------------------------------------------------
109 static int Write(gzFile gzf, uint8_t c);
110
111 //------------------------------------------------------------------------
114 //------------------------------------------------------------------------
115 static int Read(gzFile gzf, bool & b);
116
117 //------------------------------------------------------------------------
120 //------------------------------------------------------------------------
121 static int Write(gzFile gzf, bool b);
122
123 //------------------------------------------------------------------------
126 //------------------------------------------------------------------------
127 static int Read(gzFile gzf, int16_t & val);
128
129 //------------------------------------------------------------------------
133 //------------------------------------------------------------------------
134 static int Write(gzFile gzf, int16_t val);
135
136 //------------------------------------------------------------------------
139 //------------------------------------------------------------------------
140 static int Read(gzFile gzf, uint16_t & val);
141
142 //------------------------------------------------------------------------
146 //------------------------------------------------------------------------
147 static int Write(gzFile gzf, uint16_t val);
148
149 //------------------------------------------------------------------------
152 //------------------------------------------------------------------------
153 static int Read(gzFile gzf, int32_t & val);
154
155 //------------------------------------------------------------------------
159 //------------------------------------------------------------------------
160 static int Write(gzFile gzf, int32_t val);
161
162 //------------------------------------------------------------------------
165 //------------------------------------------------------------------------
166 static int Read(gzFile gzf, uint32_t & val);
167
168 //------------------------------------------------------------------------
172 //------------------------------------------------------------------------
173 static int Write(gzFile gzf, uint32_t val);
174
175 //------------------------------------------------------------------------
178 //------------------------------------------------------------------------
179 static int Read(gzFile gzf, int64_t & val);
180
181 //------------------------------------------------------------------------
185 //------------------------------------------------------------------------
186 static int Write(gzFile gzf, const int64_t & val);
187
188 //------------------------------------------------------------------------
191 //------------------------------------------------------------------------
192 static int Read(gzFile gzf, uint64_t & val);
193
194 //------------------------------------------------------------------------
198 //------------------------------------------------------------------------
199 static int Write(gzFile gzf, const uint64_t & val);
200
201 //------------------------------------------------------------------------
205 //------------------------------------------------------------------------
206 static int Read(gzFile gzf, float & val);
207
208 //------------------------------------------------------------------------
212 //------------------------------------------------------------------------
213 static int Write(gzFile gzf, float val);
214
215 //------------------------------------------------------------------------
219 //------------------------------------------------------------------------
220 static int Read(gzFile gzf, double & val);
221
222 //------------------------------------------------------------------------
226 //------------------------------------------------------------------------
227 static int Write(gzFile gzf, const double & val);
228
229 //------------------------------------------------------------------------
234 //------------------------------------------------------------------------
235 static int Read(gzFile gzf, std::string & s);
236
237 //------------------------------------------------------------------------
243 //------------------------------------------------------------------------
244 static int Write(gzFile gzf, const std::string & s);
245
246 //------------------------------------------------------------------------
248 //------------------------------------------------------------------------
249 static int Read(gzFile gzf, GZReadable & val)
250 { return(val.Read(gzf)); }
251
252 //------------------------------------------------------------------------
255 //------------------------------------------------------------------------
256 static int Read(gzFile gzf, HasGZRead auto & val)
257 { return val.Read(gzf); }
258
259 //------------------------------------------------------------------------
261 //------------------------------------------------------------------------
262 static int Write(gzFile gzf, const GZWritable & val)
263 { return(val.Write(gzf)); }
264
265 //------------------------------------------------------------------------
268 //------------------------------------------------------------------------
269 static int Write(gzFile gzf, const HasGZWrite auto & val)
270 { return val.Write(gzf); }
271
272 //------------------------------------------------------------------------
275 //------------------------------------------------------------------------
276 template <typename _firstT, typename _secondT>
277 static int Read(gzFile gzf, std::pair<_firstT, _secondT> & p)
278 {
279 int rc = -1;
280 if (gzf) {
281 int bytesRead = Read(gzf, p.first);
282 if (bytesRead > 0) {
283 rc = bytesRead;
284 bytesRead = Read(gzf, p.second);
285 if (bytesRead > 0)
286 rc += bytesRead;
287 else
288 rc = -1;
289 }
290 }
291 return(rc);
292 }
293
294 //------------------------------------------------------------------------
297 //------------------------------------------------------------------------
298 template <typename _firstT, typename _secondT>
299 static int Write(gzFile gzf, const std::pair<_firstT,_secondT> & p)
300 {
301 int rc = -1;
302 if (gzf) {
303 int bytesWritten = Write(gzf, p.first);
304 if (bytesWritten > 0) {
305 rc = bytesWritten;
306 bytesWritten = Write(gzf, p.second);
307 if (bytesWritten > 0) {
308 rc += bytesWritten;
309 }
310 else {
311 rc = -1;
312 }
313 }
314 }
315 return(rc);
316 }
317
318 //------------------------------------------------------------------------
321 //------------------------------------------------------------------------
322 template <typename _keyT, typename _valueT,
323 typename _Compare, typename _Alloc>
324 static int Read(gzFile gzf, std::map<_keyT, _valueT, _Compare, _Alloc> & m)
325 {
326 return(PairAssocContRead<std::map<_keyT, _valueT, _Compare, _Alloc> >(gzf, m));
327 }
328
329 //------------------------------------------------------------------------
332 //------------------------------------------------------------------------
333 template<typename _keyT, typename _valueT,
334 typename _Compare, typename _Alloc>
335 static int
336 Write(gzFile gzf, const std::map<_keyT,_valueT,_Compare,_Alloc> & m)
337 {
338 return(ContainerWrite<std::map<_keyT,_valueT,_Compare,_Alloc> >(gzf, m));
339 }
340
341 //------------------------------------------------------------------------
344 //------------------------------------------------------------------------
345 template <typename _keyT, typename _valueT,
346 typename _Compare, typename _Alloc>
347 static int
348 Read(gzFile gzf, std::multimap<_keyT, _valueT, _Compare, _Alloc> & m)
349 {
350 return(PairAssocContRead<std::multimap<_keyT,_valueT,_Compare,_Alloc> >(gzf, m));
351 }
352
353 //------------------------------------------------------------------------
356 //------------------------------------------------------------------------
357 template <typename _keyT, typename _valueT,
358 typename _Compare, typename _Alloc>
359 static int
360 Write(gzFile gzf, const std::multimap<_keyT,_valueT, _Compare, _Alloc> & m)
361 {
362 return(ContainerWrite<std::multimap<_keyT,_valueT,_Compare,_Alloc> >(gzf, m));
363 }
364
365 //------------------------------------------------------------------------
368 //------------------------------------------------------------------------
369 template <typename _valueT, size_t N>
370 static int Read(gzFile gzf, std::array<_valueT, N> & a)
371 {
372 int rc = 0;
373 for (size_t i = 0; i < N; ++i) {
374 int bytesRead = Read(gzf, a[i]);
375 if (bytesRead > 0) {
376 rc += bytesRead;
377 }
378 else {
379 rc = -1;
380 break;
381 }
382 }
383 return rc;
384 }
385
386 //------------------------------------------------------------------------
389 //------------------------------------------------------------------------
390 template <typename _valueT, size_t N>
391 static int Write(gzFile gzf, const std::array<_valueT, N> & a)
392 {
393 int rc = 0;
394 for (size_t i = 0; i < N; ++i) {
395 int bytesWritten = Write(gzf, a[i]);
396 if (bytesWritten > 0) {
397 rc += bytesWritten;
398 }
399 else {
400 rc = -1;
401 break;
402 }
403 }
404 return rc;
405 }
406
407 //------------------------------------------------------------------------
410 //------------------------------------------------------------------------
411 template <typename _valueT, typename _Alloc>
412 static int Read(gzFile gzf, std::vector<_valueT, _Alloc> & v)
413 {
414 return(ContainerRead<std::vector<_valueT, _Alloc> >(gzf, v));
415 }
416
417 //------------------------------------------------------------------------
420 //------------------------------------------------------------------------
421 template <typename _valueT, typename _Alloc>
422 static int Write(gzFile gzf, const std::vector<_valueT, _Alloc> & v)
423 {
424 return(ContainerWrite<std::vector<_valueT, _Alloc> >(gzf, v));
425 }
426
427 //------------------------------------------------------------------------
430 //------------------------------------------------------------------------
431 template <typename _valueT, typename _Alloc>
432 static int Read(gzFile gzf, std::deque<_valueT, _Alloc> & d)
433 {
434 return(ContainerRead<std::deque<_valueT, _Alloc> >(gzf, d));
435 }
436
437 //------------------------------------------------------------------------
440 //------------------------------------------------------------------------
441 template <typename _valueT, typename _Alloc>
442 static int Write(gzFile gzf, const std::deque<_valueT, _Alloc> & d)
443 {
444 return(ContainerWrite<std::deque<_valueT, _Alloc> >(gzf, d));
445 }
446
447 //------------------------------------------------------------------------
450 //------------------------------------------------------------------------
451 template <typename _valueT, typename _Alloc>
452 static int Read(gzFile gzf, std::list<_valueT, _Alloc> & l)
453 {
454 return(ContainerRead<std::list<_valueT, _Alloc> >(gzf, l));
455 }
456
457 //------------------------------------------------------------------------
460 //------------------------------------------------------------------------
461 template <typename _valueT, typename _Alloc>
462 static int Write(gzFile gzf, const std::list<_valueT, _Alloc> & l)
463 {
464 return(ContainerWrite<std::list<_valueT, _Alloc> >(gzf, l));
465 }
466
467 //------------------------------------------------------------------------
470 //------------------------------------------------------------------------
471 template <typename _valueT, typename _Compare, typename _Alloc>
472 static int Read(gzFile gzf, std::set<_valueT, _Compare, _Alloc> & l)
473 {
474 return(ContainerRead<std::set<_valueT, _Compare, _Alloc> >(gzf, l));
475 }
476
477 //------------------------------------------------------------------------
480 //------------------------------------------------------------------------
481 template <typename _valueT, typename _Compare, typename _Alloc>
482 static int Write(gzFile gzf, const std::set<_valueT, _Compare, _Alloc> & l)
483 {
484 return(ContainerWrite<std::set<_valueT, _Compare, _Alloc> >(gzf, l));
485 }
486
487 //------------------------------------------------------------------------
490 //------------------------------------------------------------------------
491 template <typename _valueT, typename _Compare, typename _Alloc>
492 static int Read(gzFile gzf, std::multiset<_valueT, _Compare, _Alloc> & l)
493 {
494 return(ContainerRead<std::multiset<_valueT, _Compare, _Alloc> >(gzf, l));
495 }
496
497 //------------------------------------------------------------------------
500 //------------------------------------------------------------------------
501 template <typename _valueT, typename _Compare, typename _Alloc>
502 static int
503 Write(gzFile gzf, const std::multiset<_valueT, _Compare, _Alloc> & l)
504 {
505 return(ContainerWrite<std::multiset<_valueT, _Compare, _Alloc> >(gzf, l));
506 }
507
508 //------------------------------------------------------------------------
512 //------------------------------------------------------------------------
513 static int Read(gzFile gzf, std::monostate & sm)
514 {
515 return 0;
516 }
517
518 //------------------------------------------------------------------------
522 //------------------------------------------------------------------------
523 static int Write(gzFile gzf, const std::monostate & sm)
524 {
525 return 0;
526 }
527
528 //------------------------------------------------------------------------
531 //------------------------------------------------------------------------
532 template <typename... Ts>
533 static int Read(gzFile gzf, std::variant<Ts...> & v)
534 {
535 int rc = -1;
536 uint64_t index = 0;
537 int bytesRead = Read(gzf, index);
538 if (bytesRead > 0) {
539 rc = bytesRead;
540 if (index < std::variant_size_v<std::variant<Ts...>>) {
541 v = VariantFromIndex<Ts...>(index);
542 std::visit([&] (auto && arg) { rc = Read(gzf, arg); }, v);
543 if (bytesRead >= 0) {
544 rc += bytesRead;
545 }
546 else {
547 rc = -1;
548 }
549 }
550 }
551 return rc;
552 }
553
554 //------------------------------------------------------------------------
557 //------------------------------------------------------------------------
558 template <typename... Ts>
559 static int Write(gzFile gzf, const std::variant<Ts...> & v)
560 {
561 int rc = -1;
562 uint64_t index = v.index();
563 int bytesWritten = Write(gzf, index);
564 if (bytesWritten > 0) {
565 rc = bytesWritten;
566 std::visit([&] (const auto & arg)
567 { bytesWritten = Write(gzf, arg); }, v);
568 if (bytesWritten >= 0) {
569 rc += bytesWritten;
570 }
571 else {
572 rc = -1;
573 }
574 }
575 return rc;
576 }
577
578 //------------------------------------------------------------------------
581 //------------------------------------------------------------------------
582 template <typename... Args>
583 static int Read(gzFile gzf, std::tuple<Args...> & t)
584 {
585 return(std::apply([&gzf](auto&&...args)
586 {
587 int rc = 0;
588 auto read_tuple_mem = [&gzf,&rc](auto&& x) {
589 int bytesRead = Read(gzf, x);
590 if (bytesRead > 0) { rc += bytesRead; return true; }
591 else { return false; }
592 };
593 if ((read_tuple_mem(args) && ...)) {
594 return rc;
595 }
596 else {
597 return -1;
598 }
599 }, t));
600 }
601
602 //------------------------------------------------------------------------
605 //------------------------------------------------------------------------
606 template <typename... Args>
607 static int Write(gzFile gzf, const std::tuple<Args...> & t)
608 {
609 return(std::apply([&gzf](auto&&...args)
610 {
611 int rc = 0;
612 auto read_tuple_mem = [&gzf,&rc](auto&& x) {
613 int bytesWritten = Write(gzf, x);
614 if (bytesWritten > 0) { rc += bytesWritten; return true; }
615 else { return false; }
616 };
617 if ((read_tuple_mem(args) && ...)) {
618 return rc;
619 }
620 else {
621 return -1;
622 }
623 }, t));
624 }
625
626 //------------------------------------------------------------------------
629 //------------------------------------------------------------------------
630 template<typename _keyT, typename _valueT, typename _Hash,
631 typename _Pred, typename _Alloc>
632 static int
633 Read(gzFile gzf, std::unordered_map<_keyT,_valueT,_Hash,_Pred,_Alloc> & hm)
634 {
635 return(PairAssocContRead<std::unordered_map<_keyT,_valueT,_Hash,_Pred,_Alloc> >(gzf, hm));
636 }
637
638 //------------------------------------------------------------------------
641 //------------------------------------------------------------------------
642 template<typename _keyT, typename _valueT, typename _Hash,
643 typename _Pred, typename _Alloc>
644 static int
645 Write(gzFile gzf,
646 const std::unordered_map<_keyT,_valueT,_Hash,_Pred,_Alloc> & hm)
647 {
648 return(ContainerWrite<std::unordered_map<_keyT,_valueT,_Hash,_Pred,_Alloc> >(gzf, hm));
649 }
650
651 //------------------------------------------------------------------------
654 //------------------------------------------------------------------------
655 template<typename _valueT, typename _Hash,
656 typename _Pred, typename _Alloc>
657 static int
658 Read(gzFile gzf, std::unordered_set<_valueT,_Hash,_Pred,_Alloc> & hm)
659 {
660 return(ContainerRead<std::unordered_set<_valueT,_Hash,_Pred,_Alloc> >(gzf, hm));
661 }
662
663 //------------------------------------------------------------------------
666 //------------------------------------------------------------------------
667 template<typename _valueT, typename _Hash,
668 typename _Pred, typename _Alloc>
669 static int
670 Write(gzFile gzf,
671 const std::unordered_set<_valueT,_Hash,_Pred,_Alloc> & hm)
672 {
673 return(ContainerWrite<std::unordered_set<_valueT,_Hash,_Pred,_Alloc> >(gzf, hm));
674 }
675
676 //------------------------------------------------------------------------
679 //------------------------------------------------------------------------
680 template<typename _keyT, typename _valueT, typename _Hash,
681 typename _Pred, typename _Alloc>
682 static int
683 Read(gzFile gzf, std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc> & hm)
684 {
685 return(PairAssocContRead<std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc> >(gzf, hm));
686 }
687
688 //------------------------------------------------------------------------
691 //------------------------------------------------------------------------
692 template<typename _keyT, typename _valueT, typename _Hash,
693 typename _Pred, typename _Alloc>
694 static int
695 Write(gzFile gzf,
696 const std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc> & hm)
697 {
698 return(ContainerWrite<std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc> >(gzf, hm));
699 }
700
701 //------------------------------------------------------------------------
704 //------------------------------------------------------------------------
705 template<typename _valueT, typename _Hash,
706 typename _Pred, typename _Alloc>
707 static int
708 Read(gzFile gzf, std::unordered_multiset<_valueT,_Hash,_Pred,_Alloc> & hm)
709 {
710 return(ContainerRead<std::unordered_multiset<_valueT,_Hash,_Pred,_Alloc> >(gzf, hm));
711 }
712
713 //------------------------------------------------------------------------
716 //------------------------------------------------------------------------
717 template<typename _valueT, typename _Hash,
718 typename _Pred, typename _Alloc>
719 static int
720 Write(gzFile gzf,
721 const std::unordered_multiset<_valueT,_Hash,_Pred,_Alloc> & hm)
722 {
723 return(ContainerWrite<std::unordered_multiset<_valueT,_Hash,_Pred,_Alloc> >(gzf, hm));
724 }
725
726 //------------------------------------------------------------------------
729 //------------------------------------------------------------------------
730 template <typename ...Args>
731 static int ReadV(gzFile gzf, Args & ...args)
732 {
733 int rv = 0;
734 auto readOne = [&] (auto & arg) {
735 bool rc = true;
736 int bytesRead = Read(gzf, arg);
737 if (bytesRead > 0) {
738 rv += bytesRead;
739 }
740 else {
741 rv = -1;
742 rc = false;
743 }
744 return rc;
745 };
746 (readOne(args) && ...);
747 return rv;
748 }
749
750 //------------------------------------------------------------------------
753 //------------------------------------------------------------------------
754 template <typename ...Args>
755 static int WriteV(gzFile gzf, const Args & ...args)
756 {
757 ssize_t rv = 0;
758 auto writeOne = [&] (auto & arg) {
759 bool rc = true;
760 int bytesWritten = Write(gzf, arg);
761 if (bytesWritten > 0) {
762 rv += bytesWritten;
763 }
764 else {
765 rv = -1;
766 rc = false;
767 }
768 return rc;
769 };
770 (writeOne(args) && ...);
771 return rv;
772 }
773
774 private:
775 //------------------------------------------------------------------------
777 //------------------------------------------------------------------------
778 template <typename _inputIteratorT>
779 static int Write(gzFile gzf, _inputIteratorT f, _inputIteratorT l)
780 {
781 int rc = 0;
782 if (gzf) {
783 for ( ; f != l; ++f) {
784 int bytesWritten = Write(gzf, *f);
785 if (bytesWritten > 0) {
786 rc += bytesWritten;
787 }
788 else {
789 rc = -1;
790 break;
791 }
792 }
793 }
794 return(rc);
795 }
796
797 //------------------------------------------------------------------------
801 //------------------------------------------------------------------------
802 template <typename _containerT>
803 static int ContainerRead(gzFile gzf, _containerT & c)
804 {
805 if (! c.empty())
806 c.clear();
807 int rc = -1;
808 if (gzf) {
809 uint64_t numEntries;
810 int bytesRead = Read(gzf, numEntries);
811 if (bytesRead == sizeof(numEntries)) {
812 rc = bytesRead;
813 for (uint64_t i = 0; i < numEntries; ++i) {
814 typename _containerT::value_type val;
815 bytesRead = Read(gzf, val);
816 if (bytesRead > 0) {
817 rc += bytesRead;
818 c.insert(c.end(), std::move(val));
819 }
820 else {
821 rc = -1;
822 break;
823 }
824 }
825 }
826 }
827 return(rc);
828 }
829
830 //------------------------------------------------------------------------
834 //------------------------------------------------------------------------
835 template <typename _containerT>
836 static int ContainerWrite(gzFile gzf, const _containerT & c)
837 {
838 int rc = -1;
839 if (gzf) {
840 uint64_t numEntries = c.size();
841 uint64_t bytesWritten = Write(gzf, numEntries);
842 if (bytesWritten == sizeof(numEntries)) {
843 rc = bytesWritten;
844 if (numEntries) {
845 bytesWritten =
847 c.begin(),
848 c.end());
849 if (bytesWritten > 0) {
850 rc += bytesWritten;
851 }
852 else {
853 rc = -1;
854 }
855 }
856 }
857 }
858 return(rc);
859 }
860
861 //------------------------------------------------------------------------
865 //------------------------------------------------------------------------
866 template <typename _containerT>
867 static int PairAssocContRead(gzFile gzf, _containerT & m)
868 {
869 int rc = -1;
870 if (! m.empty())
871 m.clear();
872 if (gzf) {
873 uint64_t numEntries;
874 int bytesRead = Read(gzf, numEntries);
875 if (bytesRead == sizeof(numEntries)) {
876 rc = bytesRead;
877 for (uint64_t i = 0; i < numEntries; ++i) {
878 typename _containerT::key_type key;
879 bytesRead = Read(gzf, key);
880 if (bytesRead > 0) {
881 rc += bytesRead;
882 typename _containerT::mapped_type val;
883 bytesRead = Read(gzf, val);
884 if (bytesRead > 0) {
885 rc += bytesRead;
886 m.insert(typename _containerT::value_type(std::move(key),
887 std::move(val)));
888 }
889 else {
890 rc = -1;
891 break;
892 }
893 }
894 else {
895 rc = -1;
896 break;
897 }
898 }
899 }
900 }
901 return(rc);
902 }
903
904 };
905
906} // namespace Dwm
907
908#endif // _DWMGZIO_HH_
909
910//---------------------------- emacs settings -----------------------------
911// Local Variables:
912// mode: C++
913// tab-width: 2
914// indent-tabs-mode: nil
915// c-basic-offset: 2
916// End:
917//-------------------------------------------------------------------------
Dwm::HasGZRead and Dwm::HasGZWrite concepts. Dwm::GZReadable, Dwm::GZWritable and Dwm::GZIOCapable pu...
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 DwmGZIO.hh:85
static int Read(gzFile gzf, std::string &s)
Reads s from gzf.
static int Write(gzFile gzf, const double &val)
Writes val tp gzf, in IEEE format (see RFC 1832 and/or ANSI/IEEE Standard 754-1985).
static int Read(gzFile gzf, std::tuple< Args... > &t)
Reads a tuple from a gzFile.
Definition DwmGZIO.hh:583
static int Write(gzFile gzf, const std::unordered_multimap< _keyT, _valueT, _Hash, _Pred, _Alloc > &hm)
Writes an unordered_multimap to a gzFile.
Definition DwmGZIO.hh:695
static int Write(gzFile gzf, uint16_t val)
Writes val to gzf, in network byte order (MSB first).
static int ReadV(gzFile gzf, Args &...args)
Reads args from gzf.
Definition DwmGZIO.hh:731
static int Read(gzFile gzf, GZReadable &val)
Wrapper function to read a GZReadable object from a gzFile.
Definition DwmGZIO.hh:249
static int Read(gzFile gzf, std::multimap< _keyT, _valueT, _Compare, _Alloc > &m)
Reads a multimap<_keyT,_valueT> from a gzFile.
Definition DwmGZIO.hh:348
static int Write(gzFile gzf, char c)
Writes c to gzf.
static int Read(gzFile gzf, int16_t &val)
Reads val from gzf, in network byte order (MSB first).
static int Write(gzFile gzf, const int64_t &val)
Writes val to gzf, in network byte order (MSB first).
static int Read(gzFile gzf, double &val)
Reads val from gzf, in IEEE format (see RFC 1832 and/or ANSI/IEEE Standard 754-1985).
static int Read(gzFile gzf, bool &b)
Reads b from gzf.
static int Read(gzFile gzf, int32_t &val)
Reads val from gzf, in network byte order (MSB first).
static int Read(gzFile gzf, std::deque< _valueT, _Alloc > &d)
Reads a deque<_valueT> from a gzFile.
Definition DwmGZIO.hh:432
static int Read(gzFile gzf, std::vector< _valueT, _Alloc > &v)
Reads a vector<_valueT> from a gzFile.
Definition DwmGZIO.hh:412
static int Read(gzFile gzf, uint32_t &val)
Reads val from gzf, in network byte order (MSB first).
static int Read(gzFile gzf, HasGZRead auto &val)
Reads val from gzf, where val meets the requirements of the HasGZRead concept.
Definition DwmGZIO.hh:256
static int Read(gzFile gzf, float &val)
Reads val from gzf, in IEEE format (see RFC 1832 and/or ANSI/IEEE Standard 754-1985).
static int Write(gzFile gzf, const std::array< _valueT, N > &a)
Writes an array<_valueT,N> to a gzFile.
Definition DwmGZIO.hh:391
static int Read(gzFile gzf, std::multiset< _valueT, _Compare, _Alloc > &l)
Reads a multiset<_valueT> from a gzFile.
Definition DwmGZIO.hh:492
static int Read(gzFile gzf, std::set< _valueT, _Compare, _Alloc > &l)
Reads a set<_valueT> from a gzFile.
Definition DwmGZIO.hh:472
static int Write(gzFile gzf, bool b)
Writes b to gzf.
static int Read(gzFile gzf, std::monostate &sm)
Just a dummy helper function for std::variant instances that hold a std::monostate.
Definition DwmGZIO.hh:513
static int Read(gzFile gzf, std::variant< Ts... > &v)
Reads a variant from a gzFile.
Definition DwmGZIO.hh:533
static int Write(gzFile gzf, const uint64_t &val)
Writes val to gzf, in network byte order (MSB first).
static int Write(gzFile gzf, const GZWritable &val)
Wrapper function to write a GZWritable object to a gzFile.
Definition DwmGZIO.hh:262
static int Write(gzFile gzf, const std::vector< _valueT, _Alloc > &v)
Writes a vector<_valueT> to a gzFile.
Definition DwmGZIO.hh:422
static int Read(gzFile gzf, std::unordered_set< _valueT, _Hash, _Pred, _Alloc > &hm)
Reads an unordered_set from a gzFile.
Definition DwmGZIO.hh:658
static int Write(gzFile gzf, uint8_t c)
Writes c to gzf.
static int Write(gzFile gzf, const std::list< _valueT, _Alloc > &l)
Writes a list<_valueT> to a gzFile.
Definition DwmGZIO.hh:462
static int Write(gzFile gzf, const std::unordered_map< _keyT, _valueT, _Hash, _Pred, _Alloc > &hm)
Writes an unordered_map to a gzFile.
Definition DwmGZIO.hh:645
static int Write(gzFile gzf, const std::map< _keyT, _valueT, _Compare, _Alloc > &m)
Writes a map<_keyT,_valueT> to a gzFile.
Definition DwmGZIO.hh:336
static int Read(gzFile gzf, std::map< _keyT, _valueT, _Compare, _Alloc > &m)
Reads a map<_keyT,_valueT> from a gzFile.
Definition DwmGZIO.hh:324
static int Read(gzFile gzf, std::unordered_multimap< _keyT, _valueT, _Hash, _Pred, _Alloc > &hm)
Reads an unordered_multimap from a gzFile.
Definition DwmGZIO.hh:683
static int Read(gzFile gzf, std::list< _valueT, _Alloc > &l)
Reads a list<_valueT> from a gzFile.
Definition DwmGZIO.hh:452
static int Read(gzFile gzf, std::array< _valueT, N > &a)
Reads an array<_valueT,N> from a gzFile.
Definition DwmGZIO.hh:370
static int Read(gzFile gzf, uint8_t &c)
Reads c from gzf.
static int Write(gzFile gzf, const std::monostate &sm)
Just a dummy helper function for std::variant instances that hold a std::monostate.
Definition DwmGZIO.hh:523
static int Write(gzFile gzf, const std::variant< Ts... > &v)
Writes a variant to a gzFile.
Definition DwmGZIO.hh:559
static int Read(gzFile gzf, int64_t &val)
Reads val from gzf, in network byte order (MSB first).
static int Write(gzFile gzf, const std::multimap< _keyT, _valueT, _Compare, _Alloc > &m)
Writes a multimap<_keyT,_valueT> to a gzFile.
Definition DwmGZIO.hh:360
static int Write(gzFile gzf, const HasGZWrite auto &val)
Writes val to gzf, where val meets the requirements of the HasGZWrite concept.
Definition DwmGZIO.hh:269
static int Write(gzFile gzf, const std::tuple< Args... > &t)
Writes a tuple to a gzFile.
Definition DwmGZIO.hh:607
static int Write(gzFile gzf, int16_t val)
Writes val to gzf, in network byte order (MSB first).
static int Write(gzFile gzf, const std::unordered_set< _valueT, _Hash, _Pred, _Alloc > &hm)
Writes an unordered_set to a gzFile.
Definition DwmGZIO.hh:670
static int Write(gzFile gzf, const std::string &s)
Writes s to gzf.
static int Read(gzFile gzf, uint16_t &val)
Reads val from gzf, in network byte order (MSB first).
static int Write(gzFile gzf, const std::unordered_multiset< _valueT, _Hash, _Pred, _Alloc > &hm)
Writes an unordered_multiset to a gzFile.
Definition DwmGZIO.hh:720
static int Write(gzFile gzf, const std::multiset< _valueT, _Compare, _Alloc > &l)
Writes a multiset<_valueT> to a gzFile.
Definition DwmGZIO.hh:503
static int Write(gzFile gzf, const std::pair< _firstT, _secondT > &p)
Writes a pair<_firstT,_secondT> to a gzFile.
Definition DwmGZIO.hh:299
static int Write(gzFile gzf, const std::set< _valueT, _Compare, _Alloc > &l)
Writes a set<_valueT> to a gzFile.
Definition DwmGZIO.hh:482
static int Read(gzFile gzf, uint64_t &val)
Reads val from gzf, in network byte order (MSB first).
static int WriteV(gzFile gzf, const Args &...args)
Writes args to gzf.
Definition DwmGZIO.hh:755
static int Write(gzFile gzf, uint32_t val)
Writes val to gzf, in network byte order (MSB first).
static int Read(gzFile gzf, std::unordered_multiset< _valueT, _Hash, _Pred, _Alloc > &hm)
Reads an unordered_multiset from a gzFile.
Definition DwmGZIO.hh:708
static int Read(gzFile gzf, char &c)
Reads from gzf.
static int Read(gzFile gzf, std::unordered_map< _keyT, _valueT, _Hash, _Pred, _Alloc > &hm)
Reads an unordered_map from a gzFile.
Definition DwmGZIO.hh:633
static int Write(gzFile gzf, const std::deque< _valueT, _Alloc > &d)
Writes a deque<_valueT> to a gzFile.
Definition DwmGZIO.hh:442
static int Write(gzFile gzf, int32_t val)
Writes val to gzf, in network byte order (MSB first).
static int Write(gzFile gzf, float val)
Writes val tp gzf, in IEEE format (see RFC 1832 and/or ANSI/IEEE Standard 754-1985).
static int Read(gzFile gzf, std::pair< _firstT, _secondT > &p)
Reads a pair<_firstT,_secondT> from a gzFile.
Definition DwmGZIO.hh:277
This class is a pure virtual class, defining an interface for classes that can read their contents fr...
Definition DwmGZIOCapable.hh:78
virtual int Read(gzFile gzf)=0
Read from a gzFile.
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition DwmGZIOCapable.hh:97
virtual int Write(gzFile gzf) const =0
Write to a gzFile.
T has a Read(gzFile) member that returns int (return value of gzread() on success,...
Definition DwmGZIOCapable.hh:60
T has a Write(gzFile) const member that returns int (return value of gzwrite() on success,...
Definition DwmGZIOCapable.hh:69