text_wiarchive_impl.ipp 2.7 KB

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