libDwm-0.6.0
DwmIO.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/libDwm/tags/libDwm-0.6.0/include/DwmIO.hh 8995 $
3 // @(#) $Id: DwmIO.hh 8995 2017-04-10 05:21:11Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2004, 2005, 2006, 2007, 2016
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // 1. Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // 2. Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // 3. The names of the authors and copyright holders may not be used to
18 // endorse or promote products derived from this software without
19 // specific prior written permission.
20 //
21 // IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
22 // DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
23 // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
24 // EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
25 // DAMAGE.
26 //
27 // THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
28 // DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
29 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
30 // REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
31 // IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
33 // PURPOSE, OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
34 // TRADEMARK OR OTHER RIGHTS.
35 //===========================================================================
36 
37 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 
42 #ifndef _DWMIO_HH_
43 #define _DWMIO_HH_
44 
45 extern "C" {
46  #include <inttypes.h>
47  #include <sys/types.h>
48 }
49 
50 #include <cstdio>
51 #include <deque>
52 #include <iostream>
53 #include <list>
54 #include <map>
55 #include <set>
56 #include <string>
57 #include <tuple>
58 #include <unordered_map>
59 #include <unordered_set>
60 #include <vector>
61 
62 #include "DwmPortability.hh"
63 
64 #include "DwmReadable.hh"
65 #include "DwmWritable.hh"
66 
67 namespace Dwm {
68 
69  //--------------------------------------------------------------------------
84  //--------------------------------------------------------------------------
85  class IO
86  {
87  public:
88  //------------------------------------------------------------------------
91  //------------------------------------------------------------------------
92  static uint32_t StreamedLength(char c)
93  {
94  return(sizeof(c));
95  }
96 
97  //------------------------------------------------------------------------
99  //------------------------------------------------------------------------
100  static std::ostream & Write(std::ostream & os, char c);
101 
102  //------------------------------------------------------------------------
105  //------------------------------------------------------------------------
106  static uint32_t StreamedLength(uint8_t c)
107  {
108  return(sizeof(c));
109  }
110 
111  //------------------------------------------------------------------------
113  //------------------------------------------------------------------------
114  static std::ostream & Write(std::ostream & os, uint8_t c);
115 
116  //------------------------------------------------------------------------
119  //------------------------------------------------------------------------
120  static uint32_t StreamedLength(bool b)
121  {
122  return(1);
123  }
124 
125  //------------------------------------------------------------------------
127  //------------------------------------------------------------------------
128  static std::ostream & Write(std::ostream & os, bool b);
129 
130  //------------------------------------------------------------------------
133  //------------------------------------------------------------------------
134  static uint32_t StreamedLength(int16_t val)
135  {
136  return(sizeof(val));
137  }
138 
139  //------------------------------------------------------------------------
142  //------------------------------------------------------------------------
143  static std::ostream & Write(std::ostream & os, int16_t val);
144 
145  //------------------------------------------------------------------------
148  //------------------------------------------------------------------------
149  static uint32_t StreamedLength(uint16_t val)
150  {
151  return(sizeof(val));
152  }
153 
154  //------------------------------------------------------------------------
157  //------------------------------------------------------------------------
158  static std::ostream & Write(std::ostream & os, uint16_t val);
159 
160  //------------------------------------------------------------------------
163  //------------------------------------------------------------------------
164  static uint32_t StreamedLength(int32_t val)
165  {
166  return(sizeof(val));
167  }
168 
169  //------------------------------------------------------------------------
172  //------------------------------------------------------------------------
173  static std::ostream & Write(std::ostream & os, int32_t val);
174 
175  //------------------------------------------------------------------------
178  //------------------------------------------------------------------------
179  static uint32_t StreamedLength(uint32_t val)
180  {
181  return(sizeof(val));
182  }
183 
184  //------------------------------------------------------------------------
187  //------------------------------------------------------------------------
188  static std::ostream & Write(std::ostream & os, uint32_t val);
189 
190  //------------------------------------------------------------------------
193  //------------------------------------------------------------------------
194  static uint32_t StreamedLength(int64_t val)
195  {
196  return(sizeof(val));
197  }
198 
199  //------------------------------------------------------------------------
202  //------------------------------------------------------------------------
203  static std::ostream & Write(std::ostream & os, const int64_t & val);
204 
205  //------------------------------------------------------------------------
208  //------------------------------------------------------------------------
209  static uint32_t StreamedLength(uint64_t val)
210  {
211  return(sizeof(val));
212  }
213 
214  //------------------------------------------------------------------------
217  //------------------------------------------------------------------------
218  static std::ostream & Write(std::ostream & os, const uint64_t & val);
219 
220  //------------------------------------------------------------------------
223  //------------------------------------------------------------------------
224  static uint32_t StreamedLength(float val)
225  {
226  return(4);
227  }
228 
229  //------------------------------------------------------------------------
232  //------------------------------------------------------------------------
233  static std::ostream & Write(std::ostream & os, float val);
234 
235  //------------------------------------------------------------------------
238  //------------------------------------------------------------------------
239  static uint32_t StreamedLength(double val)
240  {
241  return(8);
242  }
243 
244  //------------------------------------------------------------------------
247  //------------------------------------------------------------------------
248  static std::ostream & Write(std::ostream & os, const double & val);
249 
250  //------------------------------------------------------------------------
253  //------------------------------------------------------------------------
254  static uint32_t StreamedLength(const std::string & s)
255  {
256  return(sizeof(uint32_t) + s.size());
257  }
258 
259  //------------------------------------------------------------------------
265  //------------------------------------------------------------------------
266  static std::ostream & Write(std::ostream & os, const std::string & s);
267 
268  //------------------------------------------------------------------------
270  //------------------------------------------------------------------------
271  static std::istream & Read(std::istream & is, char & c);
272 
273  //------------------------------------------------------------------------
275  //------------------------------------------------------------------------
276  static std::istream & Read(std::istream & is, uint8_t & c);
277 
278  //------------------------------------------------------------------------
280  //------------------------------------------------------------------------
281  static std::istream & Read(std::istream & is, bool & b);
282 
283  //------------------------------------------------------------------------
286  //------------------------------------------------------------------------
287  static std::istream & Read(std::istream & is, int16_t & val);
288 
289  //------------------------------------------------------------------------
292  //------------------------------------------------------------------------
293  static std::istream & Read(std::istream & is, uint16_t & val);
294 
295  //------------------------------------------------------------------------
298  //------------------------------------------------------------------------
299  static std::istream & Read(std::istream & is, int32_t & val);
300 
301  //------------------------------------------------------------------------
304  //------------------------------------------------------------------------
305  static std::istream & Read(std::istream & is, uint32_t & val);
306 
307  //------------------------------------------------------------------------
310  //------------------------------------------------------------------------
311  static std::istream & Read(std::istream & is, int64_t & val);
312 
313  //------------------------------------------------------------------------
316  //------------------------------------------------------------------------
317  static std::istream & Read(std::istream & is, uint64_t & val);
318 
319  //------------------------------------------------------------------------
322  //------------------------------------------------------------------------
323  static std::istream & Read(std::istream & is, float & val);
324 
325  //------------------------------------------------------------------------
328  //------------------------------------------------------------------------
329  static std::istream & Read(std::istream & is, double & val);
330 
331  //------------------------------------------------------------------------
335  //------------------------------------------------------------------------
336  static std::istream & Read(std::istream & is, std::string & s);
337 
338  //------------------------------------------------------------------------
341  //------------------------------------------------------------------------
342  static ssize_t Write(int fd, char c);
343 
344  //------------------------------------------------------------------------
347  //------------------------------------------------------------------------
348  static ssize_t Write(int fd, uint8_t c);
349 
350  //------------------------------------------------------------------------
353  //------------------------------------------------------------------------
354  static ssize_t Write(int fd, bool b);
355 
356  //------------------------------------------------------------------------
360  //------------------------------------------------------------------------
361  static ssize_t Write(int fd, int16_t val);
362 
363  //------------------------------------------------------------------------
367  //------------------------------------------------------------------------
368  static ssize_t Write(int fd, uint16_t val);
369 
370  //------------------------------------------------------------------------
374  //------------------------------------------------------------------------
375  static ssize_t Write(int fd, int32_t val);
376 
377  //------------------------------------------------------------------------
381  //------------------------------------------------------------------------
382  static ssize_t Write(int fd, uint32_t val);
383 
384  //------------------------------------------------------------------------
388  //------------------------------------------------------------------------
389  static ssize_t Write(int fd, const int64_t & val);
390 
391  //------------------------------------------------------------------------
395  //------------------------------------------------------------------------
396  static ssize_t Write(int fd, const uint64_t & val);
397 
398  //------------------------------------------------------------------------
402  //------------------------------------------------------------------------
403  static ssize_t Write(int fd, float val);
404 
405  //------------------------------------------------------------------------
409  //------------------------------------------------------------------------
410  static ssize_t Write(int fd, const double & val);
411 
412  //------------------------------------------------------------------------
418  //------------------------------------------------------------------------
419  static ssize_t Write(int fd, const std::string & s);
420 
421  //------------------------------------------------------------------------
424  //------------------------------------------------------------------------
425  static ssize_t Read(int fd, char & c);
426 
427  //------------------------------------------------------------------------
430  //------------------------------------------------------------------------
431  static ssize_t Read(int fd, uint8_t & c);
432 
433  //------------------------------------------------------------------------
436  //------------------------------------------------------------------------
437  static ssize_t Read(int fd, bool & b);
438 
439  //------------------------------------------------------------------------
442  //------------------------------------------------------------------------
443  static ssize_t Read(int fd, int16_t & val);
444 
445  //------------------------------------------------------------------------
448  //------------------------------------------------------------------------
449  static ssize_t Read(int fd, uint16_t & val);
450 
451  //------------------------------------------------------------------------
454  //------------------------------------------------------------------------
455  static ssize_t Read(int fd, int32_t & val);
456 
457  //------------------------------------------------------------------------
460  //------------------------------------------------------------------------
461  static ssize_t Read(int fd, uint32_t & val);
462 
463  //------------------------------------------------------------------------
466  //------------------------------------------------------------------------
467  static ssize_t Read(int fd, int64_t & val);
468 
469  //------------------------------------------------------------------------
472  //------------------------------------------------------------------------
473  static ssize_t Read(int fd, uint64_t & val);
474 
475  //------------------------------------------------------------------------
479  //------------------------------------------------------------------------
480  static ssize_t Read(int fd, float & val);
481 
482  //------------------------------------------------------------------------
486  //------------------------------------------------------------------------
487  static ssize_t Read(int fd, double & val);
488 
489  //------------------------------------------------------------------------
494  //------------------------------------------------------------------------
495  static ssize_t Read(int fd, std::string & s);
496 
497  //------------------------------------------------------------------------
500  //------------------------------------------------------------------------
501  static size_t Write(FILE * f, char c);
502 
503  //------------------------------------------------------------------------
506  //------------------------------------------------------------------------
507  static size_t Write(FILE * f, uint8_t c);
508 
509  //------------------------------------------------------------------------
512  //------------------------------------------------------------------------
513  static size_t Write(FILE * f, bool b);
514 
515  //------------------------------------------------------------------------
518  //------------------------------------------------------------------------
519  static size_t Write(FILE * f, int16_t val);
520 
521  //------------------------------------------------------------------------
524  //------------------------------------------------------------------------
525  static size_t Write(FILE * f, uint16_t val);
526 
527  //------------------------------------------------------------------------
530  //------------------------------------------------------------------------
531  static size_t Write(FILE * f, int32_t val);
532 
533  //------------------------------------------------------------------------
536  //------------------------------------------------------------------------
537  static size_t Write(FILE * f, uint32_t val);
538 
539  //------------------------------------------------------------------------
542  //------------------------------------------------------------------------
543  static size_t Write(FILE * f, const int64_t & val);
544 
545  //------------------------------------------------------------------------
548  //------------------------------------------------------------------------
549  static size_t Write(FILE * f, const uint64_t & val);
550 
551  //------------------------------------------------------------------------
555  //------------------------------------------------------------------------
556  static size_t Write(FILE * f, float val);
557 
558  //------------------------------------------------------------------------
562  //------------------------------------------------------------------------
563  static size_t Write(FILE * f, const double & val);
564 
565  //------------------------------------------------------------------------
570  //------------------------------------------------------------------------
571  static size_t Write(FILE * f, const std::string & s);
572 
573  //------------------------------------------------------------------------
576  //------------------------------------------------------------------------
577  static size_t Read(FILE * f, char & c);
578 
579  //------------------------------------------------------------------------
582  //------------------------------------------------------------------------
583  static size_t Read(FILE * f, uint8_t & c);
584 
585  //------------------------------------------------------------------------
588  //------------------------------------------------------------------------
589  static size_t Read(FILE * f, bool & b);
590 
591  //------------------------------------------------------------------------
594  //------------------------------------------------------------------------
595  static size_t Read(FILE * f, int16_t & val);
596 
597  //------------------------------------------------------------------------
600  //------------------------------------------------------------------------
601  static size_t Read(FILE * f, uint16_t & val);
602 
603  //------------------------------------------------------------------------
606  //------------------------------------------------------------------------
607  static size_t Read(FILE * f, int32_t & val);
608 
609  //------------------------------------------------------------------------
612  //------------------------------------------------------------------------
613  static size_t Read(FILE * f, uint32_t & val);
614 
615  //------------------------------------------------------------------------
618  //------------------------------------------------------------------------
619  static size_t Read(FILE * f, int64_t & val);
620 
621  //------------------------------------------------------------------------
624  //------------------------------------------------------------------------
625  static size_t Read(FILE * f, uint64_t & val);
626 
627  //------------------------------------------------------------------------
631  //------------------------------------------------------------------------
632  static size_t Read(FILE * f, float & val);
633 
634  //------------------------------------------------------------------------
638  //------------------------------------------------------------------------
639  static size_t Read(FILE * f, double & val);
640 
641  //------------------------------------------------------------------------
645  //------------------------------------------------------------------------
646  static size_t Read(FILE * f, std::string & s);
647 
648  //------------------------------------------------------------------------
651  //------------------------------------------------------------------------
652  static uint32_t StreamedLength(const Writable & val)
653  {
654  return(val.StreamedLength());
655  }
656 
657  //------------------------------------------------------------------------
659  //------------------------------------------------------------------------
660  static std::ostream & Write(std::ostream & os, const Writable & val)
661  {
662  return(val.Write(os));
663  }
664 
665  //------------------------------------------------------------------------
667  //------------------------------------------------------------------------
668  static ssize_t Write(int fd, const Writable & val)
669  {
670  return(val.Write(fd));
671  }
672 
673  //------------------------------------------------------------------------
675  //------------------------------------------------------------------------
676  static size_t Write(FILE * f, const Writable & val)
677  {
678  return(val.Write(f));
679  }
680 
681  //------------------------------------------------------------------------
683  //------------------------------------------------------------------------
684  static std::istream & Read(std::istream & is, Readable & val)
685  {
686  return(val.Read(is));
687  }
688 
689  //------------------------------------------------------------------------
691  //------------------------------------------------------------------------
692  static ssize_t Read(int fd, Readable & val)
693  {
694  return(val.Read(fd));
695  }
696 
697  //------------------------------------------------------------------------
699  //------------------------------------------------------------------------
700  static size_t Read(FILE *f, Readable & val)
701  {
702  return(val.Read(f));
703  }
704 
705  //------------------------------------------------------------------------
708  //------------------------------------------------------------------------
709  template <typename _firstT, typename _secondT>
710  static uint32_t StreamedLength(const std::pair<_firstT, _secondT> & p)
711  {
712  return(StreamedLength(p.first) + StreamedLength(p.second));
713  }
714 
715  //------------------------------------------------------------------------
717  //------------------------------------------------------------------------
718  template <typename _firstT, typename _secondT>
719  static std::istream & Read(std::istream & is,
720  std::pair<_firstT, _secondT> & p)
721  {
722  if (is) {
723  if (Read(is, p.first))
724  Read(is, p.second);
725  }
726  return(is);
727  }
728 
729  //------------------------------------------------------------------------
731  //------------------------------------------------------------------------
732  template <typename _firstT, typename _secondT>
733  static std::ostream & Write(std::ostream & os,
734  const std::pair<_firstT,_secondT> & p)
735  {
736  if (os) {
737  if (Write(os, p.first)) {
738  Write(os, p.second);
739  }
740  }
741  return(os);
742  }
743 
744  //------------------------------------------------------------------------
747  //------------------------------------------------------------------------
748  template <typename _firstT, typename _secondT>
749  static size_t Read(FILE *f, std::pair<_firstT,_secondT> & p)
750  {
751  size_t rc = 0;
752  if (f)
753  if (Read(f, p.first) > 0)
754  if (Read(f, p.second) > 0)
755  rc = 1;
756  return(rc);
757  }
758 
759  //------------------------------------------------------------------------
762  //------------------------------------------------------------------------
763  template <typename _firstT, typename _secondT>
764  static size_t Write(FILE *f, const std::pair<_firstT,_secondT> & p)
765  {
766  size_t rc = 0;
767  if (f)
768  if (Write(f, p.first) > 0)
769  if (Write(f, p.second) > 0)
770  rc = 1;
771  return(rc);
772  }
773 
774  //------------------------------------------------------------------------
777  //------------------------------------------------------------------------
778  template <typename _firstT, typename _secondT>
779  static ssize_t Read(int fd, std::pair<_firstT, _secondT> & p)
780  {
781  ssize_t rc = -1;
782  if (fd >= 0) {
783  ssize_t bytesRead = Read(fd, p.first);
784  if (bytesRead > 0) {
785  rc = bytesRead;
786  bytesRead = Read(fd, p.second);
787  if (bytesRead > 0)
788  rc += bytesRead;
789  else
790  rc = -1;
791  }
792  }
793  return(rc);
794  }
795 
796  //------------------------------------------------------------------------
799  //------------------------------------------------------------------------
800  template <typename _firstT, typename _secondT>
801  static ssize_t Write(int fd, const std::pair<_firstT,_secondT> & p)
802  {
803  ssize_t rc = -1;
804  if (fd >= 0) {
805  ssize_t bytesWritten = Write(fd, p.first);
806  if (bytesWritten > 0) {
807  rc = bytesWritten;
808  bytesWritten = Write(fd, p.second);
809  if (bytesWritten > 0) {
810  rc += bytesWritten;
811  }
812  else {
813  rc = -1;
814  }
815  }
816  }
817  return(rc);
818  }
819 
820  //------------------------------------------------------------------------
823  //------------------------------------------------------------------------
824  template <typename _keyT, typename _valueT,
825  typename _Compare, typename _Alloc>
826  static uint32_t
827  StreamedLength(const std::map<_keyT, _valueT, _Compare, _Alloc> & m)
828  {
829  return(ContainerStreamedLength<std::map<_keyT, _valueT, _Compare, _Alloc> >(m));
830  }
831 
832  //------------------------------------------------------------------------
834  //------------------------------------------------------------------------
835  template <typename _keyT, typename _valueT,
836  typename _Compare, typename _Alloc>
837  static std::istream & Read(std::istream & is,
838  std::map<_keyT, _valueT, _Compare, _Alloc> & m)
839  {
840  return(PairAssocContRead<std::map<_keyT, _valueT, _Compare, _Alloc> >(is, m));
841  }
842 
843  //------------------------------------------------------------------------
845  //------------------------------------------------------------------------
846  template <typename _keyT, typename _valueT,
847  typename _Compare, typename _Alloc>
848  static std::ostream & Write(std::ostream & os,
849  const std::map<_keyT,_valueT, _Compare, _Alloc> & m)
850  {
851  return(ContainerWrite<std::map<_keyT,_valueT,_Compare,_Alloc> >(os, m));
852  }
853 
854  //------------------------------------------------------------------------
857  //------------------------------------------------------------------------
858  template <typename _keyT, typename _valueT,
859  typename _Compare, typename _Alloc>
860  static size_t Read(FILE *f, std::map<_keyT, _valueT, _Compare, _Alloc> & m)
861  {
862  return(PairAssocContRead<std::map<_keyT, _valueT, _Compare, _Alloc> >(f, m));
863  }
864 
865  //------------------------------------------------------------------------
868  //------------------------------------------------------------------------
869  template <typename _keyT, typename _valueT,
870  typename _Compare, typename _Alloc>
871  static size_t
872  Write(FILE *f, const std::map<_keyT, _valueT, _Compare, _Alloc> & m)
873  {
874  return(ContainerWrite<std::map<_keyT,_valueT> >(f, m));
875  }
876 
877  //------------------------------------------------------------------------
880  //------------------------------------------------------------------------
881  template <typename _keyT, typename _valueT,
882  typename _Compare, typename _Alloc>
883  static ssize_t Read(int fd, std::map<_keyT, _valueT, _Compare, _Alloc> & m)
884  {
885  return(PairAssocContRead<std::map<_keyT, _valueT, _Compare, _Alloc> >(fd, m));
886  }
887 
888  //------------------------------------------------------------------------
891  //------------------------------------------------------------------------
892  template<typename _keyT, typename _valueT,
893  typename _Compare, typename _Alloc>
894  static ssize_t
895  Write(int fd, const std::map<_keyT,_valueT,_Compare,_Alloc> & m)
896  {
897  return(ContainerWrite<std::map<_keyT,_valueT,_Compare,_Alloc> >(fd, m));
898  }
899 
900  //------------------------------------------------------------------------
903  //------------------------------------------------------------------------
904  template <typename _keyT, typename _valueT,
905  typename _Compare, typename _Alloc>
906  static uint32_t
907  StreamedLength(const std::multimap<_keyT,_valueT,_Compare,_Alloc> & m)
908  {
909  return(ContainerStreamedLength<std::multimap<_keyT,_valueT,_Compare,_Alloc> >(m));
910  }
911 
912  //------------------------------------------------------------------------
915  //------------------------------------------------------------------------
916  template <typename _keyT, typename _valueT,
917  typename _Compare, typename _Alloc>
918  static std::istream &
919  Read(std::istream & is, std::multimap<_keyT,_valueT,_Compare,_Alloc> & m)
920  {
921  return(PairAssocContRead<std::multimap<_keyT,_valueT,_Compare,_Alloc> >(is, m));
922  }
923 
924  //------------------------------------------------------------------------
926  //------------------------------------------------------------------------
927  template <typename _keyT, typename _valueT,
928  typename _Compare, typename _Alloc>
929  static std::ostream &
930  Write(std::ostream & os,
931  const std::multimap<_keyT,_valueT, _Compare, _Alloc> & m)
932  {
933  return(ContainerWrite<std::multimap<_keyT,_valueT,_Compare,_Alloc> >(os, m));
934  }
935 
936  //------------------------------------------------------------------------
939  //------------------------------------------------------------------------
940  template <typename _keyT, typename _valueT,
941  typename _Compare, typename _Alloc>
942  static size_t
943  Read(FILE *f, std::multimap<_keyT, _valueT, _Compare, _Alloc> & m)
944  {
945  return(PairAssocContRead<std::multimap<_keyT,_valueT,_Compare,_Alloc> >(f, m));
946  }
947 
948  //------------------------------------------------------------------------
951  //------------------------------------------------------------------------
952  template <typename _keyT, typename _valueT,
953  typename _Compare, typename _Alloc>
954  static size_t
955  Write(FILE *f, const std::multimap<_keyT,_valueT, _Compare, _Alloc> & m)
956  {
957  return(ContainerWrite<std::multimap<_keyT,_valueT,_Compare,_Alloc> >(f, m));
958  }
959 
960  //------------------------------------------------------------------------
963  //------------------------------------------------------------------------
964  template <typename _keyT, typename _valueT,
965  typename _Compare, typename _Alloc>
966  static ssize_t
967  Read(int fd, std::multimap<_keyT, _valueT, _Compare, _Alloc> & m)
968  {
969  return(PairAssocContRead<std::multimap<_keyT,_valueT,_Compare,_Alloc> >(fd, m));
970  }
971 
972  //------------------------------------------------------------------------
975  //------------------------------------------------------------------------
976  template <typename _keyT, typename _valueT,
977  typename _Compare, typename _Alloc>
978  static ssize_t
979  Write(int fd, const std::multimap<_keyT,_valueT, _Compare, _Alloc> & m)
980  {
981  return(ContainerWrite<std::multimap<_keyT,_valueT,_Compare,_Alloc> >(fd, m));
982  }
983 
984  //------------------------------------------------------------------------
987  //------------------------------------------------------------------------
988  template <typename _valueT, typename _Alloc>
989  static uint32_t StreamedLength(const std::vector<_valueT, _Alloc> & v)
990  {
991  return(ContainerStreamedLength<std::vector<_valueT, _Alloc> >(v));
992  }
993 
994  //------------------------------------------------------------------------
996  //------------------------------------------------------------------------
997  template <typename _valueT, typename _Alloc>
998  static std::istream & Read(std::istream & is,
999  std::vector<_valueT, _Alloc> & v)
1000  {
1001  return(ContainerRead<std::vector<_valueT, _Alloc> >(is, v));
1002  }
1003 
1004  //------------------------------------------------------------------------
1006  //------------------------------------------------------------------------
1007  template <typename _valueT, typename _Alloc>
1008  static std::ostream & Write(std::ostream & os,
1009  const std::vector<_valueT, _Alloc> & v)
1010  {
1011  return(ContainerWrite<std::vector<_valueT, _Alloc> >(os, v));
1012  }
1013 
1014  //------------------------------------------------------------------------
1017  //------------------------------------------------------------------------
1018  template <typename _valueT, typename _Alloc>
1019  static size_t Read(FILE *f, std::vector<_valueT, _Alloc> & v)
1020  {
1021  return(ContainerRead<std::vector<_valueT, _Alloc> >(f, v));
1022  }
1023 
1024  //------------------------------------------------------------------------
1027  //------------------------------------------------------------------------
1028  template <typename _valueT, typename _Alloc>
1029  static size_t Write(FILE *f, const std::vector<_valueT, _Alloc> & v)
1030  {
1031  return(ContainerWrite<std::vector<_valueT, _Alloc> >(f, v));
1032  }
1033 
1034  //------------------------------------------------------------------------
1037  //------------------------------------------------------------------------
1038  template <typename _valueT, typename _Alloc>
1039  static ssize_t Read(int fd, std::vector<_valueT, _Alloc> & v)
1040  {
1041  return(ContainerRead<std::vector<_valueT, _Alloc> >(fd, v));
1042  }
1043 
1044  //------------------------------------------------------------------------
1047  //------------------------------------------------------------------------
1048  template <typename _valueT, typename _Alloc>
1049  static ssize_t Write(int fd, const std::vector<_valueT, _Alloc> & v)
1050  {
1051  return(ContainerWrite<std::vector<_valueT, _Alloc> >(fd, v));
1052  }
1053 
1054  //------------------------------------------------------------------------
1057  //------------------------------------------------------------------------
1058  template <typename _valueT, typename _Alloc>
1059  static uint32_t StreamedLength(const std::deque<_valueT, _Alloc> & d)
1060  {
1061  return(ContainerStreamedLength<std::deque<_valueT, _Alloc> >(d));
1062  }
1063 
1064  //------------------------------------------------------------------------
1066  //------------------------------------------------------------------------
1067  template <typename _valueT, typename _Alloc>
1068  static std::istream & Read(std::istream & is,
1069  std::deque<_valueT, _Alloc> & d)
1070  {
1071  return(ContainerRead<std::deque<_valueT, _Alloc> >(is, d));
1072  }
1073 
1074  //------------------------------------------------------------------------
1076  //------------------------------------------------------------------------
1077  template <typename _valueT, typename _Alloc>
1078  static std::ostream & Write(std::ostream & os,
1079  const std::deque<_valueT, _Alloc> & d)
1080  {
1081  return(ContainerWrite<std::deque<_valueT, _Alloc> >(os, d));
1082  }
1083 
1084  //------------------------------------------------------------------------
1087  //------------------------------------------------------------------------
1088  template <typename _valueT, typename _Alloc>
1089  static size_t Read(FILE *f, std::deque<_valueT, _Alloc> & d)
1090  {
1091  return(ContainerRead<std::deque<_valueT, _Alloc> >(f, d));
1092  }
1093 
1094  //------------------------------------------------------------------------
1097  //------------------------------------------------------------------------
1098  template <typename _valueT, typename _Alloc>
1099  static size_t Write(FILE *f, const std::deque<_valueT, _Alloc> & d)
1100  {
1101  return(ContainerWrite<std::deque<_valueT, _Alloc> >(f, d));
1102  }
1103 
1104  //------------------------------------------------------------------------
1107  //------------------------------------------------------------------------
1108  template <typename _valueT, typename _Alloc>
1109  static ssize_t Read(int fd, std::deque<_valueT, _Alloc> & d)
1110  {
1111  return(ContainerRead<std::deque<_valueT, _Alloc> >(fd, d));
1112  }
1113 
1114  //------------------------------------------------------------------------
1117  //------------------------------------------------------------------------
1118  template <typename _valueT, typename _Alloc>
1119  static ssize_t Write(int fd, const std::deque<_valueT, _Alloc> & d)
1120  {
1121  return(ContainerWrite<std::deque<_valueT, _Alloc> >(fd, d));
1122  }
1123 
1124  //------------------------------------------------------------------------
1127  //------------------------------------------------------------------------
1128  template <typename _valueT, typename _Alloc>
1129  static uint32_t StreamedLength(const std::list<_valueT, _Alloc> & l)
1130  {
1131  return(ContainerStreamedLength<std::list<_valueT, _Alloc> >(l));
1132  }
1133 
1134  //------------------------------------------------------------------------
1136  //------------------------------------------------------------------------
1137  template <typename _valueT, typename _Alloc>
1138  static std::istream & Read(std::istream & is,
1139  std::list<_valueT, _Alloc> & l)
1140  {
1141  return(ContainerRead<std::list<_valueT, _Alloc> >(is, l));
1142  }
1143 
1144  //------------------------------------------------------------------------
1146  //------------------------------------------------------------------------
1147  template <typename _valueT, typename _Alloc>
1148  static std::ostream & Write(std::ostream & os,
1149  const std::list<_valueT, _Alloc> & l)
1150  {
1151  return(ContainerWrite<std::list<_valueT, _Alloc> >(os, l));
1152  }
1153 
1154  //------------------------------------------------------------------------
1157  //------------------------------------------------------------------------
1158  template <typename _valueT, typename _Alloc>
1159  static size_t Read(FILE *f, std::list<_valueT, _Alloc> & l)
1160  {
1161  return(ContainerRead<std::list<_valueT, _Alloc> >(f, l));
1162  }
1163 
1164  //------------------------------------------------------------------------
1167  //------------------------------------------------------------------------
1168  template <typename _valueT, typename _Alloc>
1169  static size_t Write(FILE *f, const std::list<_valueT, _Alloc> & l)
1170  {
1171  return(ContainerWrite<std::list<_valueT, _Alloc> >(f, l));
1172  }
1173 
1174  //------------------------------------------------------------------------
1177  //------------------------------------------------------------------------
1178  template <typename _valueT, typename _Alloc>
1179  static ssize_t Read(int fd, std::list<_valueT, _Alloc> & l)
1180  {
1181  return(ContainerRead<std::list<_valueT, _Alloc> >(fd, l));
1182  }
1183 
1184  //------------------------------------------------------------------------
1187  //------------------------------------------------------------------------
1188  template <typename _valueT, typename _Alloc>
1189  static ssize_t Write(int fd, const std::list<_valueT, _Alloc> & l)
1190  {
1191  return(ContainerWrite<std::list<_valueT, _Alloc> >(fd, l));
1192  }
1193 
1194  //------------------------------------------------------------------------
1197  //------------------------------------------------------------------------
1198  template <typename _valueT, typename _Compare, typename _Alloc>
1199  static uint32_t
1200  StreamedLength(const std::set<_valueT, _Compare, _Alloc> & l)
1201  {
1202  return(ContainerStreamedLength<std::set<_valueT, _Compare, _Alloc> >(l));
1203  }
1204 
1205  //------------------------------------------------------------------------
1207  //------------------------------------------------------------------------
1208  template <typename _valueT, typename _Compare, typename _Alloc>
1209  static std::istream & Read(std::istream & is,
1210  std::set<_valueT, _Compare, _Alloc> & l)
1211  {
1212  return(ContainerRead<std::set<_valueT, _Compare, _Alloc> >(is, l));
1213  }
1214 
1215  //------------------------------------------------------------------------
1217  //------------------------------------------------------------------------
1218  template <typename _valueT, typename _Compare, typename _Alloc>
1219  static std::ostream & Write(std::ostream & os,
1220  const std::set<_valueT, _Compare, _Alloc> & l)
1221  {
1222  return(ContainerWrite<std::set<_valueT, _Compare, _Alloc> >(os, l));
1223  }
1224 
1225  //------------------------------------------------------------------------
1228  //------------------------------------------------------------------------
1229  template <typename _valueT, typename _Compare, typename _Alloc>
1230  static size_t Read(FILE *f, std::set<_valueT, _Compare, _Alloc> & l)
1231  {
1232  return(ContainerRead<std::set<_valueT, _Compare, _Alloc> >(f, l));
1233  }
1234 
1235  //------------------------------------------------------------------------
1238  //------------------------------------------------------------------------
1239  template <typename _valueT, typename _Compare, typename _Alloc>
1240  static size_t Write(FILE *f, const std::set<_valueT, _Compare, _Alloc> & l)
1241  {
1242  return(ContainerWrite<std::set<_valueT, _Compare, _Alloc> >(f, l));
1243  }
1244 
1245  //------------------------------------------------------------------------
1248  //------------------------------------------------------------------------
1249  template <typename _valueT, typename _Compare, typename _Alloc>
1250  static ssize_t Read(int fd, std::set<_valueT, _Compare, _Alloc> & l)
1251  {
1252  return(ContainerRead<std::set<_valueT, _Compare, _Alloc> >(fd, l));
1253  }
1254 
1255  //------------------------------------------------------------------------
1258  //------------------------------------------------------------------------
1259  template <typename _valueT, typename _Compare, typename _Alloc>
1260  static ssize_t Write(int fd, const std::set<_valueT, _Compare, _Alloc> & l)
1261  {
1262  return(ContainerWrite<std::set<_valueT, _Compare, _Alloc> >(fd, l));
1263  }
1264 
1265  //------------------------------------------------------------------------
1268  //------------------------------------------------------------------------
1269  template <typename _valueT, typename _Compare, typename _Alloc>
1270  static uint32_t
1271  StreamedLength(const std::multiset<_valueT, _Compare, _Alloc> & l)
1272  {
1273  return(ContainerStreamedLength<std::multiset<_valueT, _Compare, _Alloc> >(l));
1274  }
1275 
1276  //------------------------------------------------------------------------
1278  //------------------------------------------------------------------------
1279  template <typename _valueT, typename _Compare, typename _Alloc>
1280  static std::istream & Read(std::istream & is,
1281  std::multiset<_valueT, _Compare, _Alloc> & l)
1282  {
1283  return(ContainerRead<std::multiset<_valueT, _Compare, _Alloc> >(is, l));
1284  }
1285 
1286  //------------------------------------------------------------------------
1288  //------------------------------------------------------------------------
1289  template <typename _valueT, typename _Compare, typename _Alloc>
1290  static std::ostream &
1291  Write(std::ostream & os,
1292  const std::multiset<_valueT, _Compare, _Alloc> & l)
1293  {
1294  return(ContainerWrite<std::multiset<_valueT, _Compare, _Alloc> >(os, l));
1295  }
1296 
1297  //------------------------------------------------------------------------
1300  //------------------------------------------------------------------------
1301  template <typename _valueT, typename _Compare, typename _Alloc>
1302  static size_t Read(FILE *f, std::multiset<_valueT, _Compare, _Alloc> & l)
1303  {
1304  return(ContainerRead<std::multiset<_valueT, _Compare, _Alloc> >(f, l));
1305  }
1306 
1307  //------------------------------------------------------------------------
1310  //------------------------------------------------------------------------
1311  template <typename _valueT, typename _Compare, typename _Alloc>
1312  static size_t
1313  Write(FILE *f, const std::multiset<_valueT, _Compare, _Alloc> & l)
1314  {
1315  return(ContainerWrite<std::multiset<_valueT, _Compare, _Alloc> >(f, l));
1316  }
1317 
1318  //------------------------------------------------------------------------
1321  //------------------------------------------------------------------------
1322  template <typename _valueT, typename _Compare, typename _Alloc>
1323  static ssize_t Read(int fd, std::multiset<_valueT, _Compare, _Alloc> & l)
1324  {
1325  return(ContainerRead<std::multiset<_valueT, _Compare, _Alloc> >(fd, l));
1326  }
1327 
1328  //------------------------------------------------------------------------
1331  //------------------------------------------------------------------------
1332  template <typename _valueT, typename _Compare, typename _Alloc>
1333  static ssize_t
1334  Write(int fd, const std::multiset<_valueT, _Compare, _Alloc> & l)
1335  {
1336  return(ContainerWrite<std::multiset<_valueT, _Compare, _Alloc> >(fd, l));
1337  }
1338 
1339  //------------------------------------------------------------------------
1341  //------------------------------------------------------------------------
1342  template <typename T, typename... Args>
1343  static uint32_t VarStreamedLength(const T & t, Args... args)
1344  {
1345  uint32_t rc = StreamedLength(t);
1346  if (sizeof...(Args) > 0)
1347  rc += VarStreamedLength(args...);
1348  return(rc);
1349  }
1350 
1351  //------------------------------------------------------------------------
1353  //------------------------------------------------------------------------
1354  template <typename T, typename... Args>
1355  static std::ostream & VarWrite(std::ostream & os,
1356  const T & t, Args... args)
1357  {
1358  if (Write(os, t))
1359  if (sizeof...(Args) > 0)
1360  Write(os, args...);
1361  return(os);
1362  }
1363 
1364  //------------------------------------------------------------------------
1366  //------------------------------------------------------------------------
1367  template <typename T, typename... Args>
1368  static std::istream & VarRead(std::istream & is,
1369  const T & t, Args... args)
1370  {
1371  if (Read(is, t))
1372  if (sizeof...(Args) > 0)
1373  Read(is, args...);
1374  return(is);
1375  }
1376 
1377  //------------------------------------------------------------------------
1380  //------------------------------------------------------------------------
1381  template <typename T, typename... Args>
1382  static uint32_t StreamedLength(const std::tuple<T, Args...> & t)
1383  {
1384  return(TupleStreamedLength<std::tuple<T, Args...> >(t));
1385  }
1386 
1387  //------------------------------------------------------------------------
1389  //------------------------------------------------------------------------
1390  template <typename T, typename... Args>
1391  static std::istream & Read(std::istream & is,
1392  std::tuple<T, Args...> & t)
1393  {
1394  return(ReadTuple<std::tuple<T, Args...> >(is, t));
1395  }
1396 
1397  //------------------------------------------------------------------------
1399  //------------------------------------------------------------------------
1400  template <typename T, typename... Args>
1401  static std::ostream & Write(std::ostream & os,
1402  const std::tuple<T, Args...> & t)
1403  {
1404  return(WriteTuple<std::tuple<T, Args...> >(os, t));
1405  }
1406 
1407  //------------------------------------------------------------------------
1410  //------------------------------------------------------------------------
1411  template <typename T, typename... Args>
1412  static ssize_t Read(int fd, std::tuple<T, Args...> & t)
1413  {
1414  return(ReadTuple<std::tuple<T, Args...> >(fd, t));
1415  }
1416 
1417  //------------------------------------------------------------------------
1420  //------------------------------------------------------------------------
1421  template <typename T, typename... Args>
1422  static ssize_t Write(int fd, const std::tuple<T, Args...> & t)
1423  {
1424  return(WriteTuple<std::tuple<T, Args...> >(fd, t));
1425  }
1426 
1427  //------------------------------------------------------------------------
1429  //------------------------------------------------------------------------
1430  template <typename T, typename... Args>
1431  static size_t Read(FILE *f, std::tuple<T, Args...> & t)
1432  {
1433  return(ReadTuple<std::tuple<T, Args...> >(f, t));
1434  }
1435 
1436  //------------------------------------------------------------------------
1438  //------------------------------------------------------------------------
1439  template <typename T, typename... Args>
1440  static size_t Write(FILE *f, const std::tuple<T, Args...> & t)
1441  {
1442  return(WriteTuple<std::tuple<T, Args...> >(f, t));
1443  }
1444 
1445  //------------------------------------------------------------------------
1447  //------------------------------------------------------------------------
1448  template <typename T>
1449  static std::istream & ReadTuple(std::istream & is, T & t)
1450  {
1451  return(TupleIOHelper<T,std::tuple_size<T>::value-1>::Read(is, t));
1452  }
1453 
1454  //------------------------------------------------------------------------
1456  //------------------------------------------------------------------------
1457  template <typename T>
1458  static std::ostream & WriteTuple(std::ostream & os, const T & t)
1459  {
1460  return(TupleIOHelper<T,std::tuple_size<T>::value-1>::Write(os, t));
1461  }
1462 
1463  //------------------------------------------------------------------------
1465  //------------------------------------------------------------------------
1466  template <typename T>
1467  static ssize_t ReadTuple(int fd, T & t)
1468  {
1469  return(TupleIOHelper<T,std::tuple_size<T>::value-1>::Read(fd, t));
1470  }
1471 
1472  //------------------------------------------------------------------------
1474  //------------------------------------------------------------------------
1475  template <typename T>
1476  static ssize_t WriteTuple(int fd, const T & t)
1477  {
1478  return(TupleIOHelper<T,std::tuple_size<T>::value-1>::Write(fd, t));
1479  }
1480 
1481  //------------------------------------------------------------------------
1483  //------------------------------------------------------------------------
1484  template <typename T>
1485  static size_t ReadTuple(FILE *f, T & t)
1486  {
1487  if (TupleIOHelper<T,std::tuple_size<T>::value-1>::Read(f, t) > 0)
1488  return(1);
1489  return(0);
1490  }
1491 
1492  //------------------------------------------------------------------------
1494  //------------------------------------------------------------------------
1495  template <typename T>
1496  static size_t WriteTuple(FILE *f, const T & t)
1497  {
1498  if (TupleIOHelper<T,std::tuple_size<T>::value-1>::Write(f, t) > 0)
1499  return(1);
1500  return(0);
1501  }
1502 
1503  //------------------------------------------------------------------------
1505  //------------------------------------------------------------------------
1506  template <typename T>
1507  static uint32_t TupleStreamedLength(const T & t)
1508  {
1509  return(TupleIOHelper<T,std::tuple_size<T>::value-1>::StreamedLength(t));
1510  }
1511 
1512  private:
1513  //------------------------------------------------------------------------
1515  //------------------------------------------------------------------------
1516  template <typename _inputIteratorT>
1517  static uint32_t StreamedLength(_inputIteratorT f, _inputIteratorT l)
1518  {
1519  uint32_t rc = 0;
1520  for ( ; f != l; ++f)
1521  rc += StreamedLength(*f);
1522  return(rc);
1523  }
1524 
1525  //------------------------------------------------------------------------
1527  //------------------------------------------------------------------------
1528  template <typename _inputIteratorT>
1529  static std::ostream & Write(std::ostream & os,
1530  _inputIteratorT f, _inputIteratorT l)
1531  {
1532  if (os) {
1533  for ( ; f != l; ++f) {
1534  if (! Write(os, *f)) {
1535  break;
1536  }
1537  }
1538  }
1539  return(os);
1540  }
1541 
1542  //------------------------------------------------------------------------
1544  //------------------------------------------------------------------------
1545  template <typename _inputIteratorT>
1546  static size_t Write(FILE *file, _inputIteratorT f, _inputIteratorT l)
1547  {
1548  size_t rc = 0;
1549  if (file) {
1550  for ( ; f != l; ++f) {
1551  if (Write(file, *f) <= 0) {
1552  break;
1553  }
1554  }
1555  if (f == l)
1556  rc = 1;
1557  }
1558  return(rc);
1559  }
1560 
1561  //------------------------------------------------------------------------
1563  //------------------------------------------------------------------------
1564  template <typename _inputIteratorT>
1565  static ssize_t Write(int fd, _inputIteratorT f, _inputIteratorT l)
1566  {
1567  ssize_t rc = 0;
1568  if (fd >= 0) {
1569  for ( ; f != l; ++f) {
1570  ssize_t bytesWritten = Write(fd, *f);
1571  if (bytesWritten > 0) {
1572  rc += bytesWritten;
1573  }
1574  else {
1575  rc = -1;
1576  break;
1577  }
1578  }
1579  }
1580  return(rc);
1581  }
1582 
1583  //------------------------------------------------------------------------
1585  //------------------------------------------------------------------------
1586  template <typename _containerT>
1587  static uint32_t ContainerStreamedLength(const _containerT & c)
1588  {
1589  uint32_t rc = sizeof(uint32_t); // for size()
1590 
1591  rc += StreamedLength<typename _containerT::const_iterator>(c.begin(),
1592  c.end());
1593  return(rc);
1594  }
1595 
1596  //------------------------------------------------------------------------
1599  //------------------------------------------------------------------------
1600  template <typename _containerT>
1601  static std::istream & ContainerRead(std::istream & is,
1602  _containerT & c)
1603  {
1604  if (! c.empty())
1605  c.clear();
1606  if (is) {
1607  uint32_t numEntries;
1608  if (Read(is, numEntries)) {
1609  for (uint32_t i = 0; i < numEntries; ++i) {
1610  typename _containerT::value_type val;
1611  if (! Read(is, val))
1612  break;
1613  c.insert(c.end(), val);
1614  }
1615  }
1616  }
1617  return(is);
1618  }
1619 
1620  //------------------------------------------------------------------------
1623  //------------------------------------------------------------------------
1624  template <typename _containerT>
1625  static std::ostream & ContainerWrite(std::ostream & os,
1626  const _containerT & c)
1627  {
1628  if (os) {
1629  uint32_t numEntries = c.size();
1630  if (Write(os, numEntries)) {
1631  if (numEntries) {
1632  Write<typename _containerT::const_iterator>(os,
1633  c.begin(),
1634  c.end());
1635  }
1636  }
1637  }
1638  return(os);
1639  }
1640 
1641  //------------------------------------------------------------------------
1645  //------------------------------------------------------------------------
1646  template <typename _containerT>
1647  static size_t ContainerRead(FILE *f, _containerT & c)
1648  {
1649  size_t rc = 0;
1650  if (! c.empty())
1651  c.clear();
1652  if (f) {
1653  uint32_t numEntries;
1654  if (Read(f, numEntries)) {
1655  uint32_t i = 0;
1656  for ( ; i < numEntries; ++i) {
1657  typename _containerT::value_type val;
1658  if (Read(f, val) > 0)
1659  c.insert(c.end(), val);
1660  else
1661  break;
1662  }
1663  if (i == numEntries)
1664  rc = 1;
1665  }
1666  }
1667  return(rc);
1668  }
1669 
1670  //------------------------------------------------------------------------
1674  //------------------------------------------------------------------------
1675  template <typename _containerT>
1676  static size_t ContainerWrite(FILE *f, const _containerT & c)
1677  {
1678  size_t rc = 0;
1679  if (f) {
1680  uint32_t numEntries = c.size();
1681  if (Write(f, numEntries)) {
1682  if (numEntries) {
1683  rc = Write<typename _containerT::const_iterator>(f,
1684  c.begin(), c.end());
1685  }
1686  else {
1687  rc = 1;
1688  }
1689  }
1690  }
1691  return(rc);
1692  }
1693 
1694  //------------------------------------------------------------------------
1698  //------------------------------------------------------------------------
1699  template <typename _containerT>
1700  static ssize_t ContainerRead(int fd, _containerT & c)
1701  {
1702  if (! c.empty())
1703  c.clear();
1704  ssize_t rc = -1;
1705  if (fd >= 0) {
1706  uint32_t numEntries;
1707  ssize_t bytesRead = Read(fd, numEntries);
1708  if (bytesRead == sizeof(numEntries)) {
1709  rc = bytesRead;
1710  for (uint32_t i = 0; i < numEntries; ++i) {
1711  typename _containerT::value_type val;
1712  bytesRead = Read(fd, val);
1713  if (bytesRead > 0) {
1714  rc += bytesRead;
1715  c.insert(c.end(), val);
1716  }
1717  else {
1718  rc = -1;
1719  break;
1720  }
1721  }
1722  }
1723  }
1724  return(rc);
1725  }
1726 
1727  //------------------------------------------------------------------------
1731  //------------------------------------------------------------------------
1732  template <typename _containerT>
1733  static ssize_t ContainerWrite(int fd, const _containerT & c)
1734  {
1735  ssize_t rc = -1;
1736  if (fd >= 0) {
1737  uint32_t numEntries = c.size();
1738  uint32_t bytesWritten = Write(fd, numEntries);
1739  if (bytesWritten == sizeof(numEntries)) {
1740  rc = bytesWritten;
1741  if (numEntries) {
1742  bytesWritten =
1743  Write<typename _containerT::const_iterator>(fd,
1744  c.begin(),
1745  c.end());
1746  if (bytesWritten > 0)
1747  rc += bytesWritten;
1748  else
1749  rc = -1;
1750  }
1751  }
1752  }
1753  return(rc);
1754  }
1755 
1756 
1757  //------------------------------------------------------------------------
1761  //------------------------------------------------------------------------
1762  template <typename _containerT>
1763  static std::istream &
1764  PairAssocContRead(std::istream & is, _containerT & m)
1765  {
1766  if (! m.empty())
1767  m.clear();
1768  if (is) {
1769  uint32_t numEntries;
1770  if (Read(is, numEntries)) {
1771  for (uint32_t i = 0; i < numEntries; ++i) {
1772  typename _containerT::key_type key;
1773  if (Read(is, key)) {
1774  typename _containerT::mapped_type val;
1775  if (Read(is, val))
1776  m.insert(typename _containerT::value_type(key, val));
1777  else
1778  break;
1779  }
1780  else
1781  break;
1782  }
1783  }
1784  }
1785  return(is);
1786  }
1787 
1788  //------------------------------------------------------------------------
1792  //------------------------------------------------------------------------
1793  template <typename _containerT>
1794  static size_t PairAssocContRead(FILE *f, _containerT & m)
1795  {
1796  ssize_t rc = 0;
1797  if (! m.empty())
1798  m.clear();
1799  if (f) {
1800  uint32_t numEntries;
1801  if (Read(f, numEntries)) {
1802  uint32_t i = 0;
1803  for ( ; i < numEntries; ++i) {
1804  typename _containerT::key_type key;
1805  if (Read(f, key) > 0) {
1806  typename _containerT::mapped_type val;
1807  if (Read(f, val) > 0) {
1808  m.insert(typename _containerT::value_type(key, val));
1809  }
1810  else {
1811  break;
1812  }
1813  }
1814  else {
1815  break;
1816  }
1817  }
1818  if (i == numEntries)
1819  rc = 1;
1820  }
1821  }
1822  return(rc);
1823  }
1824 
1825  //------------------------------------------------------------------------
1829  //------------------------------------------------------------------------
1830  template <typename _containerT>
1831  static ssize_t PairAssocContRead(int fd, _containerT & m)
1832  {
1833  ssize_t rc = -1;
1834  if (! m.empty())
1835  m.clear();
1836  if (fd >= 0) {
1837  uint32_t numEntries;
1838  ssize_t bytesRead = Read(fd, numEntries);
1839  if (bytesRead == sizeof(numEntries)) {
1840  rc = bytesRead;
1841  for (uint32_t i = 0; i < numEntries; ++i) {
1842  typename _containerT::key_type key;
1843  bytesRead = Read(fd, key);
1844  if (bytesRead > 0) {
1845  rc += bytesRead;
1846  typename _containerT::mapped_type val;
1847  bytesRead = Read(fd, val);
1848  if (bytesRead > 0) {
1849  rc += bytesRead;
1850  m.insert(typename _containerT::value_type(key, val));
1851  }
1852  else {
1853  rc = -1;
1854  break;
1855  }
1856  }
1857  else {
1858  rc = -1;
1859  break;
1860  }
1861  }
1862  }
1863  }
1864  return(rc);
1865  }
1866 
1867  //------------------------------------------------------------------------
1870  //------------------------------------------------------------------------
1871  template <typename T, size_t elt>
1872  class TupleIOHelper;
1873 
1874  //------------------------------------------------------------------------
1876  //------------------------------------------------------------------------
1877  template <typename T>
1878  class TupleIOHelper<T, 0>
1879  {
1880  public:
1881  //----------------------------------------------------------------------
1883  //----------------------------------------------------------------------
1884  static std::istream & Read(std::istream & is, T & t)
1885  {
1886  return(IO::Read(is, std::get<0>(t)));
1887  }
1888 
1889  //----------------------------------------------------------------------
1891  //----------------------------------------------------------------------
1892  static std::ostream & Write(std::ostream & os, const T & t)
1893  {
1894  return(IO::Write(os, std::get<0>(t)));
1895  }
1896 
1897  //----------------------------------------------------------------------
1900  //----------------------------------------------------------------------
1901  static ssize_t Read(int fd, T & t)
1902  {
1903  return(IO::Read(fd, std::get<0>(t)));
1904  }
1905 
1906  //----------------------------------------------------------------------
1909  //----------------------------------------------------------------------
1910  static ssize_t Write(int fd, const T & t)
1911  {
1912  return(IO::Write(fd, std::get<0>(t)));
1913  }
1914 
1915  //----------------------------------------------------------------------
1918  //----------------------------------------------------------------------
1919  static size_t Read(FILE *f, T & t)
1920  {
1921  return(IO::Read(f, std::get<0>(t)));
1922  }
1923 
1924  //----------------------------------------------------------------------
1927  //----------------------------------------------------------------------
1928  static size_t Write(FILE *f, const T & t)
1929  {
1930  return(IO::Write(f, std::get<0>(t)));
1931  }
1932 
1933  //----------------------------------------------------------------------
1936  //----------------------------------------------------------------------
1937  static uint32_t StreamedLength(const T & t)
1938  {
1939  return(IO::StreamedLength(std::get<0>(t)));
1940  }
1941  };
1942 
1943  //------------------------------------------------------------------------
1945  //------------------------------------------------------------------------
1946  template <typename T, size_t elt>
1947  class TupleIOHelper
1948  {
1949  public:
1950  //----------------------------------------------------------------------
1952  //----------------------------------------------------------------------
1953  static std::istream & Read(std::istream & is, T & t)
1954  {
1955  if (TupleIOHelper<T,elt-1>::Read(is, t))
1956  IO::Read(is, std::get<elt>(t));
1957  return(is);
1958  }
1959 
1960  //----------------------------------------------------------------------
1962  //----------------------------------------------------------------------
1963  static std::ostream & Write(std::ostream & os, const T & t)
1964  {
1965  if (TupleIOHelper<T,elt-1>::Write(os, t))
1966  IO::Write(os, std::get<elt>(t));
1967  return(os);
1968  }
1969 
1970  //----------------------------------------------------------------------
1972  //----------------------------------------------------------------------
1973  static ssize_t Read(int fd, T & t)
1974  {
1975  ssize_t rc = TupleIOHelper<T,elt-1>::Read(fd, t);
1976  rc += IO::Read(fd, std::get<elt>(t));
1977  return(rc);
1978  }
1979 
1980  //----------------------------------------------------------------------
1982  //----------------------------------------------------------------------
1983  static ssize_t Write(int fd, const T & t)
1984  {
1985  ssize_t rc = TupleIOHelper<T,elt-1>::Write(fd, t);
1986  rc += IO::Write(fd, std::get<elt>(t));
1987  return(rc);
1988  }
1989 
1990  //----------------------------------------------------------------------
1992  //----------------------------------------------------------------------
1993  static size_t Read(FILE *f, T & t)
1994  {
1995  size_t rc = TupleIOHelper<T,elt-1>::Read(f, t);
1996  if (rc > 0)
1997  rc = IO::Read(f, std::get<elt>(t));
1998  return(rc);
1999  }
2000 
2001  //----------------------------------------------------------------------
2003  //----------------------------------------------------------------------
2004  static size_t Write(FILE *f, const T & t)
2005  {
2006  size_t rc = TupleIOHelper<T,elt-1>::Write(f, t);
2007  if (rc > 0) {
2008  rc = IO::Write(f, std::get<elt>(t));
2009  }
2010 
2011  return(rc);
2012  }
2013 
2014  //----------------------------------------------------------------------
2017  //----------------------------------------------------------------------
2018  static uint32_t StreamedLength(const T & t)
2019  {
2020  uint32_t rc = TupleIOHelper<T,elt-1>::StreamedLength(t);
2021  rc += IO::StreamedLength(std::get<elt>(t));
2022  return(rc);
2023  }
2024  };
2025 
2026  public:
2027 
2028  //------------------------------------------------------------------------
2030  //------------------------------------------------------------------------
2031  template <typename _keyT, typename _valueT,
2032  typename _Hash, typename _Pred, typename _Alloc>
2033  static uint32_t
2034  StreamedLength(const std::unordered_map<_keyT, _valueT, _Hash, _Pred, _Alloc> & m)
2035  {
2036  return(ContainerStreamedLength<std::unordered_map<_keyT, _valueT, _Hash, _Pred, _Alloc> >(m));
2037  }
2038 
2039  //------------------------------------------------------------------------
2042  //------------------------------------------------------------------------
2043  template <typename _keyT, typename _valueT,
2044  typename _Hash, typename _Pred, typename _Alloc>
2045  static std::istream &
2046  Read(std::istream & is,
2047  std::unordered_map<_keyT, _valueT, _Hash, _Pred, _Alloc> & m)
2048  {
2049  return(PairAssocContRead<std::unordered_map<_keyT, _valueT, _Hash, _Pred, _Alloc> >(is, m));
2050  }
2051 
2052  //------------------------------------------------------------------------
2055  //------------------------------------------------------------------------
2056  template <typename _keyT, typename _valueT,
2057  typename _Hash, typename _Pred, typename _Alloc>
2058  static std::ostream &
2059  Write(std::ostream & os,
2060  const std::unordered_map<_keyT, _valueT, _Hash, _Pred, _Alloc> & m)
2061  {
2062  return(ContainerWrite<std::unordered_map<_keyT,_valueT,_Hash,_Pred,_Alloc> >(os, m));
2063  }
2064 
2065  //------------------------------------------------------------------------
2068  //------------------------------------------------------------------------
2069  template <typename _keyT, typename _valueT,
2070  typename _Hash, typename _Pred, typename _Alloc>
2071  static ssize_t
2072  Read(int fd, std::unordered_map<_keyT, _valueT, _Hash, _Pred, _Alloc> & m)
2073  {
2074  return(PairAssocContRead<std::unordered_map<_keyT, _valueT, _Hash, _Pred, _Alloc> >(fd, m));
2075  }
2076 
2077  //------------------------------------------------------------------------
2080  //------------------------------------------------------------------------
2081  template<typename _keyT, typename _valueT,
2082  typename _Hash, typename _Pred, typename _Alloc>
2083  static ssize_t
2084  Write(int fd,
2085  const std::unordered_map<_keyT,_valueT,_Hash,_Pred,_Alloc> & m)
2086  {
2087  return(ContainerWrite<std::unordered_map<_keyT,_valueT,_Hash,_Pred,_Alloc> >(fd, m));
2088  }
2089 
2090  //------------------------------------------------------------------------
2093  //------------------------------------------------------------------------
2094  template<typename _keyT, typename _valueT, typename _Hash,
2095  typename _Pred, typename _Alloc>
2096  static size_t
2097  Read(FILE *f, std::unordered_map<_keyT,_valueT,_Hash,_Pred,_Alloc> & hm)
2098  {
2099  return(PairAssocContRead<std::unordered_map<_keyT,_valueT,_Hash,_Pred,_Alloc> >(f, hm));
2100  }
2101 
2102  //------------------------------------------------------------------------
2105  //------------------------------------------------------------------------
2106  template<typename _keyT, typename _valueT, typename _Hash,
2107  typename _Pred, typename _Alloc>
2108  static size_t
2109  Write(FILE *f, const std::unordered_map<_keyT,_valueT,_Hash,_Pred,_Alloc> & hm)
2110  {
2111  return(ContainerWrite<std::unordered_map<_keyT,_valueT,_Hash,_Pred,_Alloc> >(f, hm));
2112  }
2113 
2114  //========================================================================
2115  // I/O functions for unordered_multimap
2116  //========================================================================
2117 
2118  //------------------------------------------------------------------------
2120  //------------------------------------------------------------------------
2121  template <typename _keyT, typename _valueT,
2122  typename _Hash, typename _Pred, typename _Alloc>
2123  static uint32_t
2124  StreamedLength(const std::unordered_multimap<_keyT, _valueT, _Hash, _Pred, _Alloc> & m)
2125  {
2126  return(ContainerStreamedLength<std::unordered_multimap<_keyT, _valueT, _Hash, _Pred, _Alloc> >(m));
2127  }
2128 
2129  //------------------------------------------------------------------------
2132  //------------------------------------------------------------------------
2133  template <typename _keyT, typename _valueT,
2134  typename _Hash, typename _Pred, typename _Alloc>
2135  static std::istream & Read(std::istream & is,
2136  std::unordered_multimap<_keyT, _valueT, _Hash, _Pred, _Alloc> & m)
2137  {
2138  return(PairAssocContRead<std::unordered_multimap<_keyT, _valueT, _Hash, _Pred, _Alloc> >(is, m));
2139  }
2140 
2141  //------------------------------------------------------------------------
2144  //------------------------------------------------------------------------
2145  template <typename _keyT, typename _valueT,
2146  typename _Hash, typename _Pred, typename _Alloc>
2147  static std::ostream &
2148  Write(std::ostream & os,
2149  const std::unordered_multimap<_keyT, _valueT, _Hash, _Pred, _Alloc> & m)
2150  {
2151  return(ContainerWrite<std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc> >(os, m));
2152  }
2153 
2154  //------------------------------------------------------------------------
2157  //------------------------------------------------------------------------
2158  template <typename _keyT, typename _valueT,
2159  typename _Hash, typename _Pred, typename _Alloc>
2160  static ssize_t
2161  Read(int fd, std::unordered_multimap<_keyT, _valueT, _Hash, _Pred, _Alloc> & m)
2162  {
2163  return(PairAssocContRead<std::unordered_multimap<_keyT, _valueT, _Hash, _Pred, _Alloc> >(fd, m));
2164  }
2165 
2166  //------------------------------------------------------------------------
2169  //------------------------------------------------------------------------
2170  template<typename _keyT, typename _valueT,
2171  typename _Hash, typename _Pred, typename _Alloc>
2172  static ssize_t
2173  Write(int fd, const std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc> & m)
2174  {
2175  return(ContainerWrite<std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc> >(fd, m));
2176  }
2177 
2178  //------------------------------------------------------------------------
2181  //------------------------------------------------------------------------
2182  template<typename _keyT, typename _valueT, typename _Hash,
2183  typename _Pred, typename _Alloc>
2184  static size_t
2185  Read(FILE *f, std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc> & hm)
2186  {
2187  return(PairAssocContRead<std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc> >(f, hm));
2188  }
2189 
2190  //------------------------------------------------------------------------
2193  //------------------------------------------------------------------------
2194  template<typename _keyT, typename _valueT, typename _Hash,
2195  typename _Pred, typename _Alloc>
2196  static size_t
2197  Write(FILE *f, const std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc> & hm)
2198  {
2199  return(ContainerWrite<std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc> >(f, hm));
2200  }
2201 
2202  //========================================================================
2203  // I/O functions for unordered_set
2204  //========================================================================
2205 
2206  //------------------------------------------------------------------------
2208  //------------------------------------------------------------------------
2209  template <typename _valueT, typename _Hash,
2210  typename _Pred, typename _Alloc>
2211  static uint32_t
2212  StreamedLength(const std::unordered_set<_valueT, _Hash, _Pred, _Alloc> & m)
2213  {
2214  return(ContainerStreamedLength<std::unordered_set<_valueT, _Hash, _Pred, _Alloc> >(m));
2215  }
2216 
2217  //------------------------------------------------------------------------
2220  //------------------------------------------------------------------------
2221  template <typename _valueT, typename _Hash,
2222  typename _Pred, typename _Alloc>
2223  static std::istream &
2224  Read(std::istream & is,
2225  std::unordered_set<_valueT, _Hash, _Pred, _Alloc> & m)
2226  {
2227  return(ContainerRead<std::unordered_set<_valueT, _Hash, _Pred, _Alloc> >(is, m));
2228  }
2229 
2230  //------------------------------------------------------------------------
2233  //------------------------------------------------------------------------
2234  template <typename _valueT, typename _Hash,
2235  typename _Pred, typename _Alloc>
2236  static std::ostream &
2237  Write(std::ostream & os,
2238  const std::unordered_set<_valueT, _Hash, _Pred, _Alloc> & m)
2239  {
2240  return(ContainerWrite<std::unordered_set<_valueT,_Hash,_Pred,_Alloc> >(os, m));
2241  }
2242 
2243  //------------------------------------------------------------------------
2246  //------------------------------------------------------------------------
2247  template <typename _valueT, typename _Hash,
2248  typename _Pred, typename _Alloc>
2249  static ssize_t
2250  Read(int fd, std::unordered_set<_valueT, _Hash, _Pred, _Alloc> & m)
2251  {
2252  return(ContainerRead<std::unordered_set<_valueT, _Hash, _Pred, _Alloc> >(fd, m));
2253  }
2254 
2255  //------------------------------------------------------------------------
2258  //------------------------------------------------------------------------
2259  template<typename _valueT, typename _Hash,
2260  typename _Pred, typename _Alloc>
2261  static ssize_t
2262  Write(int fd, const std::unordered_set<_valueT,_Hash,_Pred,_Alloc> & m)
2263  {
2264  return(ContainerWrite<std::unordered_set<_valueT,_Hash,_Pred,_Alloc> >(fd, m));
2265  }
2266 
2267  //------------------------------------------------------------------------
2270  //------------------------------------------------------------------------
2271  template<typename _valueT, typename _Hash,
2272  typename _Pred, typename _Alloc>
2273  static size_t
2274  Read(FILE *f, std::unordered_set<_valueT,_Hash,_Pred,_Alloc> & hm)
2275  {
2276  return(ContainerRead<std::unordered_set<_valueT,_Hash,_Pred,_Alloc> >(f, hm));
2277  }
2278 
2279  //------------------------------------------------------------------------
2282  //------------------------------------------------------------------------
2283  template<typename _valueT, typename _Hash,
2284  typename _Pred, typename _Alloc>
2285  static size_t
2286  Write(FILE *f, const std::unordered_set<_valueT,_Hash,_Pred,_Alloc> & hm)
2287  {
2288  return(ContainerWrite<std::unordered_set<_valueT,_Hash,_Pred,_Alloc> >(f, hm));
2289  }
2290 
2291  //========================================================================
2292  // I/O functions for unordered_multiset
2293  //========================================================================
2294 
2295  //------------------------------------------------------------------------
2297  //------------------------------------------------------------------------
2298  template <typename _valueT, typename _Hash,
2299  typename _Pred, typename _Alloc>
2300  static uint32_t
2301  StreamedLength(const std::unordered_multiset<_valueT, _Hash, _Pred, _Alloc> & m)
2302  {
2303  return(ContainerStreamedLength<std::unordered_multiset<_valueT, _Hash, _Pred, _Alloc> >(m));
2304  }
2305 
2306  //------------------------------------------------------------------------
2309  //------------------------------------------------------------------------
2310  template <typename _valueT, typename _Hash,
2311  typename _Pred, typename _Alloc>
2312  static std::istream &
2313  Read(std::istream & is,
2314  std::unordered_multiset<_valueT, _Hash, _Pred, _Alloc> & m)
2315  {
2316  return(ContainerRead<std::unordered_multiset<_valueT, _Hash, _Pred, _Alloc> >(is, m));
2317  }
2318 
2319  //------------------------------------------------------------------------
2322  //------------------------------------------------------------------------
2323  template <typename _valueT, typename _Hash,
2324  typename _Pred, typename _Alloc>
2325  static std::ostream &
2326  Write(std::ostream & os,
2327  const std::unordered_multiset<_valueT, _Hash, _Pred, _Alloc> & m)
2328  {
2329  return(ContainerWrite<std::unordered_multiset<_valueT,_Hash,_Pred,_Alloc> >(os, m));
2330  }
2331 
2332  //------------------------------------------------------------------------
2335  //------------------------------------------------------------------------
2336  template <typename _valueT, typename _Hash,
2337  typename _Pred, typename _Alloc>
2338  static ssize_t
2339  Read(int fd, std::unordered_multiset<_valueT, _Hash, _Pred, _Alloc> & m)
2340  {
2341  return(ContainerRead<std::unordered_multiset<_valueT, _Hash, _Pred, _Alloc> >(fd, m));
2342  }
2343 
2344  //------------------------------------------------------------------------
2347  //------------------------------------------------------------------------
2348  template<typename _valueT, typename _Hash,
2349  typename _Pred, typename _Alloc>
2350  static ssize_t
2351  Write(int fd, const std::unordered_multiset<_valueT,_Hash,_Pred,_Alloc> & m)
2352  {
2353  return(ContainerWrite<std::unordered_multiset<_valueT,_Hash,_Pred,_Alloc> >(fd, m));
2354  }
2355 
2356  //------------------------------------------------------------------------
2359  //------------------------------------------------------------------------
2360  template<typename _valueT, typename _Hash,
2361  typename _Pred, typename _Alloc>
2362  static size_t
2363  Read(FILE *f, std::unordered_multiset<_valueT,_Hash,_Pred,_Alloc> & hm)
2364  {
2365  return(ContainerRead<std::unordered_multiset<_valueT,_Hash,_Pred,_Alloc> >(f, hm));
2366  }
2367 
2368  //------------------------------------------------------------------------
2371  //------------------------------------------------------------------------
2372  template<typename _valueT, typename _Hash,
2373  typename _Pred, typename _Alloc>
2374  static size_t
2375  Write(FILE *f, const std::unordered_multiset<_valueT,_Hash,_Pred,_Alloc> & hm)
2376  {
2377  return(ContainerWrite<std::unordered_multiset<_valueT,_Hash,_Pred,_Alloc> >(f, hm));
2378  }
2379 
2380  };
2381 
2382 
2383 } // namespace Dwm
2384 
2385 #endif // _DWMIO_HH_
2386 
2387 //---------------------------- emacs settings -----------------------------
2388 // Local Variables:
2389 // mode: C++
2390 // tab-width: 2
2391 // indent-tabs-mode: nil
2392 // c-basic-offset: 2
2393 // End:
2394 //-------------------------------------------------------------------------
static size_t Write(FILE *f, const std::list< _valueT, _Alloc > &l)
Writes a list<_valueT> to a FILE pointer.
Definition: DwmIO.hh:1169
static size_t Read(FILE *f, std::set< _valueT, _Compare, _Alloc > &l)
Reads a set<_valueT> from a FILE pointer.
Definition: DwmIO.hh:1230
static ssize_t ReadTuple(int fd, T &t)
T must be a tuple.
Definition: DwmIO.hh:1467
static ssize_t Write(int fd, const std::set< _valueT, _Compare, _Alloc > &l)
Writes a set<_valueT> to a file descriptor.
Definition: DwmIO.hh:1260
static uint32_t StreamedLength(const std::string &s)
Returns the number of bytes that should be written if we call one of the Write() members for a string...
Definition: DwmIO.hh:254
static uint32_t StreamedLength(bool b)
Returns the number of bytes that would be written if we called one of the Write() members for a bool...
Definition: DwmIO.hh:120
static std::istream & Read(std::istream &is, std::set< _valueT, _Compare, _Alloc > &l)
Reads a set<_valueT> from an istream. Returns the istream.
Definition: DwmIO.hh:1209
static size_t Write(FILE *f, const std::pair< _firstT, _secondT > &p)
Writes a pair<_firstT,_secondT> to a FILE pointer.
Definition: DwmIO.hh:764
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.
Definition: DwmIO.hh:837
static ssize_t Read(int fd, std::tuple< T, Args... > &t)
Reads a tuple from a file descriptor.
Definition: DwmIO.hh:1412
Dwm::Writable pure virtual class definition.
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.
Definition: DwmIO.hh:930
static ssize_t Read(int fd, std::list< _valueT, _Alloc > &l)
Reads a list<_valueT> from a file descriptor.
Definition: DwmIO.hh:1179
static std::istream & Read(std::istream &is, std::vector< _valueT, _Alloc > &v)
Reads a vector<_valueT> from an istream. Returns the istream.
Definition: DwmIO.hh:998
static size_t WriteTuple(FILE *f, const T &t)
T must be a tuple.
Definition: DwmIO.hh:1496
static size_t Write(FILE *f, const std::deque< _valueT, _Alloc > &d)
Writes a deque<_valueT> to a FILE pointer.
Definition: DwmIO.hh:1099
virtual std::istream & Read(std::istream &is)=0
Read from an istream. Return the istream.
static ssize_t Write(int fd, const std::map< _keyT, _valueT, _Compare, _Alloc > &m)
Writes a map<_keyT,_valueT> to a file descriptor.
Definition: DwmIO.hh:895
Dwm::Readable pure virtual class definition.
static ssize_t Read(int fd, std::unordered_set< _valueT, _Hash, _Pred, _Alloc > &m)
Reads an unordered_set<_valueT> from a file descriptor.
Definition: DwmIO.hh:2250
static size_t Write(FILE *f, const Writable &val)
Wrapper function to write a Writable object to a FILE pointer.
Definition: DwmIO.hh:676
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.
Definition: DwmIO.hh:2148
virtual std::ostream & Write(std::ostream &os) const =0
Write to an ostream. Return the ostream.
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.
Definition: DwmIO.hh:2046
static std::istream & Read(std::istream &is, std::unordered_set< _valueT, _Hash, _Pred, _Alloc > &m)
Reads an unordered_set<_valueT> from an istream.
Definition: DwmIO.hh:2224
static std::istream & Read(std::istream &is, std::pair< _firstT, _secondT > &p)
Reads a pair<_firstT,_secondT> from an istream. Returns the istream.
Definition: DwmIO.hh:719
static ssize_t Write(int fd, const std::list< _valueT, _Alloc > &l)
Writes a list<_valueT> to a file descriptor.
Definition: DwmIO.hh:1189
static size_t Read(FILE *f, std::unordered_multiset< _valueT, _Hash, _Pred, _Alloc > &hm)
Reads an unordered_multiset from a FILE pointer.
Definition: DwmIO.hh:2363
static size_t Read(FILE *f, std::tuple< T, Args... > &t)
Reads a tuple from a FILE. Returns 1 on success, 0 on failure.
Definition: DwmIO.hh:1431
static ssize_t Write(int fd, const std::multimap< _keyT, _valueT, _Compare, _Alloc > &m)
Writes a multimap<_keyT,_valueT> to a file descriptor.
Definition: DwmIO.hh:979
static std::ostream & Write(std::ostream &os, const Writable &val)
Wrapper function to write a Writable object to an ostream.
Definition: DwmIO.hh:660
virtual uint32_t StreamedLength() const =0
Returns the number of bytes that should be written if one of the Write() members is called...
static uint32_t StreamedLength(uint64_t val)
Returns the number of bytes that would be written if we called one of the Write() members for a uint6...
Definition: DwmIO.hh:209
static ssize_t Read(int fd, std::deque< _valueT, _Alloc > &d)
Reads a deque<_valueT> from a file descriptor.
Definition: DwmIO.hh:1109
static ssize_t Write(int fd, const std::pair< _firstT, _secondT > &p)
Writes a pair<_firstT,_secondT> to a file descriptor.
Definition: DwmIO.hh:801
static ssize_t Write(int fd, const Writable &val)
Wrapper function to write a Writable object to a descriptor.
Definition: DwmIO.hh:668
static std::ostream & Write(std::ostream &os, const std::unordered_multiset< _valueT, _Hash, _Pred, _Alloc > &m)
Writes a unordered_multiset<_valueT> to an ostream.
Definition: DwmIO.hh:2326
static std::istream & ReadTuple(std::istream &is, T &t)
T must be a tuple.
Definition: DwmIO.hh:1449
static ssize_t Read(int fd, Readable &val)
Wrapper function to read a Readable object from a descriptor.
Definition: DwmIO.hh:692
static size_t Write(FILE *f, const std::multimap< _keyT, _valueT, _Compare, _Alloc > &m)
Writes a multimap<_keyT,_valueT> to a FILE pointer.
Definition: DwmIO.hh:955
static std::istream & Read(std::istream &is, std::unordered_multiset< _valueT, _Hash, _Pred, _Alloc > &m)
Reads an unordered_multiset<_valueT> from an istream.
Definition: DwmIO.hh:2313
static std::ostream & Write(std::ostream &os, const std::unordered_set< _valueT, _Hash, _Pred, _Alloc > &m)
Writes a unordered_set<_valueT> to an ostream.
Definition: DwmIO.hh:2237
static size_t Read(FILE *f, std::multiset< _valueT, _Compare, _Alloc > &l)
Reads a multiset<_valueT> from a FILE pointer.
Definition: DwmIO.hh:1302
static size_t Read(FILE *f, Readable &val)
Wrapper function to read a Readable object from a FILE pointer.
Definition: DwmIO.hh:700
static ssize_t Read(int fd, std::multimap< _keyT, _valueT, _Compare, _Alloc > &m)
Reads a multimap<_keyT,_valueT> from a file descriptor.
Definition: DwmIO.hh:967
static size_t Write(FILE *f, const std::multiset< _valueT, _Compare, _Alloc > &l)
Writes a multiset<_valueT> to a FILE pointer.
Definition: DwmIO.hh:1313
static uint32_t StreamedLength(int16_t val)
Returns the number of bytes that would be written if we called one of the Write() members for an int1...
Definition: DwmIO.hh:134
static std::ostream & Write(std::ostream &os, char c)
Writes c to os. Returns os.
static uint32_t TupleStreamedLength(const T &t)
T must be a tuple.
Definition: DwmIO.hh:1507
This class contains a collection of static functions for reading and writing simple types...
Definition: DwmIO.hh:85
static size_t ReadTuple(FILE *f, T &t)
T must be a tuple.
Definition: DwmIO.hh:1485
static size_t Read(FILE *f, std::unordered_set< _valueT, _Hash, _Pred, _Alloc > &hm)
Reads an unordered_set from a FILE pointer.
Definition: DwmIO.hh:2274
static size_t Write(FILE *f, const std::set< _valueT, _Compare, _Alloc > &l)
Writes a set<_valueT> to a FILE pointer.
Definition: DwmIO.hh:1240
static uint32_t StreamedLength(uint8_t c)
Returns the number of bytes that would be written if we called Write() for a uint8_t.
Definition: DwmIO.hh:106
static ssize_t Write(int fd, const std::vector< _valueT, _Alloc > &v)
Writes a vector<_valueT> to a file descriptor.
Definition: DwmIO.hh:1049
static uint32_t StreamedLength(const std::multiset< _valueT, _Compare, _Alloc > &l)
Returns the number of bytes that should be written if we call one of the Write() members for a multis...
Definition: DwmIO.hh:1271
static uint32_t StreamedLength(int32_t val)
Returns the number of bytes that would be written if we called one of the Write() members for an int3...
Definition: DwmIO.hh:164
static std::istream & Read(std::istream &is, std::deque< _valueT, _Alloc > &d)
Reads a deque<_valueT> from an istream. Returns the istream.
Definition: DwmIO.hh:1068
static size_t Read(FILE *f, std::list< _valueT, _Alloc > &l)
Reads a list<_valueT> from a FILE pointer.
Definition: DwmIO.hh:1159
static ssize_t Write(int fd, const std::unordered_multiset< _valueT, _Hash, _Pred, _Alloc > &m)
Writes an unordered_multiset<_valueT> to a file descriptor.
Definition: DwmIO.hh:2351
static std::ostream & Write(std::ostream &os, const std::multiset< _valueT, _Compare, _Alloc > &l)
Writes a multiset<_valueT> to an ostream. Returns the ostream.
Definition: DwmIO.hh:1291
static ssize_t Write(int fd, const std::tuple< T, Args... > &t)
Writes a tuple to a file descriptor.
Definition: DwmIO.hh:1422
static uint32_t StreamedLength(const std::pair< _firstT, _secondT > &p)
Returns the number of bytes that should be written if we call one of the Write() members for a pair<_...
Definition: DwmIO.hh:710
static ssize_t Read(int fd, std::unordered_multimap< _keyT, _valueT, _Hash, _Pred, _Alloc > &m)
Reads an unordered_multimap<_keyT,_valueT> from a file descriptor.
Definition: DwmIO.hh:2161
static std::ostream & WriteTuple(std::ostream &os, const T &t)
T must be a tuple.
Definition: DwmIO.hh:1458
static std::istream & Read(std::istream &is, char &c)
Reads c from is. Returns is.
static uint32_t StreamedLength(const std::set< _valueT, _Compare, _Alloc > &l)
Returns the number of bytes that should be written if we call one of the Write() members for a set<_v...
Definition: DwmIO.hh:1200
static uint32_t StreamedLength(uint16_t val)
Returns the number of bytes that would be written if we called one of the Write() members for a uint1...
Definition: DwmIO.hh:149
Definition: DwmBZ2IO.hh:67
static size_t Write(FILE *f, const std::vector< _valueT, _Alloc > &v)
Writes a vector<_valueT> to a FILE pointer.
Definition: DwmIO.hh:1029
static size_t Read(FILE *f, std::multimap< _keyT, _valueT, _Compare, _Alloc > &m)
Reads a multimap<_keyT,_valueT> from a FILE pointer.
Definition: DwmIO.hh:943
static size_t Read(FILE *f, std::deque< _valueT, _Alloc > &d)
Reads a deque<_valueT> from a FILE pointer.
Definition: DwmIO.hh:1089
static ssize_t Write(int fd, const std::multiset< _valueT, _Compare, _Alloc > &l)
Writes a multiset<_valueT> to a file descriptor.
Definition: DwmIO.hh:1334
static uint32_t StreamedLength(const std::deque< _valueT, _Alloc > &d)
Returns the number of bytes that should be written if we call one of the Write() members for a deque<...
Definition: DwmIO.hh:1059
static std::ostream & Write(std::ostream &os, const std::list< _valueT, _Alloc > &l)
Writes a list<_valueT> to an ostream. Returns the ostream.
Definition: DwmIO.hh:1148
static uint32_t StreamedLength(int64_t val)
Returns the number of bytes that would be written if we called one of the Write() members for an int6...
Definition: DwmIO.hh:194
static uint32_t StreamedLength(double val)
Returns the number of bytes that should be written if we call one of the Write() members for a double...
Definition: DwmIO.hh:239
static size_t Read(FILE *f, std::unordered_map< _keyT, _valueT, _Hash, _Pred, _Alloc > &hm)
Reads an unordered_map from a FILE pointer.
Definition: DwmIO.hh:2097
static uint32_t StreamedLength(const Writable &val)
Returns the number of bytes that should be written if we call one of the Write() members for a Writab...
Definition: DwmIO.hh:652
static ssize_t Write(int fd, const std::unordered_set< _valueT, _Hash, _Pred, _Alloc > &m)
Writes an unordered_set<_valueT> to a file descriptor.
Definition: DwmIO.hh:2262
static size_t Read(FILE *f, std::vector< _valueT, _Alloc > &v)
Reads a vector<_valueT> from a FILE pointer.
Definition: DwmIO.hh:1019
static std::istream & Read(std::istream &is, std::multiset< _valueT, _Compare, _Alloc > &l)
Reads a multiset<_valueT> from an istream. Returns the istream.
Definition: DwmIO.hh:1280
static size_t Read(FILE *f, std::unordered_multimap< _keyT, _valueT, _Hash, _Pred, _Alloc > &hm)
Reads an unordered_multimap from a FILE pointer.
Definition: DwmIO.hh:2185
static std::ostream & Write(std::ostream &os, const std::pair< _firstT, _secondT > &p)
Writes a pair<_firstT,_secondT> to an ostream. Returns the ostream.
Definition: DwmIO.hh:733
static ssize_t Write(int fd, const std::unordered_multimap< _keyT, _valueT, _Hash, _Pred, _Alloc > &m)
Writes an unordered_multimap<_keyT,_valueT> to a file descriptor.
Definition: DwmIO.hh:2173
static uint32_t StreamedLength(float val)
Returns the number of bytes that should be written if we call one of the Write() members for a float...
Definition: DwmIO.hh:224
static std::ostream & Write(std::ostream &os, const std::vector< _valueT, _Alloc > &v)
Writes a vector<_valueT> to an ostream. Returns the ostream.
Definition: DwmIO.hh:1008
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.
Definition: DwmIO.hh:848
static std::istream & Read(std::istream &is, std::tuple< T, Args... > &t)
Reads a tuple from an istream. Returns the istream.
Definition: DwmIO.hh:1391
static size_t Write(FILE *f, const std::unordered_map< _keyT, _valueT, _Hash, _Pred, _Alloc > &hm)
Writes an unordered_map to a FILE pointer.
Definition: DwmIO.hh:2109
static ssize_t Read(int fd, std::unordered_map< _keyT, _valueT, _Hash, _Pred, _Alloc > &m)
Reads an unordered_map<_keyT,_valueT> from a file descriptor.
Definition: DwmIO.hh:2072
This class defines an interface for classes that can write their contents to an ostream, file descriptor or FILE pointer.
Definition: DwmWritable.hh:58
static std::ostream & Write(std::ostream &os, const std::set< _valueT, _Compare, _Alloc > &l)
Writes a set<_valueT> to an ostream. Returns the ostream.
Definition: DwmIO.hh:1219
static uint32_t StreamedLength(char c)
Returns the number of bytes that would be written if we called Write() for a char.
Definition: DwmIO.hh:92
static ssize_t Read(int fd, std::unordered_multiset< _valueT, _Hash, _Pred, _Alloc > &m)
Reads an unordered_multiset<_valueT> from a file descriptor.
Definition: DwmIO.hh:2339
static uint32_t StreamedLength(const std::multimap< _keyT, _valueT, _Compare, _Alloc > &m)
Returns the number of bytes that should be written if we call one of the Write() members for a multim...
Definition: DwmIO.hh:907
static size_t Write(FILE *f, const std::tuple< T, Args... > &t)
Writes a tuple to a FILE. Returns 1 on success, 0 on failure.
Definition: DwmIO.hh:1440
static ssize_t Read(int fd, std::set< _valueT, _Compare, _Alloc > &l)
Reads a set<_valueT> from a file descriptor.
Definition: DwmIO.hh:1250
static size_t Write(FILE *f, const std::map< _keyT, _valueT, _Compare, _Alloc > &m)
Writes a map<_keyT,_valueT> to a FILE pointer.
Definition: DwmIO.hh:872
static uint32_t StreamedLength(const std::map< _keyT, _valueT, _Compare, _Alloc > &m)
Returns the number of bytes that should be written if we call one of the Write() members for a map<_k...
Definition: DwmIO.hh:827
This class defines an interface for classes that can read their contents from an istream, file descriptor or FILE pointer.
Definition: DwmReadable.hh:58
static size_t Write(FILE *f, const std::unordered_multimap< _keyT, _valueT, _Hash, _Pred, _Alloc > &hm)
Writes an unordered_multimap to a FILE pointer.
Definition: DwmIO.hh:2197
static uint32_t StreamedLength(const std::vector< _valueT, _Alloc > &v)
Returns the number of bytes that should be written if we call one of the Write() members for a vector...
Definition: DwmIO.hh:989
static std::istream & Read(std::istream &is, std::multimap< _keyT, _valueT, _Compare, _Alloc > &m)
Reads a multimap<_keyT,_valueT> from an istream.
Definition: DwmIO.hh:919
static uint32_t StreamedLength(const std::tuple< T, Args... > &t)
Returns the number of bytes that should be written if we call one of the Write() members for a tuple...
Definition: DwmIO.hh:1382
static size_t Write(FILE *f, const std::unordered_multiset< _valueT, _Hash, _Pred, _Alloc > &hm)
Writes an unordered_multiset to a FILE pointer.
Definition: DwmIO.hh:2375
static ssize_t Read(int fd, std::map< _keyT, _valueT, _Compare, _Alloc > &m)
Reads a map<_keyT,_valueT> from a file descriptor.
Definition: DwmIO.hh:883
static uint32_t StreamedLength(const std::list< _valueT, _Alloc > &l)
Returns the number of bytes that should be written if we call one of the Write() members for a list<_...
Definition: DwmIO.hh:1129
static ssize_t WriteTuple(int fd, const T &t)
T must be a tuple.
Definition: DwmIO.hh:1476
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.
Definition: DwmIO.hh:2059
static ssize_t Write(int fd, const std::unordered_map< _keyT, _valueT, _Hash, _Pred, _Alloc > &m)
Writes an unordered_map<_keyT,_valueT> to a file descriptor.
Definition: DwmIO.hh:2084
static std::istream & Read(std::istream &is, std::list< _valueT, _Alloc > &l)
Reads a list<_valueT> from an istream. Returns the istream.
Definition: DwmIO.hh:1138
static std::ostream & Write(std::ostream &os, const std::tuple< T, Args... > &t)
Writes a tuple to an ostream. Returns the ostream.
Definition: DwmIO.hh:1401
static ssize_t Read(int fd, std::vector< _valueT, _Alloc > &v)
Reads a vector<_valueT> from a file descriptor.
Definition: DwmIO.hh:1039
static size_t Write(FILE *f, const std::unordered_set< _valueT, _Hash, _Pred, _Alloc > &hm)
Writes an unordered_set to a FILE pointer.
Definition: DwmIO.hh:2286
static size_t Read(FILE *f, std::pair< _firstT, _secondT > &p)
Reads a pair<_firstT,_secondT> from a FILE pointer.
Definition: DwmIO.hh:749
static ssize_t Read(int fd, std::pair< _firstT, _secondT > &p)
Reads a pair<_firstT,_secondT> from a file descriptor.
Definition: DwmIO.hh:779
static ssize_t Read(int fd, std::multiset< _valueT, _Compare, _Alloc > &l)
Reads a multiset<_valueT> from a file descriptor.
Definition: DwmIO.hh:1323
static std::istream & Read(std::istream &is, Readable &val)
Wrapper function to read a Readable object from an istream.
Definition: DwmIO.hh:684
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.
Definition: DwmIO.hh:2135
static std::ostream & Write(std::ostream &os, const std::deque< _valueT, _Alloc > &d)
Writes a deque<_valueT> to an ostream. Returns the ostream.
Definition: DwmIO.hh:1078
static size_t Read(FILE *f, std::map< _keyT, _valueT, _Compare, _Alloc > &m)
Reads a map<_keyT,_valueT> from a FILE pointer.
Definition: DwmIO.hh:860
static ssize_t Write(int fd, const std::deque< _valueT, _Alloc > &d)
Writes a deque<_valueT> to a file descriptor.
Definition: DwmIO.hh:1119
A configure target for dealing with OS differences.
static uint32_t StreamedLength(uint32_t val)
Returns the number of bytes that would be written if we called one of the Write() members for a uint3...
Definition: DwmIO.hh:179