Chris@16: // Copyright David Abrahams 2002. Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: #ifndef REFERENT_STORAGE_DWA200278_HPP Chris@16: # define REFERENT_STORAGE_DWA200278_HPP Chris@16: # include Chris@16: # include Chris@16: Chris@16: namespace boost { namespace python { namespace detail { Chris@16: Chris@16: struct alignment_dummy; Chris@16: typedef void (*function_ptr)(); Chris@16: typedef int (alignment_dummy::*member_ptr); Chris@16: typedef int (alignment_dummy::*member_function_ptr)(); Chris@16: Chris@16: # define BOOST_PYTHON_ALIGNER(T, n) \ Chris@16: typename mpl::if_c< \ Chris@16: sizeof(T) <= size, T, char>::type t##n Chris@16: Chris@16: // Storage for size bytes, aligned to all fundamental types no larger than size Chris@16: template Chris@16: union aligned_storage Chris@16: { Chris@16: BOOST_PYTHON_ALIGNER(char, 0); Chris@16: BOOST_PYTHON_ALIGNER(short, 1); Chris@16: BOOST_PYTHON_ALIGNER(int, 2); Chris@16: BOOST_PYTHON_ALIGNER(long, 3); Chris@16: BOOST_PYTHON_ALIGNER(float, 4); Chris@16: BOOST_PYTHON_ALIGNER(double, 5); Chris@16: BOOST_PYTHON_ALIGNER(long double, 6); Chris@16: BOOST_PYTHON_ALIGNER(void*, 7); Chris@16: BOOST_PYTHON_ALIGNER(function_ptr, 8); Chris@16: BOOST_PYTHON_ALIGNER(member_ptr, 9); Chris@16: BOOST_PYTHON_ALIGNER(member_function_ptr, 10); Chris@16: char bytes[size]; Chris@16: }; Chris@16: Chris@16: # undef BOOST_PYTHON_ALIGNER Chris@16: Chris@16: // Compute the size of T's referent. We wouldn't need this at all, Chris@16: // but sizeof() is broken in CodeWarriors <= 8.0 Chris@16: template struct referent_size; Chris@16: Chris@16: # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION Chris@16: Chris@16: template Chris@16: struct referent_size Chris@16: { Chris@16: BOOST_STATIC_CONSTANT( Chris@16: std::size_t, value = sizeof(T)); Chris@16: }; Chris@16: Chris@16: # else Chris@16: Chris@16: template struct referent_size Chris@16: { Chris@16: static T f(); Chris@16: BOOST_STATIC_CONSTANT(std::size_t, value = sizeof(f())); Chris@16: }; Chris@16: Chris@16: # endif Chris@16: Chris@16: // A metafunction returning a POD type which can store U, where T == Chris@16: // U&. If T is not a reference type, returns a POD which can store T. Chris@16: template Chris@16: struct referent_storage Chris@16: { Chris@16: typedef aligned_storage< Chris@16: ::boost::python::detail::referent_size::value Chris@16: > type; Chris@16: }; Chris@16: Chris@16: }}} // namespace boost::python::detail Chris@16: Chris@16: #endif // REFERENT_STORAGE_DWA200278_HPP