1 | #ifndef BOOST_ARCHIVE_ITERATORS_INSERT_LINEBREAKS_HPP
|
---|
2 | #define BOOST_ARCHIVE_ITERATORS_INSERT_LINEBREAKS_HPP
|
---|
3 |
|
---|
4 | // MS compatible compilers support #pragma once
|
---|
5 | #if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
---|
6 | # pragma once
|
---|
7 | #endif
|
---|
8 |
|
---|
9 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
---|
10 | // binary_from_base64.hpp
|
---|
11 |
|
---|
12 | // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
|
---|
13 | // Use, modification and distribution is subject to the Boost Software
|
---|
14 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
---|
15 | // http://www.boost.org/LICENSE_1_0.txt)
|
---|
16 |
|
---|
17 | // See http://www.boost.org for updates, documentation, and revision history.
|
---|
18 |
|
---|
19 | #include <cassert>
|
---|
20 |
|
---|
21 | #include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
|
---|
22 | #if defined(BOOST_NO_STDC_NAMESPACE)
|
---|
23 | namespace std{ using ::memcpy; }
|
---|
24 | #endif
|
---|
25 |
|
---|
26 | #include <boost/pfto.hpp>
|
---|
27 |
|
---|
28 | #include <boost/iterator/iterator_adaptor.hpp>
|
---|
29 | #include <boost/iterator/iterator_traits.hpp>
|
---|
30 |
|
---|
31 | namespace boost {
|
---|
32 | namespace archive {
|
---|
33 | namespace iterators {
|
---|
34 |
|
---|
35 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
---|
36 | // insert line break every N characters
|
---|
37 | template<
|
---|
38 | class Base,
|
---|
39 | int N,
|
---|
40 | class CharType = BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type
|
---|
41 | >
|
---|
42 | class insert_linebreaks :
|
---|
43 | public iterator_adaptor<
|
---|
44 | insert_linebreaks<Base, N, CharType>,
|
---|
45 | Base,
|
---|
46 | CharType,
|
---|
47 | single_pass_traversal_tag,
|
---|
48 | CharType
|
---|
49 | >
|
---|
50 | {
|
---|
51 | private:
|
---|
52 | friend class boost::iterator_core_access;
|
---|
53 | typedef iterator_adaptor<
|
---|
54 | insert_linebreaks<Base, N, CharType>,
|
---|
55 | Base,
|
---|
56 | CharType,
|
---|
57 | single_pass_traversal_tag,
|
---|
58 | CharType
|
---|
59 | > super_t;
|
---|
60 |
|
---|
61 | bool equal(const insert_linebreaks<Base, N, CharType> & rhs) const {
|
---|
62 | return
|
---|
63 | // m_count == rhs.m_count
|
---|
64 | // && base_reference() == rhs.base_reference()
|
---|
65 | this->base_reference() == rhs.base_reference()
|
---|
66 | ;
|
---|
67 | }
|
---|
68 |
|
---|
69 | void increment() {
|
---|
70 | if(m_count == N){
|
---|
71 | m_count = 0;
|
---|
72 | return;
|
---|
73 | }
|
---|
74 | ++m_count;
|
---|
75 | ++(this->base_reference());
|
---|
76 | }
|
---|
77 | CharType dereference() const {
|
---|
78 | if(m_count == N)
|
---|
79 | return '\n';
|
---|
80 | return * (this->base_reference());
|
---|
81 | }
|
---|
82 | unsigned int m_count;
|
---|
83 | public:
|
---|
84 | // make composible buy using templated constructor
|
---|
85 | template<class T>
|
---|
86 | insert_linebreaks(BOOST_PFTO_WRAPPER(T) start) :
|
---|
87 | super_t(Base(BOOST_MAKE_PFTO_WRAPPER(static_cast<T>(start)))),
|
---|
88 | m_count(0)
|
---|
89 | {}
|
---|
90 | // intel 7.1 doesn't like default copy constructor
|
---|
91 | insert_linebreaks(const insert_linebreaks & rhs) :
|
---|
92 | super_t(rhs.base_reference()),
|
---|
93 | m_count(rhs.m_count)
|
---|
94 | {}
|
---|
95 | };
|
---|
96 |
|
---|
97 | } // namespace iterators
|
---|
98 | } // namespace archive
|
---|
99 | } // namespace boost
|
---|
100 |
|
---|
101 | #endif // BOOST_ARCHIVE_ITERATORS_INSERT_LINEBREAKS_HPP
|
---|