text_woarchive_impl.ipp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. // text_woarchive_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 <boost/config.hpp>
  9. #ifndef BOOST_NO_STD_WSTREAMBUF
  10. #include <cstring>
  11. #include <cstddef> // size_t
  12. #if defined(BOOST_NO_STDC_NAMESPACE) && ! defined(__LIBCOMO__)
  13. namespace std{
  14. using ::strlen;
  15. using ::size_t;
  16. } // namespace std
  17. #endif
  18. #include <ostream>
  19. #include <boost/archive/text_woarchive.hpp>
  20. namespace boost {
  21. namespace archive {
  22. //////////////////////////////////////////////////////////////////////
  23. // implementation of woarchive functions
  24. //
  25. template<class Archive>
  26. BOOST_WARCHIVE_DECL void
  27. text_woarchive_impl<Archive>::save(const char *s)
  28. {
  29. // note: superfluous local variable fixes borland warning
  30. const std::size_t size = std::strlen(s);
  31. * this->This() << size;
  32. this->This()->newtoken();
  33. while(*s != '\0')
  34. os.put(os.widen(*s++));
  35. }
  36. template<class Archive>
  37. BOOST_WARCHIVE_DECL void
  38. text_woarchive_impl<Archive>::save(const std::string &s)
  39. {
  40. const std::size_t size = s.size();
  41. * this->This() << size;
  42. this->This()->newtoken();
  43. const char * cptr = s.data();
  44. for(std::size_t i = size; i-- > 0;)
  45. os.put(os.widen(*cptr++));
  46. }
  47. #ifndef BOOST_NO_INTRINSIC_WCHAR_T
  48. template<class Archive>
  49. BOOST_WARCHIVE_DECL void
  50. text_woarchive_impl<Archive>::save(const wchar_t *ws)
  51. {
  52. const std::size_t size = std::wostream::traits_type::length(ws);
  53. * this->This() << size;
  54. this->This()->newtoken();
  55. os.write(ws, size);
  56. }
  57. #endif
  58. #ifndef BOOST_NO_STD_WSTRING
  59. template<class Archive>
  60. BOOST_WARCHIVE_DECL void
  61. text_woarchive_impl<Archive>::save(const std::wstring &ws)
  62. {
  63. const std::size_t size = ws.length();
  64. * this->This() << size;
  65. this->This()->newtoken();
  66. os.write(ws.data(), size);
  67. }
  68. #endif
  69. } // namespace archive
  70. } // namespace boost
  71. #endif