3902 |
05 May 20 |
peter |
1 |
#ifndef _theplu_yat_utility_binary_ostream_iterator |
3902 |
05 May 20 |
peter |
2 |
#define _theplu_yat_utility_binary_ostream_iterator |
3902 |
05 May 20 |
peter |
3 |
|
3902 |
05 May 20 |
peter |
// $Id$ |
3902 |
05 May 20 |
peter |
5 |
|
3902 |
05 May 20 |
peter |
6 |
/* |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2020, 2022 Peter Johansson |
3902 |
05 May 20 |
peter |
8 |
|
3902 |
05 May 20 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
3902 |
05 May 20 |
peter |
10 |
|
3902 |
05 May 20 |
peter |
The yat library is free software; you can redistribute it and/or |
3902 |
05 May 20 |
peter |
modify it under the terms of the GNU General Public License as |
3902 |
05 May 20 |
peter |
published by the Free Software Foundation; either version 3 of the |
3902 |
05 May 20 |
peter |
License, or (at your option) any later version. |
3902 |
05 May 20 |
peter |
15 |
|
3902 |
05 May 20 |
peter |
The yat library is distributed in the hope that it will be useful, |
3902 |
05 May 20 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
3902 |
05 May 20 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3902 |
05 May 20 |
peter |
General Public License for more details. |
3902 |
05 May 20 |
peter |
20 |
|
3902 |
05 May 20 |
peter |
You should have received a copy of the GNU General Public License |
3902 |
05 May 20 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
3902 |
05 May 20 |
peter |
23 |
*/ |
3902 |
05 May 20 |
peter |
24 |
|
3902 |
05 May 20 |
peter |
25 |
#include "utility.h" |
3902 |
05 May 20 |
peter |
26 |
|
4252 |
18 Nov 22 |
peter |
27 |
#include <boost/iterator/function_output_iterator.hpp> |
3902 |
05 May 20 |
peter |
28 |
|
3902 |
05 May 20 |
peter |
29 |
namespace theplu { |
3902 |
05 May 20 |
peter |
30 |
namespace yat { |
3902 |
05 May 20 |
peter |
31 |
namespace utility { |
3902 |
05 May 20 |
peter |
32 |
|
3902 |
05 May 20 |
peter |
33 |
namespace detail { |
3902 |
05 May 20 |
peter |
/// \cond IGNORE_DOXYGEN |
3902 |
05 May 20 |
peter |
35 |
template <typename T> |
3902 |
05 May 20 |
peter |
36 |
class BinaryWriter |
3902 |
05 May 20 |
peter |
37 |
{ |
3902 |
05 May 20 |
peter |
38 |
public: |
3902 |
05 May 20 |
peter |
39 |
BinaryWriter(std::ostream& os) |
3902 |
05 May 20 |
peter |
40 |
: out_(&os) {} |
3902 |
05 May 20 |
peter |
41 |
|
3902 |
05 May 20 |
peter |
42 |
void operator()(T x) const |
3902 |
05 May 20 |
peter |
43 |
{ |
3902 |
05 May 20 |
peter |
44 |
binary_write(*out_, x); |
3902 |
05 May 20 |
peter |
45 |
} |
3902 |
05 May 20 |
peter |
46 |
private: |
3902 |
05 May 20 |
peter |
47 |
std::ostream* out_; |
3902 |
05 May 20 |
peter |
48 |
}; |
3902 |
05 May 20 |
peter |
/// \endcond |
3902 |
05 May 20 |
peter |
50 |
} // end detail namespace |
3902 |
05 May 20 |
peter |
51 |
|
3902 |
05 May 20 |
peter |
52 |
/** |
3902 |
05 May 20 |
peter |
An iterator that can be used to write a range of data into an \c |
3902 |
05 May 20 |
peter |
ostream in binary format using binary_write(std::ostream&, |
3902 |
05 May 20 |
peter |
T). BinaryOstreamIterator models an \output_iterator. |
3902 |
05 May 20 |
peter |
56 |
|
3902 |
05 May 20 |
peter |
\since New in yat 0.18 |
3902 |
05 May 20 |
peter |
58 |
*/ |
3902 |
05 May 20 |
peter |
59 |
template <typename T> |
3902 |
05 May 20 |
peter |
60 |
class BinaryOstreamIterator |
3902 |
05 May 20 |
peter |
61 |
: public boost::function_output_iterator<detail::BinaryWriter<T> > |
3902 |
05 May 20 |
peter |
62 |
{ |
3902 |
05 May 20 |
peter |
63 |
public: |
3902 |
05 May 20 |
peter |
64 |
/** |
3902 |
05 May 20 |
peter |
Create an iterator that writes to \a os. |
3902 |
05 May 20 |
peter |
66 |
*/ |
3902 |
05 May 20 |
peter |
67 |
explicit BinaryOstreamIterator(std::ostream& os) |
3902 |
05 May 20 |
peter |
68 |
: boost::function_output_iterator<detail::BinaryWriter<T> >(detail::BinaryWriter<T>(os)) {} |
3902 |
05 May 20 |
peter |
69 |
|
3902 |
05 May 20 |
peter |
70 |
private: |
3902 |
05 May 20 |
peter |
// Using compiler generated copy |
3902 |
05 May 20 |
peter |
//BinaryOstreamIterator(const BinaryOstreamIterator&); |
3902 |
05 May 20 |
peter |
//BinaryOstreamIterator& operator=(const BinaryOstreamIterator&); |
3902 |
05 May 20 |
peter |
74 |
}; |
3902 |
05 May 20 |
peter |
75 |
|
3902 |
05 May 20 |
peter |
76 |
}}} // of namespace utility, yat, and theplu |
3902 |
05 May 20 |
peter |
77 |
|
3902 |
05 May 20 |
peter |
78 |
#endif |