.. _program_listing_file__tmp_ws_src_eigenpy_include_eigenpy_alignment.hpp: Program Listing for File alignment.hpp ====================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/eigenpy/include/eigenpy/alignment.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /* * Copyright 2023 INRIA */ #ifndef __eigenpy_alignment_hpp__ #define __eigenpy_alignment_hpp__ #include #include #include #include #include namespace eigenpy { template struct aligned_storage { union type { typename ::boost::aligned_storage::type data; char bytes[size]; }; }; template struct aligned_instance { PyObject_VAR_HEAD PyObject *dict; PyObject *weakrefs; boost::python::instance_holder *objects; typename aligned_storage::type storage; }; inline void *aligned_malloc( std::size_t size, std::size_t alignment = EIGENPY_DEFAULT_ALIGN_BYTES) { void *original = std::malloc(size + alignment); if (original == 0) return 0; if (is_aligned(original, alignment)) return original; void *aligned = reinterpret_cast((reinterpret_cast(original) & ~(std::size_t(alignment - 1))) + alignment); *(reinterpret_cast(aligned) - 1) = original; return aligned; } } // namespace eigenpy namespace boost { namespace python { namespace detail { template struct referent_storage< Eigen::Matrix &> { typedef Eigen::Matrix T; typedef typename eigenpy::aligned_storage::value>::type type; }; template struct referent_storage< const Eigen::Matrix &> { typedef Eigen::Matrix T; typedef typename eigenpy::aligned_storage::value>::type type; }; #ifdef EIGENPY_WITH_TENSOR_SUPPORT template struct referent_storage &> { typedef Eigen::Tensor T; typedef typename eigenpy::aligned_storage::value>::type type; }; template struct referent_storage< const Eigen::Tensor &> { typedef Eigen::Tensor T; typedef typename eigenpy::aligned_storage::value>::type type; }; #endif template struct referent_storage &> { typedef Eigen::Quaternion T; typedef typename eigenpy::aligned_storage::value>::type type; }; template struct referent_storage &> { typedef Eigen::Quaternion T; typedef typename eigenpy::aligned_storage::value>::type type; }; } // namespace detail } // namespace python } // namespace boost namespace boost { namespace python { namespace objects { // Force alignment of instance with value_holder template struct instance > : ::eigenpy::aligned_instance > {}; } // namespace objects } // namespace python } // namespace boost namespace eigenpy { template struct call_destructor { static void run(void *bytes) { typedef typename boost::remove_const< typename boost::remove_reference::type>::type T_; static_cast((void *)bytes)->~T_(); } }; template struct rvalue_from_python_data : ::boost::python::converter::rvalue_from_python_storage { #if (!defined(__MWERKS__) || __MWERKS__ >= 0x3000) && \ (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 245) && \ (!defined(__DECCXX_VER) || __DECCXX_VER > 60590014) && \ !defined(BOOST_PYTHON_SYNOPSIS) /* Synopsis' OpenCXX has trouble parsing \ this */ // This must always be a POD struct with m_data its first member. BOOST_STATIC_ASSERT( BOOST_PYTHON_OFFSETOF( ::boost::python::converter::rvalue_from_python_storage, stage1) == 0); #endif // The usual constructor rvalue_from_python_data( ::boost::python::converter::rvalue_from_python_stage1_data const &_stage1) { this->stage1 = _stage1; } // This constructor just sets m_convertible -- used by // implicitly_convertible<> to perform the final step of the // conversion, where the construct() function is already known. rvalue_from_python_data(void *convertible) { this->stage1.convertible = convertible; } // Destroys any object constructed in the storage. ~rvalue_from_python_data() { if (this->stage1.convertible == this->storage.bytes) { void *storage = reinterpret_cast(this->storage.bytes); call_destructor::run(storage); } } }; } // namespace eigenpy #endif // __eigenpy_alignment_hpp__