1 | #ifndef BOOST_ARCHIVE_BASIC_BINARY_OARCHIVE_HPP |
---|
2 | #define BOOST_ARCHIVE_BASIC_BINARY_OARCHIVE_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 | // basic_binary_oarchive.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 | // archives stored as native binary - this should be the fastest way |
---|
20 | // to archive the state of a group of obects. It makes no attempt to |
---|
21 | // convert to any canonical form. |
---|
22 | |
---|
23 | // IN GENERAL, ARCHIVES CREATED WITH THIS CLASS WILL NOT BE READABLE |
---|
24 | // ON PLATFORM APART FROM THE ONE THEY ARE CREATE ON |
---|
25 | |
---|
26 | #include <boost/config.hpp> |
---|
27 | #include <boost/pfto.hpp> |
---|
28 | |
---|
29 | #include <boost/detail/workaround.hpp> |
---|
30 | #include <boost/archive/detail/common_oarchive.hpp> |
---|
31 | #include <boost/serialization/string.hpp> |
---|
32 | |
---|
33 | namespace boost { |
---|
34 | namespace archive { |
---|
35 | |
---|
36 | ////////////////////////////////////////////////////////////////////// |
---|
37 | // class basic_binary_oarchive - write serialized objects to a binary output stream |
---|
38 | // note: this archive has no pretensions to portability. Archive format |
---|
39 | // may vary across machine architectures and compilers. About the only |
---|
40 | // guarentee is that an archive created with this code will be readable |
---|
41 | // by a program built with the same tools for the same machne. This class |
---|
42 | // does have the virtue of buiding the smalles archive in the minimum amount |
---|
43 | // of time. So under some circumstances it may be he right choice. |
---|
44 | |
---|
45 | ///////////////////////////////////////////////////////////////////////// |
---|
46 | // class basic_text_iarchive - read serialized objects from a input text stream |
---|
47 | template<class Archive> |
---|
48 | class basic_binary_oarchive : |
---|
49 | public detail::common_oarchive<Archive> |
---|
50 | { |
---|
51 | protected: |
---|
52 | #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) |
---|
53 | public: |
---|
54 | #elif defined(BOOST_MSVC) |
---|
55 | // for some inexplicable reason insertion of "class" generates compile erro |
---|
56 | // on msvc 7.1 |
---|
57 | friend detail::interface_oarchive<Archive>; |
---|
58 | #else |
---|
59 | friend class detail::interface_oarchive<Archive>; |
---|
60 | #endif |
---|
61 | // any datatype not specifed below will be handled by base class |
---|
62 | typedef detail::common_oarchive<Archive> detail_common_oarchive; |
---|
63 | template<class T> |
---|
64 | void save_override(T & t, BOOST_PFTO int){ |
---|
65 | this->detail_common_oarchive::save_override(t, 0); |
---|
66 | } |
---|
67 | // binary files don't include the optional information |
---|
68 | void save_override(const class_id_optional_type & /* t */, int){} |
---|
69 | |
---|
70 | void save_override(const version_type & t, int){ |
---|
71 | // upto 255 versions |
---|
72 | // note:t.t resolves borland ambguity |
---|
73 | unsigned char x = t.t; |
---|
74 | * this->This() << x; |
---|
75 | } |
---|
76 | void save_override(const class_id_type & t, int){ |
---|
77 | // upto 32K classes |
---|
78 | int_least16_t x = t.t; |
---|
79 | * this->This() << x; |
---|
80 | } |
---|
81 | void save_override(const class_id_reference_type & t, int){ |
---|
82 | // upto 32K classes |
---|
83 | int_least16_t x = t.t; |
---|
84 | * this->This() << x; |
---|
85 | } |
---|
86 | void save_override(const object_id_type & t, int){ |
---|
87 | // upto 2G objects |
---|
88 | uint_least32_t x = t.t; |
---|
89 | * this->This() << x; |
---|
90 | } |
---|
91 | void save_override(const object_reference_type & t, int){ |
---|
92 | // upto 2G objects |
---|
93 | uint_least32_t x = t.t; |
---|
94 | * this->This() << x; |
---|
95 | } |
---|
96 | void save_override(const tracking_type & t, int){ |
---|
97 | char x = t.t; |
---|
98 | * this->This() << x; |
---|
99 | } |
---|
100 | |
---|
101 | // explicitly convert to char * to avoid compile ambiguities |
---|
102 | void save_override(const class_name_type & t, int){ |
---|
103 | const std::string s(t); |
---|
104 | * this->This() << s; |
---|
105 | } |
---|
106 | |
---|
107 | BOOST_ARCHIVE_OR_WARCHIVE_DECL(void) |
---|
108 | init(); |
---|
109 | |
---|
110 | basic_binary_oarchive(unsigned int flags) : |
---|
111 | detail::common_oarchive<Archive>(flags) |
---|
112 | {} |
---|
113 | }; |
---|
114 | |
---|
115 | } // namespace archive |
---|
116 | } // namespace boost |
---|
117 | |
---|
118 | #endif // BOOST_ARCHIVE_BASIC_BINARY_OARCHIVE_HPP |
---|