123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- #ifndef BOOST_DLL_IMPORT_MANGLED_HPP_
- #define BOOST_DLL_IMPORT_MANGLED_HPP_
- #include <boost/dll/config.hpp>
- #if (__cplusplus < 201103L) && (!defined(_MSVC_LANG) || _MSVC_LANG < 201103L)
- # error This file requires C++11 at least!
- #endif
- #include <boost/make_shared.hpp>
- #include <boost/move/move.hpp>
- #include <boost/dll/smart_library.hpp>
- #include <boost/dll/detail/import_mangled_helpers.hpp>
- #include <boost/core/addressof.hpp>
- #include <boost/core/enable_if.hpp>
- #include <boost/type_traits/conditional.hpp>
- #include <boost/type_traits/is_object.hpp>
- #ifdef BOOST_HAS_PRAGMA_ONCE
- # pragma once
- #endif
- namespace boost { namespace dll { namespace experimental {
- namespace detail
- {
- template <class ... Ts>
- class mangled_library_function {
-
- boost::shared_ptr<shared_library> lib_;
- function_tuple<Ts...> f_;
- public:
- constexpr mangled_library_function(const boost::shared_ptr<shared_library>& lib, Ts*... func_ptr) BOOST_NOEXCEPT
- : lib_(lib)
- , f_(func_ptr...)
- {}
-
-
-
-
-
-
-
-
- template <class... Args>
- auto operator()(Args&&... args) const
- -> decltype( f_(static_cast<Args&&>(args)...) )
- {
- return f_(static_cast<Args&&>(args)...);
- }
- };
- template<class Class, class Sequence>
- class mangled_library_mem_fn;
- template <class Class, class ... Ts>
- class mangled_library_mem_fn<Class, sequence<Ts...>> {
-
- typedef mem_fn_tuple<Ts...> call_tuple_t;
- boost::shared_ptr<shared_library> lib_;
- call_tuple_t f_;
- public:
- constexpr mangled_library_mem_fn(const boost::shared_ptr<shared_library>& lib, typename Ts::mem_fn... func_ptr) BOOST_NOEXCEPT
- : lib_(lib)
- , f_(func_ptr...)
- {}
- template <class ClassIn, class... Args>
- auto operator()(ClassIn *cl, Args&&... args) const
- -> decltype( f_(cl, static_cast<Args&&>(args)...) )
- {
- return f_(cl, static_cast<Args&&>(args)...);
- }
- };
- template<class Seq> struct is_variable : boost::false_type {};
- template<typename T> struct is_variable<sequence<T>> : boost::is_object<T> {};
- template <class Sequence,
- bool isFunction = is_function_seq<Sequence>::value,
- bool isMemFn = is_mem_fn_seq <Sequence>::value,
- bool isVariable = is_variable <Sequence>::value>
- struct mangled_import_type;
- template <class ...Args>
- struct mangled_import_type<sequence<Args...>, true,false,false>
- {
- typedef boost::dll::experimental::detail::mangled_library_function<Args...> type;
- static type make(
- const boost::dll::experimental::smart_library& p,
- const std::string& name)
- {
- return type(
- boost::make_shared<shared_library>(p.shared_lib()),
- boost::addressof(p.get_function<Args>(name))...);
- }
- };
- template <class Class, class ...Args>
- struct mangled_import_type<sequence<Class, Args...>, false, true, false>
- {
- typedef typename boost::dll::experimental::detail::make_mem_fn_seq<Class, Args...>::type actual_sequence;
- typedef typename boost::dll::experimental::detail::mangled_library_mem_fn<Class, actual_sequence> type;
- template<class ... ArgsIn>
- static type make_impl(
- const boost::dll::experimental::smart_library& p,
- const std::string & name,
- sequence<ArgsIn...> * )
- {
- return type(boost::make_shared<shared_library>(p.shared_lib()),
- p.get_mem_fn<typename ArgsIn::class_type, typename ArgsIn::func_type>(name)...);
- }
- static type make(
- const boost::dll::experimental::smart_library& p,
- const std::string& name)
- {
- return make_impl(p, name, static_cast<actual_sequence*>(nullptr));
- }
- };
- template <class T>
- struct mangled_import_type<sequence<T>, false, false, true>
- {
- typedef boost::shared_ptr<T> type;
- static type make(
- const boost::dll::experimental::smart_library& p,
- const std::string& name)
- {
- return type(
- boost::make_shared<shared_library>(p.shared_lib()),
- boost::addressof(p.get_variable<T>(name)));
- }
- };
- }
- #ifndef BOOST_DLL_DOXYGEN
- # define BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE inline typename \
- boost::dll::experimental::detail::mangled_import_type<boost::dll::experimental::detail::sequence<Args...>>::type
- #endif
- template <class ...Args>
- BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(const boost::dll::fs::path& lib, const char* name,
- load_mode::type mode = load_mode::default_mode)
- {
- typedef typename boost::dll::experimental::detail::mangled_import_type<
- boost::dll::experimental::detail::sequence<Args...>> type;
- boost::dll::experimental::smart_library p(lib, mode);
-
- return type::make(p, name);
- }
- template <class ...Args>
- BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(const boost::dll::fs::path& lib, const std::string& name,
- load_mode::type mode = load_mode::default_mode)
- {
- return import_mangled<Args...>(lib, name.c_str(), mode);
- }
- template <class ...Args>
- BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(const smart_library& lib, const char* name) {
- typedef typename boost::dll::experimental::detail::mangled_import_type<detail::sequence<Args...>> type;
- return type::make(lib, name);
- }
- template <class ...Args>
- BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(const smart_library& lib, const std::string& name) {
- return import_mangled<Args...>(lib, name.c_str());
- }
- template <class ...Args>
- BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(BOOST_RV_REF(smart_library) lib, const char* name) {
- typedef typename boost::dll::experimental::detail::mangled_import_type<detail::sequence<Args...>> type;
- return type::make(lib, name);
- }
- template <class ...Args>
- BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(BOOST_RV_REF(smart_library) lib, const std::string& name) {
- return import_mangled<Args...>(boost::move(lib), name.c_str());
- }
- template <class ...Args>
- BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(const shared_library& lib, const char* name) {
- typedef typename boost::dll::experimental::detail::mangled_import_type<detail::sequence<Args...>> type;
- boost::shared_ptr<boost::dll::experimental::smart_library> p = boost::make_shared<boost::dll::experimental::smart_library>(lib);
- return type::make(p, name);
- }
- template <class ...Args>
- BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(const shared_library& lib, const std::string& name) {
- return import_mangled<Args...>(lib, name.c_str());
- }
- template <class ...Args>
- BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(BOOST_RV_REF(shared_library) lib, const char* name) {
- typedef typename boost::dll::experimental::detail::mangled_import_type<detail::sequence<Args...>> type;
- boost::dll::experimental::smart_library p(boost::move(lib));
- return type::make(p, name);
- }
- template <class ...Args>
- BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(BOOST_RV_REF(shared_library) lib, const std::string& name) {
- return import_mangled<Args...>(boost::move(lib), name.c_str());
- }
- #undef BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE
- }}}
- #endif
|