polymorphic_oarchive_route.hpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #ifndef BOOST_ARCHIVE_DETAIL_POLYMORPHIC_OARCHIVE_ROUTE_HPP
  2. #define BOOST_ARCHIVE_DETAIL_POLYMORPHIC_OARCHIVE_ROUTE_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. // polymorphic_oarchive_route.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. #include <string>
  15. #include <ostream>
  16. #include <cstddef> // size_t
  17. #include <boost/config.hpp>
  18. #if defined(BOOST_NO_STDC_NAMESPACE)
  19. namespace std{
  20. using ::size_t;
  21. } // namespace std
  22. #endif
  23. #include <boost/cstdint.hpp>
  24. #include <boost/integer_traits.hpp>
  25. #include <boost/archive/polymorphic_oarchive.hpp>
  26. #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
  27. namespace boost {
  28. namespace serialization {
  29. class extended_type_info;
  30. } // namespace serialization
  31. namespace archive {
  32. namespace detail{
  33. class basic_oserializer;
  34. class basic_pointer_oserializer;
  35. #ifdef BOOST_MSVC
  36. # pragma warning(push)
  37. # pragma warning(disable : 4511 4512)
  38. #endif
  39. template<class ArchiveImplementation>
  40. class polymorphic_oarchive_route :
  41. public polymorphic_oarchive,
  42. // note: gcc dynamic cross cast fails if the the derivation below is
  43. // not public. I think this is a mistake.
  44. public /*protected*/ ArchiveImplementation
  45. {
  46. private:
  47. // these are used by the serialization library.
  48. virtual void save_object(
  49. const void *x,
  50. const detail::basic_oserializer & bos
  51. ){
  52. ArchiveImplementation::save_object(x, bos);
  53. }
  54. virtual void save_pointer(
  55. const void * t,
  56. const detail::basic_pointer_oserializer * bpos_ptr
  57. ){
  58. ArchiveImplementation::save_pointer(t, bpos_ptr);
  59. }
  60. virtual void save_null_pointer(){
  61. ArchiveImplementation::save_null_pointer();
  62. }
  63. // primitive types the only ones permitted by polymorphic archives
  64. virtual void save(const bool t){
  65. ArchiveImplementation::save(t);
  66. }
  67. virtual void save(const char t){
  68. ArchiveImplementation::save(t);
  69. }
  70. virtual void save(const signed char t){
  71. ArchiveImplementation::save(t);
  72. }
  73. virtual void save(const unsigned char t){
  74. ArchiveImplementation::save(t);
  75. }
  76. #ifndef BOOST_NO_CWCHAR
  77. #ifndef BOOST_NO_INTRINSIC_WCHAR_T
  78. virtual void save(const wchar_t t){
  79. ArchiveImplementation::save(t);
  80. }
  81. #endif
  82. #endif
  83. virtual void save(const short t){
  84. ArchiveImplementation::save(t);
  85. }
  86. virtual void save(const unsigned short t){
  87. ArchiveImplementation::save(t);
  88. }
  89. virtual void save(const int t){
  90. ArchiveImplementation::save(t);
  91. }
  92. virtual void save(const unsigned int t){
  93. ArchiveImplementation::save(t);
  94. }
  95. virtual void save(const long t){
  96. ArchiveImplementation::save(t);
  97. }
  98. virtual void save(const unsigned long t){
  99. ArchiveImplementation::save(t);
  100. }
  101. #if defined(BOOST_HAS_LONG_LONG)
  102. virtual void save(const boost::long_long_type t){
  103. ArchiveImplementation::save(t);
  104. }
  105. virtual void save(const boost::ulong_long_type t){
  106. ArchiveImplementation::save(t);
  107. }
  108. #elif defined(BOOST_HAS_MS_INT64)
  109. virtual void save(const boost::int64_t t){
  110. ArchiveImplementation::save(t);
  111. }
  112. virtual void save(const boost::uint64_t t){
  113. ArchiveImplementation::save(t);
  114. }
  115. #endif
  116. virtual void save(const float t){
  117. ArchiveImplementation::save(t);
  118. }
  119. virtual void save(const double t){
  120. ArchiveImplementation::save(t);
  121. }
  122. virtual void save(const std::string & t){
  123. ArchiveImplementation::save(t);
  124. }
  125. #ifndef BOOST_NO_STD_WSTRING
  126. virtual void save(const std::wstring & t){
  127. ArchiveImplementation::save(t);
  128. }
  129. #endif
  130. virtual library_version_type get_library_version() const{
  131. return ArchiveImplementation::get_library_version();
  132. }
  133. virtual unsigned int get_flags() const {
  134. return ArchiveImplementation::get_flags();
  135. }
  136. virtual void save_binary(const void * t, std::size_t size){
  137. ArchiveImplementation::save_binary(t, size);
  138. }
  139. // used for xml and other tagged formats default does nothing
  140. virtual void save_start(const char * name){
  141. ArchiveImplementation::save_start(name);
  142. }
  143. virtual void save_end(const char * name){
  144. ArchiveImplementation::save_end(name);
  145. }
  146. virtual void end_preamble(){
  147. ArchiveImplementation::end_preamble();
  148. }
  149. virtual void register_basic_serializer(const detail::basic_oserializer & bos){
  150. ArchiveImplementation::register_basic_serializer(bos);
  151. }
  152. virtual helper_collection &
  153. get_helper_collection(){
  154. return ArchiveImplementation::get_helper_collection();
  155. }
  156. public:
  157. // this can't be inheriteded because they appear in mulitple
  158. // parents
  159. typedef mpl::bool_<false> is_loading;
  160. typedef mpl::bool_<true> is_saving;
  161. // the << operator
  162. template<class T>
  163. polymorphic_oarchive & operator<<(T & t){
  164. return polymorphic_oarchive::operator<<(t);
  165. }
  166. // the & operator
  167. template<class T>
  168. polymorphic_oarchive & operator&(T & t){
  169. return polymorphic_oarchive::operator&(t);
  170. }
  171. // register type function
  172. template<class T>
  173. const basic_pointer_oserializer *
  174. register_type(T * t = NULL){
  175. return ArchiveImplementation::register_type(t);
  176. }
  177. // all current archives take a stream as constructor argument
  178. template <class _Elem, class _Tr>
  179. polymorphic_oarchive_route(
  180. std::basic_ostream<_Elem, _Tr> & os,
  181. unsigned int flags = 0
  182. ) :
  183. ArchiveImplementation(os, flags)
  184. {}
  185. virtual ~polymorphic_oarchive_route(){};
  186. };
  187. } // namespace detail
  188. } // namespace archive
  189. } // namespace boost
  190. #ifdef BOOST_MSVC
  191. #pragma warning(pop)
  192. #endif
  193. #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
  194. #endif // BOOST_ARCHIVE_DETAIL_POLYMORPHIC_OARCHIVE_DISPATCH_HPP