/Src/Dependencies/Boost/boost/archive/impl/basic_text_iprimitive.ipp

http://hadesmem.googlecode.com/ · C++ Header · 154 lines · 121 code · 22 blank · 11 comment · 10 complexity · 96816dadd65c31686c7fc01d822f0475 MD5 · raw file

  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. // basic_text_iprimitive.ipp:
  3. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. // See http://www.boost.org for updates, documentation, and revision history.
  8. #include <cstddef> // size_t
  9. #include <cstddef> // NULL
  10. #include <boost/config.hpp>
  11. #if defined(BOOST_NO_STDC_NAMESPACE)
  12. namespace std{
  13. using ::size_t;
  14. } // namespace std
  15. #endif
  16. #include <boost/serialization/throw_exception.hpp>
  17. #include <boost/serialization/pfto.hpp>
  18. #include <boost/archive/basic_text_iprimitive.hpp>
  19. #include <boost/archive/codecvt_null.hpp>
  20. #include <boost/archive/add_facet.hpp>
  21. #include <boost/archive/iterators/remove_whitespace.hpp>
  22. #include <boost/archive/iterators/istream_iterator.hpp>
  23. #include <boost/archive/iterators/binary_from_base64.hpp>
  24. #include <boost/archive/iterators/transform_width.hpp>
  25. namespace boost {
  26. namespace archive {
  27. namespace {
  28. template<class CharType>
  29. bool is_whitespace(CharType c);
  30. template<>
  31. bool is_whitespace(char t){
  32. return 0 != std::isspace(t);
  33. }
  34. #ifndef BOOST_NO_CWCHAR
  35. template<>
  36. bool is_whitespace(wchar_t t){
  37. return 0 != std::iswspace(t);
  38. }
  39. #endif
  40. }
  41. // translate base64 text into binary and copy into buffer
  42. // until buffer is full.
  43. template<class IStream>
  44. BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
  45. basic_text_iprimitive<IStream>::load_binary(
  46. void *address,
  47. std::size_t count
  48. ){
  49. typedef BOOST_DEDUCED_TYPENAME IStream::char_type CharType;
  50. if(0 == count)
  51. return;
  52. BOOST_ASSERT(
  53. static_cast<std::size_t>((std::numeric_limits<std::streamsize>::max)())
  54. > (count + sizeof(CharType) - 1)/sizeof(CharType)
  55. );
  56. if(is.fail())
  57. boost::serialization::throw_exception(
  58. archive_exception(archive_exception::input_stream_error)
  59. );
  60. // convert from base64 to binary
  61. typedef BOOST_DEDUCED_TYPENAME
  62. iterators::transform_width<
  63. iterators::binary_from_base64<
  64. iterators::remove_whitespace<
  65. iterators::istream_iterator<CharType>
  66. >
  67. ,CharType
  68. >
  69. ,8
  70. ,6
  71. ,CharType
  72. >
  73. binary;
  74. binary ti_begin = binary(
  75. BOOST_MAKE_PFTO_WRAPPER(
  76. iterators::istream_iterator<CharType>(is)
  77. )
  78. );
  79. char * caddr = static_cast<char *>(address);
  80. // take care that we don't increment anymore than necessary
  81. while(--count > 0){
  82. *caddr++ = static_cast<char>(*ti_begin);
  83. ++ti_begin;
  84. }
  85. *caddr++ = static_cast<char>(*ti_begin);
  86. iterators::istream_iterator<CharType> i;
  87. for(;;){
  88. BOOST_DEDUCED_TYPENAME IStream::int_type r;
  89. r = is.get();
  90. if(is.eof())
  91. break;
  92. if(is_whitespace(static_cast<CharType>(r)))
  93. break;
  94. }
  95. }
  96. template<class IStream>
  97. BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
  98. basic_text_iprimitive<IStream>::basic_text_iprimitive(
  99. IStream &is_,
  100. bool no_codecvt
  101. ) :
  102. #ifndef BOOST_NO_STD_LOCALE
  103. is(is_),
  104. flags_saver(is_),
  105. precision_saver(is_),
  106. archive_locale(NULL),
  107. locale_saver(* is_.rdbuf())
  108. {
  109. if(! no_codecvt){
  110. archive_locale.reset(
  111. add_facet(
  112. std::locale::classic(),
  113. new codecvt_null<BOOST_DEDUCED_TYPENAME IStream::char_type>
  114. )
  115. );
  116. is.imbue(* archive_locale);
  117. }
  118. is >> std::noboolalpha;
  119. }
  120. #else
  121. is(is_),
  122. flags_saver(is_),
  123. precision_saver(is_)
  124. {}
  125. #endif
  126. template<class IStream>
  127. BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
  128. basic_text_iprimitive<IStream>::~basic_text_iprimitive(){
  129. is.sync();
  130. }
  131. } // namespace archive
  132. } // namespace boost