import_class.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2016 Klemens Morgenstern
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt
  5. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. // For more information, see http://www.boost.org
  7. #include "../b2_workarounds.hpp" // contains dll_test::replace_with_full_path
  8. //[import_class_setup
  9. #include <boost/dll/smart_library.hpp>
  10. #include <boost/dll/import_mangled.hpp>
  11. #include <boost/dll/import_class.hpp>
  12. int main(int argc, char* argv[]) {
  13. /*<-*/ b2_workarounds::argv_to_path_guard guard(argc, argv); /*->*/
  14. boost::dll::fs::path lib_path(argv[1]); // argv[1] contains path to directory with our plugin library
  15. smart_library lib(lib_path);// smart library instance
  16. //]
  17. //[import_class_size
  18. auto size_f = import_mangled<std::size_t()>("space::my_plugin::size"); //get the size function
  19. auto size = (*size_f)(); // get the size of the class
  20. //]
  21. //[import_class_value
  22. auto value = import_mangled<int>(lib, "space::my_plugin::value");
  23. //]
  24. //[import_class_ctor
  25. auto cl = import_class<class alias, const std::string&>(lib, "space::my_plugin::some_class", size, "MyName");
  26. //]
  27. //[import_class_name
  28. auto name = import_mangled<const alias, std::string()>(lib, "name");
  29. std::cout << "Name: " << (cl->*name)() << std::endl;
  30. //]
  31. //[import_class_calc
  32. auto calc = import_mangled<alias, float(float, float), int(int, int)>(lib, "calculate");
  33. std::cout << "Calc(float): " (cl->*calc)(5.f, 2.f) << std::endl;
  34. std::cout << "Calc(int): " (cl->*calc)(5, 2) << std::endl;
  35. //]
  36. //[import_class_typeinfo
  37. std::type_info &ti = cl.get_type_info();
  38. //]
  39. }