text_iarchive_impl.ipp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. // text_iarchive_impl.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. //////////////////////////////////////////////////////////////////////
  9. // implementation of basic_text_iprimitive overrides for the combination
  10. // of template parameters used to implement a text_iprimitive
  11. #include <cstddef> // size_t, NULL
  12. #include <boost/config.hpp>
  13. #if defined(BOOST_NO_STDC_NAMESPACE)
  14. namespace std{
  15. using ::size_t;
  16. } // namespace std
  17. #endif
  18. #include <boost/detail/workaround.hpp> // RogueWave
  19. #include <boost/archive/text_iarchive.hpp>
  20. namespace boost {
  21. namespace archive {
  22. template<class Archive>
  23. BOOST_ARCHIVE_DECL void
  24. text_iarchive_impl<Archive>::load(char *s)
  25. {
  26. std::size_t size;
  27. * this->This() >> size;
  28. // skip separating space
  29. is.get();
  30. // Works on all tested platforms
  31. is.read(s, size);
  32. s[size] = '\0';
  33. }
  34. template<class Archive>
  35. BOOST_ARCHIVE_DECL void
  36. text_iarchive_impl<Archive>::load(std::string &s)
  37. {
  38. std::size_t size;
  39. * this->This() >> size;
  40. // skip separating space
  41. is.get();
  42. // borland de-allocator fixup
  43. #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
  44. if(NULL != s.data())
  45. #endif
  46. s.resize(size);
  47. if(0 < size)
  48. is.read(&(*s.begin()), size);
  49. }
  50. #ifndef BOOST_NO_CWCHAR
  51. #ifndef BOOST_NO_INTRINSIC_WCHAR_T
  52. template<class Archive>
  53. BOOST_ARCHIVE_DECL void
  54. text_iarchive_impl<Archive>::load(wchar_t *ws)
  55. {
  56. std::size_t size;
  57. * this->This() >> size;
  58. // skip separating space
  59. is.get();
  60. is.read((char *)ws, size * sizeof(wchar_t)/sizeof(char));
  61. ws[size] = L'\0';
  62. }
  63. #endif // BOOST_NO_INTRINSIC_WCHAR_T
  64. #ifndef BOOST_NO_STD_WSTRING
  65. template<class Archive>
  66. BOOST_ARCHIVE_DECL void
  67. text_iarchive_impl<Archive>::load(std::wstring &ws)
  68. {
  69. std::size_t size;
  70. * this->This() >> size;
  71. // borland de-allocator fixup
  72. #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
  73. if(NULL != ws.data())
  74. #endif
  75. ws.resize(size);
  76. // skip separating space
  77. is.get();
  78. is.read((char *)ws.data(), size * sizeof(wchar_t)/sizeof(char));
  79. }
  80. #endif // BOOST_NO_STD_WSTRING
  81. #endif // BOOST_NO_CWCHAR
  82. template<class Archive>
  83. BOOST_ARCHIVE_DECL void
  84. text_iarchive_impl<Archive>::load_override(class_name_type & t){
  85. basic_text_iarchive<Archive>::load_override(t);
  86. }
  87. template<class Archive>
  88. BOOST_ARCHIVE_DECL void
  89. text_iarchive_impl<Archive>::init(){
  90. basic_text_iarchive<Archive>::init();
  91. }
  92. template<class Archive>
  93. BOOST_ARCHIVE_DECL
  94. text_iarchive_impl<Archive>::text_iarchive_impl(
  95. std::istream & is,
  96. unsigned int flags
  97. ) :
  98. basic_text_iprimitive<std::istream>(
  99. is,
  100. 0 != (flags & no_codecvt)
  101. ),
  102. basic_text_iarchive<Archive>(flags)
  103. {}
  104. } // namespace archive
  105. } // namespace boost