source: NonGTP/Boost/boost/archive/detail/polymorphic_oarchive_impl.hpp @ 857

Revision 857, 6.1 KB checked in by igarcia, 18 years ago (diff)
Line 
1#ifndef BOOST_ARCHIVE_DETAIL_POLYMORPHIC_OARCHIVE_IMPL_HPP
2#define BOOST_ARCHIVE_DETAIL_POLYMORPHIC_OARCHIVE_IMPL_HPP
3
4// MS compatible compilers support #pragma once
5#if defined(_MSC_VER) && (_MSC_VER >= 1020)
6# pragma once
7#endif
8
9/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10// polymorphic_oarchive_impl.hpp
11
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)
16
17//  See http://www.boost.org for updates, documentation, and revision history.
18
19#include <string>
20#include <ostream>
21#include <boost/noncopyable.hpp>
22#include <boost/cstdint.hpp>
23#include <cstddef> // size_t
24
25#include <boost/config.hpp>
26#if defined(BOOST_NO_STDC_NAMESPACE)
27namespace std{
28    using ::size_t;
29} // namespace std
30#endif
31
32#include <boost/archive/polymorphic_oarchive.hpp>
33#include <boost/archive/detail/abi_prefix.hpp> // must be the last header
34
35namespace boost {
36template<class T>
37class shared_ptr;
38namespace serialization {
39    class extended_type_info;
40} // namespace serialization
41namespace archive {
42namespace detail{
43
44class BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) basic_oserializer;
45class BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) basic_pointer_oserializer;
46
47template<class ArchiveImplementation>
48class polymorphic_oarchive_impl :
49    public polymorphic_oarchive,
50    // note: gcc dynamic cross cast fails if the the derivation below is
51    // not public.  I think this is a mistake.
52    public /*protected*/ ArchiveImplementation,
53    private boost::noncopyable
54{
55private:
56    // these are used by the serialization library.
57    virtual void save_object(
58        const void *x,
59        const detail::basic_oserializer & bos
60    ){
61        ArchiveImplementation::save_object(x, bos);
62    }
63    virtual void save_pointer(
64        const void * t,
65        const detail::basic_pointer_oserializer * bpos_ptr
66    ){
67        ArchiveImplementation::save_pointer(t, bpos_ptr);
68    }
69    virtual void save_null_pointer(){
70        ArchiveImplementation::save_null_pointer();
71    }
72    // primitive types the only ones permitted by polymorphic archives
73    virtual void save(const bool t){
74        ArchiveImplementation::save(t);
75    }
76    virtual void save(const char t){
77        ArchiveImplementation::save(t);
78    }
79    virtual void save(const signed char t){
80        ArchiveImplementation::save(t);
81    }
82    virtual void save(const unsigned char t){
83        ArchiveImplementation::save(t);
84    }
85    #ifndef BOOST_NO_CWCHAR
86    #ifndef BOOST_NO_INTRINSIC_WCHAR_T
87    virtual void save(const wchar_t t){
88        ArchiveImplementation::save(t);
89    }
90    #endif
91    #endif
92    virtual void save(const short t){
93        ArchiveImplementation::save(t);
94    }
95    virtual void save(const unsigned short t){
96        ArchiveImplementation::save(t);
97    }
98    virtual void save(const int t){
99        ArchiveImplementation::save(t);
100    }
101    virtual void save(const unsigned int t){
102        ArchiveImplementation::save(t);
103    }
104    virtual void save(const long t){
105        ArchiveImplementation::save(t);
106    }
107    virtual void save(const unsigned long t){
108        ArchiveImplementation::save(t);
109    }
110    #if !defined(BOOST_NO_INTRINSIC_INT64_T)
111    virtual void save(const boost::int64_t t){
112        ArchiveImplementation::save(t);
113    }
114    virtual void save(const boost::uint64_t t){
115        ArchiveImplementation::save(t);
116    }
117    #endif
118    virtual void save(const float t){
119        ArchiveImplementation::save(t);
120    }
121    virtual void save(const double t){
122        ArchiveImplementation::save(t);
123    }
124    virtual void save(const std::string & t){
125        ArchiveImplementation::save(t);
126    }
127    #ifndef BOOST_NO_STD_WSTRING
128    virtual void save(const std::wstring & t){
129        ArchiveImplementation::save(t);
130    }
131    #endif
132    virtual unsigned int get_library_version() const{
133        return ArchiveImplementation::get_library_version();
134    }
135    virtual unsigned int get_flags() const {
136        return ArchiveImplementation::get_flags();
137    }
138    virtual void save_binary(const void * t, std::size_t size){
139        ArchiveImplementation::save_binary(t, size);
140    }
141    // used for xml and other tagged formats default does nothing
142    virtual void save_start(const char * name){
143        ArchiveImplementation::save_start(name);
144    }
145    virtual void save_end(const char * name){
146        ArchiveImplementation::save_end(name);
147    }
148    virtual void end_preamble(){
149        ArchiveImplementation::end_preamble();
150    }
151    virtual void register_basic_serializer(const detail::basic_oserializer & bos){
152        ArchiveImplementation::register_basic_serializer(bos);
153    }
154    virtual void lookup_basic_helper(
155        const boost::serialization::extended_type_info * const eti,
156                shared_ptr<void> & sph
157        ){
158                ArchiveImplementation::lookup_basic_helper(eti, sph);
159        }
160    virtual void insert_basic_helper(
161        const boost::serialization::extended_type_info * const eti,
162                shared_ptr<void> & sph
163        ){
164                ArchiveImplementation::insert_basic_helper(eti, sph);
165        }
166public:
167    // the << operator
168    template<class T>
169    polymorphic_oarchive & operator<<(T & t){
170        return polymorphic_oarchive::operator<<(t);
171    }
172    // the & operator
173    template<class T>
174    polymorphic_oarchive & operator&(T & t){
175        return polymorphic_oarchive::operator&(t);
176    }
177    // all current archives take a stream as constructor argument
178    template <class _Elem, class _Tr>
179    polymorphic_oarchive_impl(
180        std::basic_ostream<_Elem, _Tr> & os,
181        unsigned int flags = 0
182    ) :
183        ArchiveImplementation(os, flags)
184    {}
185};
186
187} // namespace detail
188} // namespace archive
189} // namespace boost
190
191#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
192
193#endif // BOOST_ARCHIVE_DETAIL_POLYMORPHIC_OARCHIVE_IMPL_HPP
Note: See TracBrowser for help on using the repository browser.