basic_text_iprimitive.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #ifndef BOOST_ARCHIVE_BASIC_TEXT_IPRIMITIVE_HPP
  2. #define BOOST_ARCHIVE_BASIC_TEXT_IPRIMITIVE_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. // basic_text_iprimitive.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. // archives stored as text - note these are templated on the basic
  15. // stream templates to accommodate wide (and other?) kind of characters
  16. //
  17. // Note the fact that on libraries without wide characters, ostream is
  18. // not a specialization of basic_ostream which in fact is not defined
  19. // in such cases. So we can't use basic_ostream<IStream::char_type> but rather
  20. // use two template parameters
  21. #include <boost/assert.hpp>
  22. #include <locale>
  23. #include <cstddef> // size_t
  24. #include <boost/config.hpp>
  25. #if defined(BOOST_NO_STDC_NAMESPACE)
  26. namespace std{
  27. using ::size_t;
  28. #if ! defined(BOOST_DINKUMWARE_STDLIB) && ! defined(__SGI_STL_PORT)
  29. using ::locale;
  30. #endif
  31. } // namespace std
  32. #endif
  33. #include <boost/detail/workaround.hpp>
  34. #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
  35. #include <boost/archive/dinkumware.hpp>
  36. #endif
  37. #include <boost/limits.hpp>
  38. #include <boost/io/ios_state.hpp>
  39. #include <boost/scoped_ptr.hpp>
  40. #include <boost/static_assert.hpp>
  41. #include <boost/serialization/throw_exception.hpp>
  42. #include <boost/archive/archive_exception.hpp>
  43. #include <boost/archive/basic_streambuf_locale_saver.hpp>
  44. #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
  45. namespace boost {
  46. namespace archive {
  47. /////////////////////////////////////////////////////////////////////////
  48. // class basic_text_iarchive - load serialized objects from a input text stream
  49. #if defined(_MSC_VER)
  50. #pragma warning( push )
  51. #pragma warning( disable : 4244 4267 )
  52. #endif
  53. template<class IStream>
  54. class basic_text_iprimitive
  55. {
  56. #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
  57. protected:
  58. #else
  59. public:
  60. #endif
  61. IStream &is;
  62. io::ios_flags_saver flags_saver;
  63. io::ios_precision_saver precision_saver;
  64. #ifndef BOOST_NO_STD_LOCALE
  65. boost::scoped_ptr<std::locale> archive_locale;
  66. basic_streambuf_locale_saver<
  67. BOOST_DEDUCED_TYPENAME IStream::char_type,
  68. BOOST_DEDUCED_TYPENAME IStream::traits_type
  69. > locale_saver;
  70. #endif
  71. template<class T>
  72. void load(T & t)
  73. {
  74. if(! is.fail()){
  75. is >> t;
  76. return;
  77. }
  78. boost::serialization::throw_exception(
  79. archive_exception(archive_exception::input_stream_error)
  80. );
  81. }
  82. void load(char & t)
  83. {
  84. short int i;
  85. load(i);
  86. t = i;
  87. }
  88. void load(signed char & t)
  89. {
  90. short int i;
  91. load(i);
  92. t = i;
  93. }
  94. void load(unsigned char & t)
  95. {
  96. unsigned short int i;
  97. load(i);
  98. t = i;
  99. }
  100. #ifndef BOOST_NO_INTRINSIC_WCHAR_T
  101. void load(wchar_t & t)
  102. {
  103. BOOST_STATIC_ASSERT(sizeof(wchar_t) <= sizeof(int));
  104. int i;
  105. load(i);
  106. t = i;
  107. }
  108. #endif
  109. BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
  110. basic_text_iprimitive(IStream &is, bool no_codecvt);
  111. BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
  112. ~basic_text_iprimitive();
  113. public:
  114. BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
  115. load_binary(void *address, std::size_t count);
  116. };
  117. #if defined(_MSC_VER)
  118. #pragma warning( pop )
  119. #endif
  120. } // namespace archive
  121. } // namespace boost
  122. #include <boost/archive/detail/abi_suffix.hpp> // pop pragmas
  123. #endif // BOOST_ARCHIVE_BASIC_TEXT_IPRIMITIVE_HPP