text_woarchive.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #ifndef BOOST_ARCHIVE_TEXT_WOARCHIVE_HPP
  2. #define BOOST_ARCHIVE_TEXT_WOARCHIVE_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // text_woarchive.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 <boost/config.hpp>
  15. #ifdef BOOST_NO_STD_WSTREAMBUF
  16. #error "wide char i/o not supported on this platform"
  17. #else
  18. #include <ostream>
  19. #include <cstddef> // size_t
  20. #if defined(BOOST_NO_STDC_NAMESPACE)
  21. namespace std{
  22. using ::size_t;
  23. } // namespace std
  24. #endif
  25. #include <boost/archive/detail/auto_link_warchive.hpp>
  26. #include <boost/archive/basic_text_oprimitive.hpp>
  27. #include <boost/archive/basic_text_oarchive.hpp>
  28. #include <boost/archive/detail/register_archive.hpp>
  29. #include <boost/serialization/item_version_type.hpp>
  30. #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
  31. #ifdef BOOST_MSVC
  32. # pragma warning(push)
  33. # pragma warning(disable : 4511 4512)
  34. #endif
  35. namespace boost {
  36. namespace archive {
  37. namespace detail {
  38. template<class Archive> class interface_oarchive;
  39. } // namespace detail
  40. template<class Archive>
  41. class BOOST_SYMBOL_VISIBLE text_woarchive_impl :
  42. public basic_text_oprimitive<std::wostream>,
  43. public basic_text_oarchive<Archive>
  44. {
  45. #ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
  46. public:
  47. #else
  48. protected:
  49. #if BOOST_WORKAROUND(BOOST_MSVC, < 1500)
  50. // for some inexplicable reason insertion of "class" generates compile erro
  51. // on msvc 7.1
  52. friend detail::interface_oarchive<Archive>;
  53. friend basic_text_oarchive<Archive>;
  54. friend save_access;
  55. #else
  56. friend class detail::interface_oarchive<Archive>;
  57. friend class basic_text_oarchive<Archive>;
  58. friend class save_access;
  59. #endif
  60. #endif
  61. template<class T>
  62. void save(const T & t){
  63. this->newtoken();
  64. basic_text_oprimitive<std::wostream>::save(t);
  65. }
  66. void save(const version_type & t){
  67. save(static_cast<unsigned int>(t));
  68. }
  69. void save(const boost::serialization::item_version_type & t){
  70. save(static_cast<unsigned int>(t));
  71. }
  72. BOOST_WARCHIVE_DECL void
  73. save(const char * t);
  74. #ifndef BOOST_NO_INTRINSIC_WCHAR_T
  75. BOOST_WARCHIVE_DECL void
  76. save(const wchar_t * t);
  77. #endif
  78. BOOST_WARCHIVE_DECL void
  79. save(const std::string &s);
  80. #ifndef BOOST_NO_STD_WSTRING
  81. BOOST_WARCHIVE_DECL void
  82. save(const std::wstring &ws);
  83. #endif
  84. text_woarchive_impl(std::wostream & os, unsigned int flags) :
  85. basic_text_oprimitive<std::wostream>(
  86. os,
  87. 0 != (flags & no_codecvt)
  88. ),
  89. basic_text_oarchive<Archive>(flags)
  90. {}
  91. public:
  92. void save_binary(const void *address, std::size_t count){
  93. put(static_cast<wchar_t>('\n'));
  94. this->end_preamble();
  95. #if ! defined(__MWERKS__)
  96. this->basic_text_oprimitive<std::wostream>::save_binary(
  97. #else
  98. this->basic_text_oprimitive::save_binary(
  99. #endif
  100. address,
  101. count
  102. );
  103. put(static_cast<wchar_t>('\n'));
  104. this->delimiter = this->none;
  105. }
  106. };
  107. // we use the following because we can't use
  108. // typedef text_oarchive_impl<text_oarchive_impl<...> > text_oarchive;
  109. // do not derive from this class. If you want to extend this functionality
  110. // via inheritance, derived from text_oarchive_impl instead. This will
  111. // preserve correct static polymorphism.
  112. class BOOST_SYMBOL_VISIBLE text_woarchive :
  113. public text_woarchive_impl<text_woarchive>
  114. {
  115. public:
  116. text_woarchive(std::wostream & os, unsigned int flags = 0) :
  117. text_woarchive_impl<text_woarchive>(os, flags)
  118. {
  119. if(0 == (flags & no_header))
  120. init();
  121. }
  122. ~text_woarchive() BOOST_OVERRIDE {}
  123. };
  124. } // namespace archive
  125. } // namespace boost
  126. // required by export
  127. BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::archive::text_woarchive)
  128. #ifdef BOOST_MSVC
  129. #pragma warning(pop)
  130. #endif
  131. #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
  132. #endif // BOOST_NO_STD_WSTREAMBUF
  133. #endif // BOOST_ARCHIVE_TEXT_WOARCHIVE_HPP