CMS 3D CMS Logo

bstream_iterator.h
Go to the documentation of this file.
1 #ifndef bstream_iterator_H
2 #define bstream_iterator_H
3 
4 #include "binary_ifstream.h"
5 #include "binary_ofstream.h"
6 #include <iterator>
8 
9 template <typename T>
11  public std::iterator<std::input_iterator_tag, T, ptrdiff_t, const T*, const T&>
12 {
13 public:
14 
16 
18  read();
19  }
20 
21  const T& operator*() const {return value_;}
22 
23  const T* operator->() const {return &value_;}
24 
25  bistream_iterator& operator++() {read(); return *this;}
26 
29  read();
30  return tmp;
31  }
32 
33  bool operator==(const bistream_iterator& rhs) {
34  return stream_ == rhs.stream_;
35  }
36 
37  bool operator!=(const bistream_iterator& rhs) {
38  return !operator==(rhs);
39  }
40 
41 private:
42 
45 
46  void read() {
47  if (stream_ != 0) {
48  // if (!(*stream_ >> value_)) stream_ = 0;
49  if (!(*stream_ >> value_)) {
50  stream_ = 0;
51  // std::cout << "istream_iterator: stream turned bad, set stream_ to zero" << std::endl;
52  }
53  }
54  }
55 
56 };
57 
58 template <typename T>
60  public std::iterator<std::output_iterator_tag,void,void,void,void> {
61 public:
62 
64 
66  *stream_ << t;
67  return *this;
68  }
69 
70  bostream_iterator& operator*() {return *this;}
71  bostream_iterator& operator++() {return *this;}
72  bostream_iterator& operator++(int) {return *this;}
73 
74 private:
75 
77 
78 };
79 
80 #endif
bostream_iterator & operator++(int)
bool operator!=(const bistream_iterator &rhs)
bostream_iterator & operator=(const T &t)
const T & operator*() const
bistream_iterator & operator++(int)
bostream_iterator & operator++()
binary_ifstream * stream_
const T * operator->() const
#define dso_internal
Definition: Visibility.h:13
bostream_iterator & operator*()
binary_ofstream * stream_
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
long double T
bistream_iterator(binary_ifstream &s)
bistream_iterator & operator++()
bool operator==(const bistream_iterator &rhs)
bostream_iterator(binary_ofstream &s)