47 #include <sys/types.h> 58 #include <unordered_map> 59 #include <unordered_set> 88 static int Write(gzFile gzf,
char c);
94 static int Write(gzFile gzf, uint8_t c);
101 static int Write(gzFile gzf, int16_t val);
108 static int Write(gzFile gzf, uint16_t val);
115 static int Write(gzFile gzf, int32_t val);
122 static int Write(gzFile gzf, uint32_t val);
129 static int Write(gzFile gzf,
const int64_t & val);
136 static int Write(gzFile gzf,
const uint64_t & val);
143 static int Write(gzFile gzf,
float val);
150 static int Write(gzFile gzf,
const double & val);
159 static int Write(gzFile gzf,
const std::string & s);
165 static int Read(gzFile gzf,
char & c);
171 static int Read(gzFile gzf, uint8_t & c);
177 static int Read(gzFile gzf, int16_t & val);
183 static int Read(gzFile gzf, uint16_t & val);
189 static int Read(gzFile gzf, int32_t & val);
195 static int Read(gzFile gzf, uint32_t & val);
201 static int Read(gzFile gzf, int64_t & val);
207 static int Read(gzFile gzf, uint64_t & val);
214 static int Read(gzFile gzf,
float & val);
221 static int Read(gzFile gzf,
double & val);
229 static int Read(gzFile gzf, std::string & s);
236 return(val.
Write(gzf));
244 return(val.
Read(gzf));
251 template <
typename _firstT,
typename _secondT>
252 static int Read(gzFile gzf, std::pair<_firstT, _secondT> & p)
256 int bytesRead =
Read(gzf, p.first);
259 bytesRead =
Read(gzf, p.second);
273 template <
typename _firstT,
typename _secondT>
274 static int Write(gzFile gzf,
const std::pair<_firstT,_secondT> & p)
278 int bytesWritten =
Write(gzf, p.first);
279 if (bytesWritten > 0) {
281 bytesWritten =
Write(gzf, p.second);
282 if (bytesWritten > 0) {
297 template <
typename _keyT,
typename _valueT,
298 typename _Compare,
typename _Alloc>
299 static int Read(gzFile gzf, std::map<_keyT, _valueT, _Compare, _Alloc> & m)
301 return(PairAssocContRead<std::map<_keyT, _valueT, _Compare, _Alloc> >(gzf, m));
308 template<
typename _keyT,
typename _valueT,
309 typename _Compare,
typename _Alloc>
311 Write(gzFile gzf,
const std::map<_keyT,_valueT,_Compare,_Alloc> & m)
313 return(ContainerWrite<std::map<_keyT,_valueT,_Compare,_Alloc> >(gzf, m));
320 template <
typename _keyT,
typename _valueT,
321 typename _Compare,
typename _Alloc>
323 Read(gzFile gzf, std::multimap<_keyT, _valueT, _Compare, _Alloc> & m)
325 return(PairAssocContRead<std::multimap<_keyT,_valueT,_Compare,_Alloc> >(gzf, m));
332 template <
typename _keyT,
typename _valueT,
333 typename _Compare,
typename _Alloc>
335 Write(gzFile gzf,
const std::multimap<_keyT,_valueT, _Compare, _Alloc> & m)
337 return(ContainerWrite<std::multimap<_keyT,_valueT,_Compare,_Alloc> >(gzf, m));
344 template <
typename _valueT,
typename _Alloc>
345 static int Read(gzFile gzf, std::vector<_valueT, _Alloc> & v)
347 return(ContainerRead<std::vector<_valueT, _Alloc> >(gzf, v));
354 template <
typename _valueT,
typename _Alloc>
355 static int Write(gzFile gzf,
const std::vector<_valueT, _Alloc> & v)
357 return(ContainerWrite<std::vector<_valueT, _Alloc> >(gzf, v));
364 template <
typename _valueT,
typename _Alloc>
365 static int Read(gzFile gzf, std::deque<_valueT, _Alloc> & d)
367 return(ContainerRead<std::deque<_valueT, _Alloc> >(gzf, d));
374 template <
typename _valueT,
typename _Alloc>
375 static int Write(gzFile gzf,
const std::deque<_valueT, _Alloc> & d)
377 return(ContainerWrite<std::deque<_valueT, _Alloc> >(gzf, d));
384 template <
typename _valueT,
typename _Alloc>
385 static int Read(gzFile gzf, std::list<_valueT, _Alloc> & l)
387 return(ContainerRead<std::list<_valueT, _Alloc> >(gzf, l));
394 template <
typename _valueT,
typename _Alloc>
395 static int Write(gzFile gzf,
const std::list<_valueT, _Alloc> & l)
397 return(ContainerWrite<std::list<_valueT, _Alloc> >(gzf, l));
404 template <
typename _valueT,
typename _Compare,
typename _Alloc>
405 static int Read(gzFile gzf, std::set<_valueT, _Compare, _Alloc> & l)
407 return(ContainerRead<std::set<_valueT, _Compare, _Alloc> >(gzf, l));
414 template <
typename _valueT,
typename _Compare,
typename _Alloc>
415 static int Write(gzFile gzf,
const std::set<_valueT, _Compare, _Alloc> & l)
417 return(ContainerWrite<std::set<_valueT, _Compare, _Alloc> >(gzf, l));
424 template <
typename _valueT,
typename _Compare,
typename _Alloc>
425 static int Read(gzFile gzf, std::multiset<_valueT, _Compare, _Alloc> & l)
427 return(ContainerRead<std::multiset<_valueT, _Compare, _Alloc> >(gzf, l));
434 template <
typename _valueT,
typename _Compare,
typename _Alloc>
436 Write(gzFile gzf,
const std::multiset<_valueT, _Compare, _Alloc> & l)
438 return(ContainerWrite<std::multiset<_valueT, _Compare, _Alloc> >(gzf, l));
444 template <
typename T,
typename... Args>
445 static int Write(gzFile gzf,
const std::tuple<T, Args...> & t)
447 return(
WriteTuple<std::tuple<T, Args...> >(gzf, t));
453 template <
typename T,
typename... Args>
454 static int Read(gzFile gzf, std::tuple<T, Args...> & t)
456 return(
ReadTuple<std::tuple<T, Args...> >(gzf, t));
462 template <
typename T>
465 return(TupleIOHelper<T,std::tuple_size<T>::value-1>::
Write(gzf, t));
471 template <
typename T>
474 return(TupleIOHelper<T,std::tuple_size<T>::value-1>::
Read(gzf, t));
481 template<
typename _keyT,
typename _valueT,
typename _Hash,
482 typename _Pred,
typename _Alloc>
484 Read(gzFile gzf, std::unordered_map<_keyT,_valueT,_Hash,_Pred,_Alloc> & hm)
486 return(PairAssocContRead<std::unordered_map<_keyT,_valueT,_Hash,_Pred,_Alloc> >(gzf, hm));
493 template<
typename _keyT,
typename _valueT,
typename _Hash,
494 typename _Pred,
typename _Alloc>
497 const std::unordered_map<_keyT,_valueT,_Hash,_Pred,_Alloc> & hm)
499 return(ContainerWrite<std::unordered_map<_keyT,_valueT,_Hash,_Pred,_Alloc> >(gzf, hm));
506 template<
typename _valueT,
typename _Hash,
507 typename _Pred,
typename _Alloc>
509 Read(gzFile gzf, std::unordered_set<_valueT,_Hash,_Pred,_Alloc> & hm)
511 return(ContainerRead<std::unordered_set<_valueT,_Hash,_Pred,_Alloc> >(gzf, hm));
518 template<
typename _valueT,
typename _Hash,
519 typename _Pred,
typename _Alloc>
522 const std::unordered_set<_valueT,_Hash,_Pred,_Alloc> & hm)
524 return(ContainerWrite<std::unordered_set<_valueT,_Hash,_Pred,_Alloc> >(gzf, hm));
531 template<
typename _keyT,
typename _valueT,
typename _Hash,
532 typename _Pred,
typename _Alloc>
534 Read(gzFile gzf, std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc> & hm)
536 return(PairAssocContRead<std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc> >(gzf, hm));
543 template<
typename _keyT,
typename _valueT,
typename _Hash,
544 typename _Pred,
typename _Alloc>
547 const std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc> & hm)
549 return(ContainerWrite<std::unordered_multimap<_keyT,_valueT,_Hash,_Pred,_Alloc> >(gzf, hm));
556 template<
typename _valueT,
typename _Hash,
557 typename _Pred,
typename _Alloc>
559 Read(gzFile gzf, std::unordered_multiset<_valueT,_Hash,_Pred,_Alloc> & hm)
561 return(ContainerRead<std::unordered_multiset<_valueT,_Hash,_Pred,_Alloc> >(gzf, hm));
568 template<
typename _valueT,
typename _Hash,
569 typename _Pred,
typename _Alloc>
572 const std::unordered_multiset<_valueT,_Hash,_Pred,_Alloc> & hm)
574 return(ContainerWrite<std::unordered_multiset<_valueT,_Hash,_Pred,_Alloc> >(gzf, hm));
581 template <
typename _inputIteratorT>
582 static int Write(gzFile gzf, _inputIteratorT f, _inputIteratorT l)
586 for ( ; f != l; ++f) {
587 int bytesWritten =
Write(gzf, *f);
588 if (bytesWritten > 0) {
605 template <
typename _containerT>
606 static int ContainerRead(gzFile gzf, _containerT & c)
613 int bytesRead =
Read(gzf, numEntries);
614 if (bytesRead ==
sizeof(numEntries)) {
616 for (uint32_t i = 0; i < numEntries; ++i) {
617 typename _containerT::value_type val;
618 bytesRead =
Read(gzf, val);
621 c.insert(c.end(), val);
638 template <
typename _containerT>
639 static int ContainerWrite(gzFile gzf,
const _containerT & c)
643 uint32_t numEntries = c.size();
644 uint32_t bytesWritten =
Write(gzf, numEntries);
645 if (bytesWritten ==
sizeof(numEntries)) {
649 Write<typename _containerT::const_iterator>(gzf,
652 if (bytesWritten > 0)
667 template <
typename _containerT>
668 static int PairAssocContRead(gzFile gzf, _containerT & m)
675 int bytesRead =
Read(gzf, numEntries);
676 if (bytesRead ==
sizeof(numEntries)) {
678 for (uint32_t i = 0; i < numEntries; ++i) {
679 typename _containerT::key_type key;
680 bytesRead =
Read(gzf, key);
683 typename _containerT::mapped_type val;
684 bytesRead =
Read(gzf, val);
687 m.insert(
typename _containerT::value_type(key, val));
708 template <
typename T,
size_t elt>
714 template <
typename T>
715 class TupleIOHelper<T, 0>
721 static int Write(gzFile gzf,
const T & t)
729 static int Read(gzFile gzf, T & t)
738 template <
typename T,
size_t elt>
745 static int Write(gzFile gzf,
const T & t)
747 int rc = TupleIOHelper<T,elt-1>::Write(gzf, t);
763 static int Read(gzFile gzf, T & t)
765 int rc = TupleIOHelper<T,elt-1>::Read(gzf, t);
784 #endif // _DWMGZIO_HH_ static int Read(gzFile gzf, std::set< _valueT, _Compare, _Alloc > &l)
Reads a set<_valueT> from a gzFile.
Definition: DwmGZIO.hh:405
static int Write(gzFile gzf, const std::unordered_map< _keyT, _valueT, _Hash, _Pred, _Alloc > &hm)
Writes an unordered_map to a gzFile.
Definition: DwmGZIO.hh:496
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition: DwmGZWritable.hh:57
static int Read(gzFile gzf, std::pair< _firstT, _secondT > &p)
Reads a pair<_firstT,_secondT> from a gzFile.
Definition: DwmGZIO.hh:252
static int Write(gzFile gzf, const GZWritable &val)
Wrapper function to write a GZWritable object to a gzFile.
Definition: DwmGZIO.hh:234
static int Read(gzFile gzf, std::unordered_set< _valueT, _Hash, _Pred, _Alloc > &hm)
Reads an unordered_set from a gzFile.
Definition: DwmGZIO.hh:509
Dwm::GZReadable pure virtual class definition.
static int Read(gzFile gzf, std::list< _valueT, _Alloc > &l)
Reads a list<_valueT> from a gzFile.
Definition: DwmGZIO.hh:385
static int Write(gzFile gzf, const std::vector< _valueT, _Alloc > &v)
Writes a vector<_valueT> to a gzFile.
Definition: DwmGZIO.hh:355
static int Read(gzFile gzf, std::multimap< _keyT, _valueT, _Compare, _Alloc > &m)
Reads a multimap<_keyT,_valueT> from a gzFile.
Definition: DwmGZIO.hh:323
static int Write(gzFile gzf, const std::unordered_set< _valueT, _Hash, _Pred, _Alloc > &hm)
Writes an unordered_set to a gzFile.
Definition: DwmGZIO.hh:521
static int WriteTuple(gzFile gzf, const T &t)
T must be a tuple, n is the number of elements.
Definition: DwmGZIO.hh:463
virtual int Read(gzFile gzf)=0
Read from a gzFile.
virtual int Write(gzFile gzf) const =0
Write to a gzFile.
static int Write(gzFile gzf, const std::deque< _valueT, _Alloc > &d)
Writes a deque<_valueT> to a gzFile.
Definition: DwmGZIO.hh:375
static int Write(gzFile gzf, char c)
Writes c to gzf.
static int Read(gzFile gzf, char &c)
Reads from gzf.
This class contains a collection of static functions for reading and writing simple types in network ...
Definition: DwmGZIO.hh:81
static int Write(gzFile gzf, const std::list< _valueT, _Alloc > &l)
Writes a list<_valueT> to a gzFile.
Definition: DwmGZIO.hh:395
static int Read(gzFile gzf, GZReadable &val)
Wrapper function to read a GZReadable object from a gzFile.
Definition: DwmGZIO.hh:242
Definition: DwmBZ2IO.hh:67
This class is a pure virtual class, defining an interface for classes that can read their contents fr...
Definition: DwmGZReadable.hh:57
static int Write(gzFile gzf, const std::unordered_multiset< _valueT, _Hash, _Pred, _Alloc > &hm)
Writes an unordered_multiset to a gzFile.
Definition: DwmGZIO.hh:571
static int Write(gzFile gzf, const std::multiset< _valueT, _Compare, _Alloc > &l)
Writes a multiset<_valueT> to a gzFile.
Definition: DwmGZIO.hh:436
static int Write(gzFile gzf, const std::multimap< _keyT, _valueT, _Compare, _Alloc > &m)
Writes a multimap<_keyT,_valueT> to a gzFile.
Definition: DwmGZIO.hh:335
static int Read(gzFile gzf, std::vector< _valueT, _Alloc > &v)
Reads a vector<_valueT> from a gzFile.
Definition: DwmGZIO.hh:345
static int Read(gzFile gzf, std::multiset< _valueT, _Compare, _Alloc > &l)
Reads a multiset<_valueT> from a gzFile.
Definition: DwmGZIO.hh:425
static int Read(gzFile gzf, std::deque< _valueT, _Alloc > &d)
Reads a deque<_valueT> from a gzFile.
Definition: DwmGZIO.hh:365
Dwm::GZWritable pure virtual class definition.
static int Write(gzFile gzf, const std::set< _valueT, _Compare, _Alloc > &l)
Writes a set<_valueT> to a gzFile.
Definition: DwmGZIO.hh:415
static int ReadTuple(gzFile gzf, T &t)
T must be a tuple, n is the number of elements.
Definition: DwmGZIO.hh:472
static int Write(gzFile gzf, const std::unordered_multimap< _keyT, _valueT, _Hash, _Pred, _Alloc > &hm)
Writes an unordered_multimap to a gzFile.
Definition: DwmGZIO.hh:546
static int Read(gzFile gzf, std::unordered_map< _keyT, _valueT, _Hash, _Pred, _Alloc > &hm)
Reads an unordered_map from a gzFile.
Definition: DwmGZIO.hh:484
static int Write(gzFile gzf, const std::pair< _firstT, _secondT > &p)
Writes a pair<_firstT,_secondT> to a gzFile.
Definition: DwmGZIO.hh:274
static int Read(gzFile gzf, std::unordered_multimap< _keyT, _valueT, _Hash, _Pred, _Alloc > &hm)
Reads an unordered_multimap from a gzFile.
Definition: DwmGZIO.hh:534
static int Read(gzFile gzf, std::map< _keyT, _valueT, _Compare, _Alloc > &m)
Reads a map<_keyT,_valueT> from a gzFile.
Definition: DwmGZIO.hh:299
static int Write(gzFile gzf, const std::map< _keyT, _valueT, _Compare, _Alloc > &m)
Writes a map<_keyT,_valueT> to a gzFile.
Definition: DwmGZIO.hh:311
A configure target for dealing with OS differences.
static int Read(gzFile gzf, std::unordered_multiset< _valueT, _Hash, _Pred, _Alloc > &hm)
Reads an unordered_multiset from a gzFile.
Definition: DwmGZIO.hh:559