basic_text_oarchive.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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) && (_MSC_VER >= 1020)
  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/assert.hpp>
  22. #include <boost/config.hpp>
  23. #include <boost/serialization/pfto.hpp>
  24. #include <boost/detail/workaround.hpp>
  25. #include <boost/archive/detail/common_oarchive.hpp>
  26. #include <boost/serialization/string.hpp>
  27. #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
  28. #ifdef BOOST_MSVC
  29. # pragma warning(push)
  30. # pragma warning(disable : 4511 4512)
  31. #endif
  32. namespace boost {
  33. namespace archive {
  34. /////////////////////////////////////////////////////////////////////////
  35. // class basic_text_oarchive
  36. template<class Archive>
  37. class basic_text_oarchive :
  38. public detail::common_oarchive<Archive>
  39. {
  40. protected:
  41. #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) \
  42. || BOOST_WORKAROUND(__BORLANDC__,BOOST_TESTED_AT(0x560))
  43. public:
  44. #elif defined(BOOST_MSVC)
  45. // for some inexplicable reason insertion of "class" generates compile erro
  46. // on msvc 7.1
  47. friend detail::interface_oarchive<Archive>;
  48. #else
  49. friend class detail::interface_oarchive<Archive>;
  50. #endif
  51. enum {
  52. none,
  53. eol,
  54. space
  55. } delimiter;
  56. BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
  57. newtoken();
  58. void newline(){
  59. delimiter = eol;
  60. }
  61. // default processing - kick back to base class. Note the
  62. // extra stuff to get it passed borland compilers
  63. typedef detail::common_oarchive<Archive> detail_common_oarchive;
  64. template<class T>
  65. void save_override(T & t, BOOST_PFTO int){
  66. this->detail_common_oarchive::save_override(t, 0);
  67. }
  68. // start new objects on a new line
  69. void save_override(const object_id_type & t, int){
  70. this->This()->newline();
  71. this->detail_common_oarchive::save_override(t, 0);
  72. }
  73. // text file don't include the optional information
  74. void save_override(const class_id_optional_type & /* t */, int){}
  75. void save_override(const class_name_type & t, int){
  76. const std::string s(t);
  77. * this->This() << s;
  78. }
  79. BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
  80. init();
  81. basic_text_oarchive(unsigned int flags) :
  82. detail::common_oarchive<Archive>(flags),
  83. delimiter(none)
  84. {}
  85. ~basic_text_oarchive(){}
  86. };
  87. } // namespace archive
  88. } // namespace boost
  89. #ifdef BOOST_MSVC
  90. #pragma warning(pop)
  91. #endif
  92. #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
  93. #endif // BOOST_ARCHIVE_BASIC_TEXT_OARCHIVE_HPP