stack_constructor.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef BOOST_SERIALIZATION_DETAIL_STACH_CONSTRUCTOR_HPP
  2. #define BOOST_SERIALIZATION_DETAIL_STACH_CONSTRUCTOR_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. #if defined(_MSC_VER) && (_MSC_VER <= 1020)
  8. # pragma warning (disable : 4786) // too long name, harmless warning
  9. #endif
  10. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  11. // collections_load_imp.hpp: serialization for loading stl collections
  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. // See http://www.boost.org for updates, documentation, and revision history.
  17. #include <boost/aligned_storage.hpp>
  18. namespace boost{
  19. namespace serialization {
  20. namespace detail {
  21. // reserve space on stack for an object of type T without actually
  22. // construction such an object
  23. template<typename T >
  24. struct stack_allocate
  25. {
  26. T * address() {
  27. return static_cast<T*>(storage_.address());
  28. }
  29. T & reference() {
  30. return * address();
  31. }
  32. private:
  33. typedef BOOST_DEDUCED_TYPENAME boost::aligned_storage<
  34. sizeof(T),
  35. #if BOOST_WORKAROUND(__BORLANDC__,BOOST_TESTED_AT(0x560))
  36. 8
  37. #else
  38. boost::alignment_of<T>::value
  39. #endif
  40. > type;
  41. type storage_;
  42. };
  43. // construct element on the stack
  44. template<class Archive, class T>
  45. struct stack_construct : public stack_allocate<T>
  46. {
  47. stack_construct(Archive & ar, const unsigned int version){
  48. // note borland emits a no-op without the explicit namespace
  49. boost::serialization::load_construct_data_adl(
  50. ar,
  51. this->address(),
  52. version
  53. );
  54. }
  55. ~stack_construct(){
  56. this->address()->~T(); // undo load_construct_data above
  57. }
  58. };
  59. } // detail
  60. } // serializaition
  61. } // boost
  62. #endif // BOOST_SERIALIZATION_DETAIL_STACH_CONSTRUCTOR_HPP