text_oarchive_impl.ipp 3.0 KB

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