insert_linebreaks.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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) && (_MSC_VER >= 1020)
  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 <cassert>
  15. #include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
  16. #if defined(BOOST_NO_STDC_NAMESPACE)
  17. namespace std{ using ::memcpy; }
  18. #endif
  19. #include <boost/serialization/pfto.hpp>
  20. #include <boost/iterator/iterator_adaptor.hpp>
  21. #include <boost/iterator/iterator_traits.hpp>
  22. namespace boost {
  23. namespace archive {
  24. namespace iterators {
  25. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  26. // insert line break every N characters
  27. template<
  28. class Base,
  29. int N,
  30. class CharType = BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type
  31. >
  32. class insert_linebreaks :
  33. public iterator_adaptor<
  34. insert_linebreaks<Base, N, CharType>,
  35. Base,
  36. CharType,
  37. single_pass_traversal_tag,
  38. CharType
  39. >
  40. {
  41. private:
  42. friend class boost::iterator_core_access;
  43. typedef iterator_adaptor<
  44. insert_linebreaks<Base, N, CharType>,
  45. Base,
  46. CharType,
  47. single_pass_traversal_tag,
  48. CharType
  49. > super_t;
  50. bool equal(const insert_linebreaks<Base, N, CharType> & rhs) const {
  51. return
  52. // m_count == rhs.m_count
  53. // && base_reference() == rhs.base_reference()
  54. this->base_reference() == rhs.base_reference()
  55. ;
  56. }
  57. void increment() {
  58. if(m_count == N){
  59. m_count = 0;
  60. return;
  61. }
  62. ++m_count;
  63. ++(this->base_reference());
  64. }
  65. CharType dereference() const {
  66. if(m_count == N)
  67. return '\n';
  68. return * (this->base_reference());
  69. }
  70. unsigned int m_count;
  71. public:
  72. // make composible buy using templated constructor
  73. template<class T>
  74. insert_linebreaks(BOOST_PFTO_WRAPPER(T) start) :
  75. super_t(Base(BOOST_MAKE_PFTO_WRAPPER(static_cast<T>(start)))),
  76. m_count(0)
  77. {}
  78. // intel 7.1 doesn't like default copy constructor
  79. insert_linebreaks(const insert_linebreaks & rhs) :
  80. super_t(rhs.base_reference()),
  81. m_count(rhs.m_count)
  82. {}
  83. };
  84. } // namespace iterators
  85. } // namespace archive
  86. } // namespace boost
  87. #endif // BOOST_ARCHIVE_ITERATORS_INSERT_LINEBREAKS_HPP