text_oarchive_impl.ipp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. // text_oarchive_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 <string>
  9. #include <boost/config.hpp>
  10. #include <locale>
  11. #include <cstddef> // size_t
  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. #ifndef BOOST_NO_CWCHAR
  19. #include <cwchar>
  20. #ifdef BOOST_NO_STDC_NAMESPACE
  21. namespace std{ using ::wcslen; }
  22. #endif
  23. #endif
  24. #include <boost/archive/add_facet.hpp>
  25. #include <boost/archive/text_oarchive.hpp>
  26. namespace boost {
  27. namespace archive {
  28. //////////////////////////////////////////////////////////////////////
  29. // implementation of basic_text_oprimitive overrides for the combination
  30. // of template parameters used to create a text_oprimitive
  31. template<class Archive>
  32. BOOST_ARCHIVE_DECL(void)
  33. text_oarchive_impl<Archive>::save(const char * s)
  34. {
  35. const std::size_t len = std::ostream::traits_type::length(s);
  36. *this->This() << len;
  37. this->This()->newtoken();
  38. os << s;
  39. }
  40. template<class Archive>
  41. BOOST_ARCHIVE_DECL(void)
  42. text_oarchive_impl<Archive>::save(const std::string &s)
  43. {
  44. const std::size_t size = s.size();
  45. *this->This() << size;
  46. this->This()->newtoken();
  47. os << s;
  48. }
  49. #ifndef BOOST_NO_CWCHAR
  50. #ifndef BOOST_NO_INTRINSIC_WCHAR_T
  51. template<class Archive>
  52. BOOST_ARCHIVE_DECL(void)
  53. text_oarchive_impl<Archive>::save(const wchar_t * ws)
  54. {
  55. const std::size_t l = std::wcslen(ws);
  56. * this->This() << l;
  57. this->This()->newtoken();
  58. os.write((const char *)ws, l * sizeof(wchar_t)/sizeof(char));
  59. }
  60. #endif
  61. #ifndef BOOST_NO_STD_WSTRING
  62. template<class Archive>
  63. BOOST_ARCHIVE_DECL(void)
  64. text_oarchive_impl<Archive>::save(const std::wstring &ws)
  65. {
  66. const std::size_t l = ws.size();
  67. * this->This() << l;
  68. this->This()->newtoken();
  69. os.write((const char *)(ws.data()), l * sizeof(wchar_t)/sizeof(char));
  70. }
  71. #endif
  72. #endif // BOOST_NO_CWCHAR
  73. template<class Archive>
  74. BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY())
  75. text_oarchive_impl<Archive>::text_oarchive_impl(
  76. std::ostream & os,
  77. unsigned int flags
  78. ) :
  79. basic_text_oprimitive<std::ostream>(
  80. os,
  81. 0 != (flags & no_codecvt)
  82. ),
  83. basic_text_oarchive<Archive>(flags)
  84. {
  85. if(0 == (flags & no_header))
  86. #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
  87. this->init();
  88. #else
  89. this->basic_text_oarchive<Archive>::init();
  90. #endif
  91. }
  92. template<class Archive>
  93. BOOST_ARCHIVE_DECL(void)
  94. text_oarchive_impl<Archive>::save_binary(const void *address, std::size_t count){
  95. put('\n');
  96. this->end_preamble();
  97. #if ! defined(__MWERKS__)
  98. this->basic_text_oprimitive<std::ostream>::save_binary(
  99. #else
  100. this->basic_text_oprimitive::save_binary(
  101. #endif
  102. address,
  103. count
  104. );
  105. this->delimiter = this->eol;
  106. }
  107. } // namespace archive
  108. } // namespace boost