yat  0.21pre
BinaryIstreamIterator.h
1 #ifndef _theplu_yat_utility_binary_istream_iterator_
2 #define _theplu_yat_utility_binary_istream_iterator_
3 
4 // $Id: BinaryIstreamIterator.h 3902 2020-05-05 02:17:54Z peter $
5 
6 /*
7  Copyright (C) 2020 Peter Johansson
8 
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10 
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15 
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23 */
24 
25 #include "utility.h"
26 
27 #include <boost/iterator/iterator_facade.hpp>
28 
29 #include <iterator>
30 
31 namespace theplu {
32 namespace yat {
33 namespace utility {
34 
45  template<typename T>
47  : public boost::iterator_facade<
48  BinaryIstreamIterator<T>, const T, std::input_iterator_tag
49  >
50  {
51  public:
57  : istream_(NULL) {}
58 
64  explicit BinaryIstreamIterator(std::istream& is)
65  : istream_(&is)
66  {
67  increment();
68  }
69 
70  private:
71  friend class boost::iterator_core_access;
72 
73  std::istream* istream_;
74  T value_;
75 
76  typename BinaryIstreamIterator<T>::reference dereference(void) const
77  { return value_; }
78 
79  bool equal(const BinaryIstreamIterator<T>& other) const
80  { return istream_ == other.istream_; }
81 
82  void increment(void)
83  {
84  if (!istream_)
85  return;
86  if (!binary_read(*istream_, value_)) {
87  istream_ = NULL;
88  }
89  }
90  // Using compiler generated copy
91  //BinaryIstreamIterator(const BinaryIstreamIterator&);
92  //BinaryIstreamIterator& operator=(const BinaryIstreamIterator&);
93  };
94 
95 }}} // of namespace utility, yat, and theplu
96 
97 #endif
bool is(const std::string &s)
check if string is convertible to (numerical) type T
Definition: utility.h:733
BinaryIstreamIterator(std::istream &is)
Constructor.
Definition: BinaryIstreamIterator.h:64
The Department of Theoretical Physics namespace as we define it.
Some useful functions are placed here.
std::istream & binary_read(std::istream &is, T &x)
Definition: utility.h:90
BinaryIstreamIterator(void)
Definition: BinaryIstreamIterator.h:56
Definition: BinaryIstreamIterator.h:46

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14