basic_text_oarchive.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #ifndef BOOST_ARCHIVE_BASIC_TEXT_OARCHIVE_HPP
  2. #define BOOST_ARCHIVE_BASIC_TEXT_OARCHIVE_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. // basic_text_oarchive.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. // archives stored as text - note these ar templated on the basic
  15. // stream templates to accommodate wide (and other?) kind of characters
  16. //
  17. // note the fact that on libraries without wide characters, ostream is
  18. // is not a specialization of basic_ostream which in fact is not defined
  19. // in such cases. So we can't use basic_ostream<OStream::char_type> but rather
  20. // use two template parameters
  21. #include <boost/config.hpp>
  22. #include <boost/detail/workaround.hpp>
  23. #include <boost/archive/detail/common_oarchive.hpp>
  24. #include <boost/serialization/string.hpp>
  25. #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
  26. #ifdef BOOST_MSVC
  27. # pragma warning(push)
  28. # pragma warning(disable : 4511 4512)
  29. #endif
  30. namespace boost {
  31. namespace archive {
  32. namespace detail {
  33. template<class Archive> class interface_oarchive;
  34. } // namespace detail
  35. /////////////////////////////////////////////////////////////////////////
  36. // class basic_text_oarchive
  37. template<class Archive>
  38. class BOOST_SYMBOL_VISIBLE basic_text_oarchive :
  39. public detail::common_oarchive<Archive>
  40. {
  41. #ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
  42. public:
  43. #else
  44. protected:
  45. #if BOOST_WORKAROUND(BOOST_MSVC, < 1500)
  46. // for some inexplicable reason insertion of "class" generates compile erro
  47. // on msvc 7.1
  48. friend detail::interface_oarchive<Archive>;
  49. #else
  50. friend class detail::interface_oarchive<Archive>;
  51. #endif
  52. #endif
  53. enum {
  54. none,
  55. eol,
  56. space
  57. } delimiter;
  58. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  59. newtoken();
  60. void newline(){
  61. delimiter = eol;
  62. }
  63. // default processing - kick back to base class. Note the
  64. // extra stuff to get it passed borland compilers
  65. typedef detail::common_oarchive<Archive> detail_common_oarchive;
  66. template<class T>
  67. void save_override(T & t){
  68. this->detail_common_oarchive::save_override(t);
  69. }
  70. // start new objects on a new line
  71. void save_override(const object_id_type & t){
  72. this->This()->newline();
  73. this->detail_common_oarchive::save_override(t);
  74. }
  75. // text file don't include the optional information
  76. void save_override(const class_id_optional_type & /* t */){}
  77. void save_override(const class_name_type & t){
  78. const std::string s(t);
  79. * this->This() << s;
  80. }
  81. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  82. init();
  83. basic_text_oarchive(unsigned int flags) :
  84. detail::common_oarchive<Archive>(flags),
  85. delimiter(none)
  86. {}
  87. ~basic_text_oarchive(){}
  88. };
  89. } // namespace archive
  90. } // namespace boost
  91. #ifdef BOOST_MSVC
  92. #pragma warning(pop)
  93. #endif
  94. #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
  95. #endif // BOOST_ARCHIVE_BASIC_TEXT_OARCHIVE_HPP