fix doc example typo
[boost.git] / boost / archive / polymorphic_oarchive.hpp
blob19aedf5f44623ad0cf32f2add45bf1b0f7beb4a0
1 #ifndef BOOST_ARCHIVE_POLYMORPHIC_OARCHIVE_HPP
2 #define BOOST_ARCHIVE_POLYMORPHIC_OARCHIVE_HPP
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
6 # pragma once
7 #endif
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // polymorphic_oarchive.hpp
12 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
13 // Use, modification and distribution is subject to the Boost Software
14 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
17 // See http://www.boost.org for updates, documentation, and revision history.
19 #include <cstddef> // size_t
20 #include <climits> // ULONG_MAX
21 #include <string>
23 #include <boost/config.hpp>
24 #if defined(BOOST_NO_STDC_NAMESPACE)
25 namespace std{
26 using ::size_t;
27 } // namespace std
28 #endif
30 #include <boost/cstdint.hpp>
31 #include <boost/serialization/pfto.hpp>
32 #include <boost/archive/detail/oserializer.hpp>
33 #include <boost/archive/detail/interface_oarchive.hpp>
34 #include <boost/serialization/nvp.hpp>
35 #include <boost/archive/detail/register_archive.hpp>
37 #include <boost/archive/detail/decl.hpp>
38 #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
40 // determine if its necessary to handle (u)int64_t specifically
41 // i.e. that its not a synonym for (unsigned) long
42 // if there is no 64 bit int or if its the same as a long
43 // we shouldn't define separate functions for int64 data types.
44 #if defined(BOOST_NO_INT64_T)
45 #define BOOST_NO_INTRINSIC_INT64_T
46 #else
47 #if defined(ULLONG_MAX)
48 #if(ULONG_MAX == 18446744073709551615ul) // 2**64 - 1
49 #define BOOST_NO_INTRINSIC_INT64_T
50 #endif
51 #elif defined(ULONG_MAX)
52 #if(ULONG_MAX != 0xffffffff && ULONG_MAX == 18446744073709551615ul) // 2**64 - 1
53 #define BOOST_NO_INTRINSIC_INT64_T
54 #endif
55 #else
56 #define BOOST_NO_INTRINSIC_INT64_T
57 #endif
58 #endif
60 namespace boost {
61 template<class T>
62 class shared_ptr;
63 namespace serialization {
64 class extended_type_info;
65 } // namespace serialization
66 namespace archive {
67 namespace detail {
68 class BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) basic_oarchive;
69 class BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) basic_oserializer;
72 class polymorphic_oarchive;
74 class polymorphic_oarchive_impl :
75 public detail::interface_oarchive<polymorphic_oarchive>
77 #ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
78 public:
79 #else
80 friend class detail::interface_oarchive<polymorphic_oarchive>;
81 friend class save_access;
82 #endif
83 // primitive types the only ones permitted by polymorphic archives
84 virtual void save(const bool t) = 0;
86 virtual void save(const char t) = 0;
87 virtual void save(const signed char t) = 0;
88 virtual void save(const unsigned char t) = 0;
89 #ifndef BOOST_NO_CWCHAR
90 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
91 virtual void save(const wchar_t t) = 0;
92 #endif
93 #endif
94 virtual void save(const short t) = 0;
95 virtual void save(const unsigned short t) = 0;
96 virtual void save(const int t) = 0;
97 virtual void save(const unsigned int t) = 0;
98 virtual void save(const long t) = 0;
99 virtual void save(const unsigned long t) = 0;
100 #if !defined(BOOST_NO_INTRINSIC_INT64_T)
101 virtual void save(const boost::int64_t t) = 0;
102 virtual void save(const boost::uint64_t t) = 0;
103 #endif
104 virtual void save(const float t) = 0;
105 virtual void save(const double t) = 0;
107 // string types are treated as primitives
108 virtual void save(const std::string & t) = 0;
109 #ifndef BOOST_NO_STD_WSTRING
110 virtual void save(const std::wstring & t) = 0;
111 #endif
113 virtual void save_null_pointer() = 0;
114 // used for xml and other tagged formats
115 virtual void save_start(const char * name) = 0;
116 virtual void save_end(const char * name) = 0;
117 virtual void register_basic_serializer(const detail::basic_oserializer & bos) = 0;
119 virtual void end_preamble() = 0;
121 // msvc and borland won't automatically pass these to the base class so
122 // make it explicit here
123 template<class T>
124 void save_override(T & t, BOOST_PFTO int)
126 archive::save(* this->This(), t);
128 // special treatment for name-value pairs.
129 template<class T>
130 void save_override(
131 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
132 const
133 #endif
134 ::boost::serialization::nvp<T> & t, int
136 save_start(t.name());
137 archive::save(* this->This(), t.const_value());
138 save_end(t.name());
140 protected:
141 virtual ~polymorphic_oarchive_impl(){};
142 public:
143 // utility functions implemented by all legal archives
144 virtual unsigned int get_flags() const = 0;
145 virtual unsigned int get_library_version() const = 0;
146 virtual void save_binary(const void * t, std::size_t size) = 0;
148 virtual void save_object(
149 const void *x,
150 const detail::basic_oserializer & bos
151 ) = 0;
152 virtual void save_pointer(
153 const void * t,
154 const detail::basic_pointer_oserializer * bpos_ptr
155 ) = 0;
158 // note: preserve naming symmetry
159 class polymorphic_oarchive :
160 public polymorphic_oarchive_impl
162 public:
163 virtual ~polymorphic_oarchive(){};
166 } // namespace archive
167 } // namespace boost
169 // required by export
170 BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::archive::polymorphic_oarchive)
172 #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
174 #endif // BOOST_ARCHIVE_POLYMORPHIC_OARCHIVE_HPP