• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)
6 # pragma once
7 #endif
8 
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // insert_linebreaks.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 <boost/assert.hpp>
20 
21 #include <boost/config.hpp>
22 #if defined(BOOST_NO_STDC_NAMESPACE)
23 namespace std{ using ::memcpy; }
24 #endif
25 
26 #include <boost/iterator/iterator_adaptor.hpp>
27 #include <boost/iterator/iterator_traits.hpp>
28 
29 namespace boost {
30 namespace archive {
31 namespace iterators {
32 
33 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
34 // insert line break every N characters
35 template<
36     class Base,
37     int N,
38     class CharType = typename boost::iterator_value<Base>::type
39 >
40 class insert_linebreaks :
41     public iterator_adaptor<
42         insert_linebreaks<Base, N, CharType>,
43         Base,
44         CharType,
45         single_pass_traversal_tag,
46         CharType
47     >
48 {
49 private:
50     friend class boost::iterator_core_access;
51     typedef iterator_adaptor<
52         insert_linebreaks<Base, N, CharType>,
53         Base,
54         CharType,
55         single_pass_traversal_tag,
56         CharType
57     > super_t;
58 
equal(const insert_linebreaks<Base,N,CharType> & rhs) const59     bool equal(const insert_linebreaks<Base, N, CharType> & rhs) const {
60         return
61 //            m_count == rhs.m_count
62 //            && base_reference() == rhs.base_reference()
63             this->base_reference() == rhs.base_reference()
64         ;
65     }
66 
increment()67     void increment() {
68         if(m_count == N){
69             m_count = 0;
70             return;
71         }
72         ++m_count;
73         ++(this->base_reference());
74     }
dereference() const75     CharType dereference() const {
76         if(m_count == N)
77             return '\n';
78         return * (this->base_reference());
79     }
80     unsigned int m_count;
81 public:
82     // make composible buy using templated constructor
83     template<class T>
insert_linebreaks(T start)84     insert_linebreaks(T  start) :
85         super_t(Base(static_cast< T >(start))),
86         m_count(0)
87     {}
88     // intel 7.1 doesn't like default copy constructor
insert_linebreaks(const insert_linebreaks & rhs)89     insert_linebreaks(const insert_linebreaks & rhs) :
90         super_t(rhs.base_reference()),
91         m_count(rhs.m_count)
92     {}
93 };
94 
95 } // namespace iterators
96 } // namespace archive
97 } // namespace boost
98 
99 #endif // BOOST_ARCHIVE_ITERATORS_INSERT_LINEBREAKS_HPP
100