Skip to content

Commit

Permalink
more cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
apolukhin committed Dec 17, 2024
1 parent f8b1153 commit 06d3717
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 34 deletions.
4 changes: 2 additions & 2 deletions example/tutorial6/on_unload_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

//[plugcpp_on_unload
#include <boost/dll/alias.hpp> // for BOOST_DLL_ALIAS
#include <boost/function.hpp>
#include <functional>
#include <vector>

namespace my_namespace {

struct on_unload {
using callback_t = boost::function<void()> ;
using callback_t = std::function<void()> ;
using this_type = on_unload;

~on_unload() {
Expand Down
21 changes: 10 additions & 11 deletions example/tutorial6/tutorial6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

//[callplugcpp_tutorial6
#include <boost/dll/import.hpp>
#include <boost/function.hpp>
#include <functional>
#include <iostream>

using callback_t = boost::function<void()>;
using callback_t = std::function<void()> ;

void print_unloaded() {
std::cout << "unloaded" << std::endl;
Expand All @@ -22,17 +22,16 @@ int main(int argc, char* argv[]) {
// argv[1] contains full path to our plugin library
boost::dll::fs::path shared_library_path = /*<-*/ b2_workarounds::first_lib_from_argv(argc, argv); /*->*/ //=argv[1];

{
// loading library and getting a function from it
auto on_unload = boost::dll::import_alias<void(const callback_t&)>(
shared_library_path, "on_unload"
);
// loading library and getting a function from it
std::function<void(const callback_t&)> on_unload = boost::dll::import_alias<void(const callback_t&)>(
shared_library_path, "on_unload"
);

on_unload(&print_unloaded); // adding a callback
on_unload(&print_unloaded); // adding a callback
std::cout << "Before library unload." << std::endl;

std::cout << "Before library unload." << std::endl;
// Releasing last reference to the library, so that it gets unloaded
}
// Releasing last reference to the library, so that it gets unloaded
on_unload = {};
std::cout << "After library unload." << std::endl;
}
//]
Expand Down
9 changes: 4 additions & 5 deletions example/tutorial9/tutorial9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//[callplugcpp_tutorial9
#include <boost/dll/import.hpp> // for dll::import
#include <boost/dll/shared_library.hpp> // for dll::shared_library
#include <boost/function.hpp>
#include <functional>
#include <iostream>
#include <windows.h>

Expand All @@ -29,15 +29,14 @@ int main() {
);
std::cout << "0.0 GetStdHandle() returned " << get_std_handle(STD_OUTPUT_HANDLE) << std::endl;

// You may put the `get_std_handle` into boost::function<>. But boost::function<Signature> can not compile with
// You may put the `get_std_handle` into std::function<>. But std::function<Signature> may not compile with
// Signature template parameter that contains calling conventions, so you'll have to remove the calling convention.
boost::function<HANDLE(DWORD)> get_std_handle2 = get_std_handle;
std::function<HANDLE(DWORD)> get_std_handle2 = get_std_handle;
std::cout << "0.1 GetStdHandle() returned " << get_std_handle2(STD_OUTPUT_HANDLE) << std::endl;
/*<-*/
#endif /*->*/

// OPTION #1, does not require C++11. But without C++11 dll::import<> can not handle calling conventions,
// so you'll need to hand write the import.
// OPTION #1, hand write the import.
dll::shared_library lib("Kernel32.dll", dll::load_mode::search_system_folders);
GetStdHandle_t& func = lib.get<GetStdHandle_t>("GetStdHandle");

Expand Down
4 changes: 2 additions & 2 deletions include/boost/dll/import.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace detail {
* \b Examples:
*
* \code
* boost::function<int(int)> f = import_symbol<int(int)>("test_lib.so", "integer_func_name");
* std::function<int(int)> f = import_symbol<int(int)>("test_lib.so", "integer_func_name");
*
* auto f_cpp11 = import_symbol<int(int)>("test_lib.so", "integer_func_name");
* \endcode
Expand Down Expand Up @@ -171,7 +171,7 @@ BOOST_DLL_IMPORT_RESULT_TYPE import_symbol(shared_library&& lib, const std::stri
* \b Examples:
*
* \code
* boost::function<int(int)> f = import_alias<int(int)>("test_lib.so", "integer_func_alias_name");
* std::function<int(int)> f = import_alias<int(int)>("test_lib.so", "integer_func_alias_name");
*
* auto f_cpp11 = import_alias<int(int)>("test_lib.so", "integer_func_alias_name");
* \endcode
Expand Down
2 changes: 1 addition & 1 deletion include/boost/dll/import_mangled.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ struct mangled_import_type<sequence<T>, false, false, true> //is variable
* \b Examples:
*
* \code
* boost::function<int(int)> f = import_mangled<int(int)>("test_lib.so", "integer_func_name");
* std::function<int(int)> f = import_mangled<int(int)>("test_lib.so", "integer_func_name");
*
* auto f_cpp11 = import_mangled<int(int)>("test_lib.so", "integer_func_name");
* \endcode
Expand Down
4 changes: 2 additions & 2 deletions test/cpp_import_class_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using namespace std;
#include <boost/core/lightweight_test.hpp>
#include <boost/filesystem.hpp>
#include <boost/variant.hpp>
#include <boost/function.hpp>
#include <functional>

#define L cout << __LINE__ << endl;

Expand Down Expand Up @@ -92,7 +92,7 @@ int main(int argc, char* argv[])
BOOST_TEST((cl->*fun2)(5 ,2 ) == 7 );

//test if it binds.
boost::function<int(override_class* const, int, int)> mem_fn_obj = func;
std::function<int(override_class* const, int, int)> mem_fn_obj = func;


const std::type_info & ti = cl.get_type_info();
Expand Down
4 changes: 2 additions & 2 deletions test/cpp_import_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include <boost/core/lightweight_test.hpp>
#include <boost/filesystem.hpp>
#include <boost/variant.hpp>
#include <boost/function.hpp>

#include <functional>
#include <iostream>

struct override_class
Expand Down Expand Up @@ -51,7 +51,7 @@ int main(int argc, char* argv[])
ovl(5.0);
BOOST_TEST(*sp_variable == 5.0);

boost::function<void(int)> f_test = ovl;//test if it binds
std::function<void(int)> f_test = ovl;//test if it binds
f_test(-2);
BOOST_TEST(*unscoped_var == -2);

Expand Down
18 changes: 9 additions & 9 deletions test/shared_library_get_symbol_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "../example/b2_workarounds.hpp"
#include <boost/dll.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/function.hpp>
#include <functional>
#include <boost/fusion/container.hpp>
// lib functions

Expand All @@ -35,7 +35,7 @@ void refcountable_test(boost::dll::fs::path shared_library_path) {
std::vector<int> v(1000);

{
boost::function<say_hello_func> sz2
std::function<say_hello_func> sz2
= import_symbol<say_hello_func>(shared_library_path, "say_hello");

sz2();
Expand All @@ -52,17 +52,17 @@ void refcountable_test(boost::dll::fs::path shared_library_path) {
#endif

{
boost::function<std::size_t(const std::vector<int>&)> sz
std::function<std::size_t(const std::vector<int>&)> sz
= import_alias<std::size_t(const std::vector<int>&)>(shared_library_path, "foo_bar");
BOOST_TEST(sz(v) == 1000);
}


{
boost::function<do_share_t> f;
std::function<do_share_t> f;

{
boost::function<do_share_t> f2 = import_alias<do_share_t>(shared_library_path, "do_share");
std::function<do_share_t> f2 = import_alias<do_share_t>(shared_library_path, "do_share");
f = f2;
}

Expand Down Expand Up @@ -91,13 +91,13 @@ void refcountable_test(boost::dll::fs::path shared_library_path) {
}

{
boost::function<int&()> f = import_alias<int&()>(shared_library_path, "ref_returning_function");
std::function<int&()> f = import_alias<int&()>(shared_library_path, "ref_returning_function");
BOOST_TEST(f() == 0);

f() = 10;
BOOST_TEST(f() == 10);

boost::function<int&()> f1 = import_alias<int&()>(shared_library_path, "ref_returning_function");
std::function<int&()> f1 = import_alias<int&()>(shared_library_path, "ref_returning_function");
BOOST_TEST(f1() == 10);

f1() += 10;
Expand Down Expand Up @@ -157,7 +157,7 @@ int main(int argc, char* argv[]) {

BOOST_TEST(sl.get<const int>("const_integer_g") == 777);

boost::function<int(int)> inc = sl.get<int(int)>("increment");
std::function<int(int)> inc = sl.get<int(int)>("increment");
BOOST_TEST(inc(1) == 2);
BOOST_TEST(inc(2) == 3);
BOOST_TEST(inc(3) == 4);
Expand All @@ -170,7 +170,7 @@ int main(int argc, char* argv[]) {


// Checking aliases
boost::function<std::size_t(const std::vector<int>&)> sz
std::function<std::size_t(const std::vector<int>&)> sz
= sl.get_alias<std::size_t(const std::vector<int>&)>("foo_bar");

std::vector<int> v(10);
Expand Down

0 comments on commit 06d3717

Please sign in to comment.