insert_linebreaks.hpp 2.6 KB

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