basic_text_iarchive.ipp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. // basic_text_iarchive.ipp:
  3. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  4. // Use, modification and distribution is subject to the Boost Software
  5. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. // See http://www.boost.org for updates, documentation, and revision history.
  8. #include <string>
  9. #include <algorithm>
  10. #include <cstring>
  11. #include <boost/config.hpp>
  12. #if defined(BOOST_NO_STDC_NAMESPACE)
  13. namespace std{
  14. using ::memcpy;
  15. }
  16. #endif
  17. #include <boost/detail/workaround.hpp>
  18. #include <boost/serialization/string.hpp>
  19. #include <boost/archive/basic_text_iarchive.hpp>
  20. namespace boost {
  21. namespace archive {
  22. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  23. // implementation of text_text_archive
  24. template<class Archive>
  25. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  26. basic_text_iarchive<Archive>::load_override(class_name_type & t){
  27. std::string cn;
  28. cn.reserve(BOOST_SERIALIZATION_MAX_KEY_SIZE);
  29. load_override(cn);
  30. if(cn.size() > (BOOST_SERIALIZATION_MAX_KEY_SIZE - 1))
  31. boost::serialization::throw_exception(
  32. archive_exception(archive_exception::invalid_class_name)
  33. );
  34. std::memcpy(t, cn.data(), cn.size());
  35. // borland tweak
  36. t.t[cn.size()] = '\0';
  37. }
  38. template<class Archive>
  39. BOOST_ARCHIVE_OR_WARCHIVE_DECL void
  40. basic_text_iarchive<Archive>::init(void){
  41. // read signature in an archive version independent manner
  42. std::string file_signature;
  43. * this->This() >> file_signature;
  44. if(file_signature != BOOST_ARCHIVE_SIGNATURE())
  45. boost::serialization::throw_exception(
  46. archive_exception(archive_exception::invalid_signature)
  47. );
  48. // make sure the version of the reading archive library can
  49. // support the format of the archive being read
  50. library_version_type input_library_version;
  51. * this->This() >> input_library_version;
  52. #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
  53. this->set_library_version(input_library_version);
  54. #else
  55. detail::basic_iarchive::set_library_version(input_library_version);
  56. #endif
  57. // extra little .t is to get around borland quirk
  58. if(BOOST_ARCHIVE_VERSION() < input_library_version)
  59. boost::serialization::throw_exception(
  60. archive_exception(archive_exception::unsupported_version)
  61. );
  62. }
  63. } // namespace archive
  64. } // namespace boost