VR-Vantage API Documentation
portable_binary_iarchive.hpp
Go to the documentation of this file.
1 #ifndef PORTABLE_BINARY_IARCHIVE_HPP
2 #define PORTABLE_BINARY_IARCHIVE_HPP
3 
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
6 # pragma once
7 #endif
8 
9 #if defined(_MSC_VER)
10 #pragma warning( push )
11 #pragma warning( disable : 4244 )
12 #endif
13 
15 // portable_binary_iarchive.hpp
16 
17 // (C) Copyright 2002-7 Robert Ramey - http://www.rrsd.com .
18 // Use, modification and distribution is subject to the Boost Software
19 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
20 // http://www.boost.org/LICENSE_1_0.txt)
21 
22 // See http://www.boost.org for updates, documentation, and revision history.
24 
25 #include <istream>
26 #include <boost/serialization/string.hpp>
27 #include <boost/serialization/item_version_type.hpp>
28 #include <boost/archive/archive_exception.hpp>
29 #include <boost/archive/basic_binary_iprimitive.hpp>
30 #include <boost/archive/detail/common_iarchive.hpp>
31 #include <boost/archive/shared_ptr_helper.hpp>
32 #include <boost/archive/detail/register_archive.hpp>
33 #include <boost/archive/detail/auto_link_archive.hpp>
34 
36 
38 // exception to be thrown if integer read from archive doesn't fit
39 // variable being loaded
41  public virtual boost::archive::archive_exception
42 {
43 public:
44  typedef enum {
45  incompatible_integer_size
46  } exception_code;
47  portable_binary_iarchive_exception(exception_code c = incompatible_integer_size ) :
48  boost::archive::archive_exception(boost::archive::archive_exception::other_exception)
49  {}
50  virtual const char *what( ) const throw( )
51  {
52  const char *msg = "programmer error";
53  switch(code){
54  case incompatible_integer_size:
55  msg = "integer cannot be represented";
56  break;
57  default:
58  msg = boost::archive::archive_exception::what();
59  assert(false);
60  break;
61  }
62  return msg;
63  }
64 };
65 
67 // "Portable" input binary archive. It addresses integer size and endienness so
68 // that binary archives can be passed across systems. Note:floating point types
69 // not addressed here
71  public boost::archive::basic_binary_iprimitive<
72  portable_binary_iarchive,
73  std::istream::char_type,
74  std::istream::traits_type
75  >,
76  public boost::archive::detail::common_iarchive<
77  portable_binary_iarchive
78  >
79  ,
80  public boost::archive::detail::shared_ptr_helper
81  {
82  typedef boost::archive::basic_binary_iprimitive<
84  std::istream::char_type,
85  std::istream::traits_type
87  typedef boost::archive::detail::common_iarchive<
90 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
91 public:
92 #else
93  friend archive_base_t;
94  friend primitive_base_t; // since with override load below
95  friend class boost::archive::detail::interface_iarchive<
97  >;
98  friend class boost::archive::load_access;
99 protected:
100 #endif
101  unsigned int m_flags;
102  void load_impl(boost::intmax_t & l, char maxsize);
103 
104  // default fall through for any types not specified here
105  template<class T>
106  void load(T & t){
107  boost::intmax_t l;
108  load_impl(l, sizeof(T));
109  // use cast to avoid compile time warning
110  //t = static_cast< T >(l);
111  t = T(l);
112  }
113  void load(boost::serialization::item_version_type & t){
114  boost::intmax_t l;
115  load_impl(l, sizeof(boost::serialization::item_version_type));
116  // use cast to avoid compile time warning
117  t = boost::serialization::item_version_type(l);
118  }
119  void load(boost::archive::version_type & t){
120  boost::intmax_t l;
121  load_impl(l, sizeof(boost::archive::version_type));
122  // use cast to avoid compile time warning
123  t = boost::archive::version_type(l);
124  }
125  void load(boost::archive::class_id_type & t){
126  boost::intmax_t l;
127  load_impl(l, sizeof(boost::archive::class_id_type));
128  // use cast to avoid compile time warning
129  t = boost::archive::class_id_type(static_cast<int>(l));
130  }
131  void load(std::string & t){
132  this->primitive_base_t::load(t);
133  }
134  #ifndef BOOST_NO_STD_WSTRING
135  void load(std::wstring & t){
136  this->primitive_base_t::load(t);
137  }
138  #endif
139  void load(float & t){
140  this->primitive_base_t::load(t);
141  // floats not supported
142  //BOOST_STATIC_ASSERT(false);
143  }
144  void load(double & t){
145  this->primitive_base_t::load(t);
146  // doubles not supported
147  //BOOST_STATIC_ASSERT(false);
148  }
149  void load(char & t){
150  this->primitive_base_t::load(t);
151  }
152  void load(unsigned char & t){
153  this->primitive_base_t::load(t);
154  }
155  // intermediate level to support override of operators
156  // fot templates in the absence of partial function
157  // template ordering
158  typedef boost::archive::detail::common_iarchive<portable_binary_iarchive>
160  template<class T>
161  void load_override(T & t, BOOST_PFTO int){
162  this->detail_common_iarchive::load_override(t, 0);
163  }
164  void load_override(boost::archive::class_name_type & t, int);
165  // binary files don't include the optional information
166  void load_override(
167  boost::archive::class_id_optional_type & /* t */,
168  int
169  ){}
170 
171  void init(unsigned int flags);
172 public:
173  portable_binary_iarchive(std::istream & is, unsigned flags = 0) :
175  * is.rdbuf(),
176  0 != (flags & boost::archive::no_codecvt)
177  ),
178  archive_base_t(flags),
179  m_flags(0)
180  {
181  init(flags);
182  }
183 
185  std::basic_streambuf<
186  std::istream::char_type,
187  std::istream::traits_type
188  > & bsb,
189  unsigned int flags
190  ) :
192  bsb,
193  0 != (flags & boost::archive::no_codecvt)
194  ),
195  archive_base_t(flags),
196  m_flags(0)
197  {
198  init(flags);
199  }
200 };
201 
202 // required by export in boost version > 1.34
203 #ifdef BOOST_SERIALIZATION_REGISTER_ARCHIVE
204  BOOST_SERIALIZATION_REGISTER_ARCHIVE(portable_binary_iarchive)
205 #endif
206 
207 // required by export in boost <= 1.34
208 #define BOOST_ARCHIVE_CUSTOM_IARCHIVE_TYPES portable_binary_iarchive
209 
210 #if defined(_MSC_VER)
211 #pragma warning( pop )
212 #endif
213 
214 #endif // PORTABLE_BINARY_IARCHIVE_HPP


Copyright © 2005-2013 VT MÄK Inc. All Rights Reserved (www.mak.com)