Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std type traits #69

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ target_link_libraries(boost_dll
Boost::config
Boost::core
Boost::filesystem
Boost::function
Boost::move
Boost::predef
Boost::smart_ptr
Boost::spirit
Boost::system
Boost::throw_exception
Boost::type_index
Boost::type_traits
Boost::winapi
)

Expand Down
2 changes: 0 additions & 2 deletions build.jam
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ constant boost_dependencies :
/boost/config//boost_config
/boost/core//boost_core
/boost/filesystem//boost_filesystem
/boost/function//boost_function
/boost/predef//boost_predef
/boost/smart_ptr//boost_smart_ptr
/boost/spirit//boost_spirit
/boost/system//boost_system
/boost/throw_exception//boost_throw_exception
/boost/type_index//boost_type_index
/boost/type_traits//boost_type_traits
/boost/winapi//boost_winapi ;

project /boost/dll
Expand Down
7 changes: 0 additions & 7 deletions doc/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,8 @@ local doxygen_params =
\"forcedlinkfs{1}=\\xmlonly<link linkend='boost.dll.fs.\\1'>boost::dll::fs::\\1</link>\\endxmlonly\" \\
\"forcedmacrolink{1}=\\xmlonly<link linkend='\\1'>\\1</link>\\endxmlonly\" "
<doxygen:param>"PREDEFINED= \\
\"BOOST_RV_REF(T)=T&&\" \\
\"BOOST_RV_REF(shared_library)=shared_library&&\" \\
\"BOOST_COPY_ASSIGN_REF(shared_library)=const shared_library&\" \\
\"BOOST_MOVABLE_BUT_NOT_COPYABLE(shared_library)= \\
shared_library(const shared_library&) = delete; \\
shared_library& operator=(const shared_library&) = delete; \" \\
\"BOOST_DLL_IMPORT_RESULT_TYPE=result_type\" \\
\"BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE=result_type\" \\
\"BOOST_EXPLICIT_OPERATOR_BOOL()=explicit operator bool() const noexcept;\" \\
\"BOOST_DLL_DOXYGEN\" "
;

Expand Down
3 changes: 1 addition & 2 deletions doc/dependencies.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
The Boost.DLL is a header only library, but it depends on the following libraries
and they must be available in order to compile programs that use Boost.DLL:

* Boost.System for the boost::system::error_code and boost::system::system_error classes.
* Boost.System for the boost::system::system_error class.
* Boost.Filesystem for directory manipulation.

Refcountable part of Boost.DLL also depends on:

* Boost.Function for creation of a callback system.
* Boost.SharedPtr for reference counting.

[endsect]
Expand Down
2 changes: 1 addition & 1 deletion doc/getting_started.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ boost::dll::shared_library lib("/test/boost/application/libtest_library.so");
Now you can easily import symbols from that library using the `get` and `get_alias` member functions:
```
int plugin_constant = lib.get<const int>("integer_variable");
boost::function<int()> f = lib.get<int()>("function_returning_int");
auto function_ptr = lib.get<int()>("function_returning_int");
int& i = lib.get_alias<int>("alias_to_int_variable");
```
In case of `boost::dll::shared_library` it is safe to use imported symbols only until `boost::dll::shared_library`
Expand Down
5 changes: 2 additions & 3 deletions example/tutorial2/tutorial2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ int main(int argc, char* argv[]) {
/*<-*/ b2_workarounds::argv_to_path_guard guard(argc, argv); /*->*/
boost::dll::fs::path shared_library_path(argv[1]); // argv[1] contains path to directory with our plugin library
shared_library_path /= "my_plugin_aggregator";
typedef boost::shared_ptr<my_plugin_api> (pluginapi_create_t)();
boost::function<pluginapi_create_t> creator;

creator = boost::dll::import_alias<pluginapi_create_t>( // type of imported symbol must be explicitly specified
using pluginapi_create_t = boost::shared_ptr<my_plugin_api>();
auto creator = boost::dll::import_alias<pluginapi_create_t>( // type of imported symbol must be explicitly specified
shared_library_path, // path to library
"create_plugin", // symbol to import
dll::load_mode::append_decorations // do append extensions and prefixes
Expand Down
7 changes: 4 additions & 3 deletions example/tutorial3/tutorial3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ std::size_t search_for_symbols(const std::vector<boost::dll::fs::path>& plugins)
}

// library has symbol, importing...
typedef boost::shared_ptr<my_plugin_api> (pluginapi_create_t)();
boost::function<pluginapi_create_t> creator
= dll::import_alias<pluginapi_create_t>(std::move(lib), "create_plugin");
using pluginapi_create_t = boost::shared_ptr<my_plugin_api>();
auto creator = dll::import_alias<pluginapi_create_t>(
std::move(lib), "create_plugin"
);

std::cout << "Matching plugin name: " << creator()->name() << std::endl;
++ plugins_found;
Expand Down
3 changes: 1 addition & 2 deletions example/tutorial4/load_self.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ int main() {
dll::shared_library self(dll::program_location());

std::cout << "Call function" << std::endl;
boost::function<boost::shared_ptr<my_plugin_api>()> creator
= self.get_alias<boost::shared_ptr<my_plugin_api>()>("create_plugin");
auto creator = self.get_alias<boost::shared_ptr<my_plugin_api>()>("create_plugin");

std::cout << "Computed Value: " << creator()->calculate(2, 2) << std::endl;
//<-
Expand Down
7 changes: 3 additions & 4 deletions example/tutorial5/load_all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace dll = boost::dll;

class plugins_collector {
// Name => plugin
typedef boost::container::map<std::string, dll::shared_library> plugins_t;
using plugins_t = boost::container::map<std::string, dll::shared_library>;

boost::dll::fs::path plugins_directory_;
plugins_t plugins_;
Expand Down Expand Up @@ -52,8 +52,7 @@ class plugins_collector {
//[plugcpp_plugins_collector_load_all
void plugins_collector::load_all() {
namespace fs = ::boost::dll::fs;
typedef fs::path::string_type string_type;
const string_type extension = dll::shared_library::suffix().native();
const auto extension = dll::shared_library::suffix().native();

// Searching a folder for files with '.so' or '.dll' extension
fs::recursive_directory_iterator endit;
Expand All @@ -67,7 +66,7 @@ void plugins_collector::load_all() {
}
/*->*/
// We found a file. Trying to load it
boost::dll::fs::error_code error;
std::error_code error;
dll::shared_library plugin(it->path(), error);
if (error) {
continue;
Expand Down
6 changes: 3 additions & 3 deletions example/tutorial6/on_unload_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

//[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 {
typedef boost::function<void()> callback_t;
typedef on_unload this_type;
using callback_t = std::function<void()> ;
using this_type = on_unload;

~on_unload() {
for (std::size_t i = 0; i < callbacks_.size(); ++i) {
Expand Down
13 changes: 6 additions & 7 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>

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

void print_unloaded() {
std::cout << "unloaded" << std::endl;
Expand All @@ -23,16 +23,15 @@ int main(int argc, char* argv[]) {
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
boost::function<void(const callback_t&)> on_unload
= boost::dll::import_alias<void(const callback_t&)>(
shared_library_path, "on_unload"
);
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
std::cout << "Before library unload." << std::endl;

// Releasing last reference to the library, so that it gets unloaded
on_unload.clear();
on_unload = {};
std::cout << "After library unload." << std::endl;
}
//]
Expand Down
4 changes: 2 additions & 2 deletions example/tutorial8/refcounting_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ inline boost::shared_ptr<my_refcounting_api> bind(my_refcounting_api* plugin) {
inline boost::shared_ptr<my_refcounting_api> get_plugin(
boost::dll::fs::path path, const char* func_name)
{
typedef my_refcounting_api*(func_t)();
boost::function<func_t> creator = boost::dll::import_alias<func_t>(
using func_t = my_refcounting_api*();
auto creator = boost::dll::import_alias<func_t>(
path,
func_name,
boost::dll::load_mode::append_decorations // will be ignored for executable
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
2 changes: 1 addition & 1 deletion include/boost/dll/alias.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ namespace boost { namespace dll {
#else
// Note: we can not use `aggressive_ptr_cast` here, because in that case GCC applies
// different permissions to the section and it causes Segmentation fault.
// Note: we can not use `boost::addressof()` here, because in that case GCC
// Note: we can not use `std::addressof()` here, because in that case GCC
// may optimize away the FunctionOrVar instance and we'll get a pointer to unexisting symbol.
/*!
* \brief Same as \forcedmacrolink{BOOST_DLL_ALIAS} but puts alias name into the user specified section.
Expand Down
14 changes: 4 additions & 10 deletions include/boost/dll/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#endif

#ifdef BOOST_DLL_DOXYGEN
/// Define this macro to make Boost.DLL use C++17's std::filesystem::path, std::system_error and std::error_code.
/// Define this macro to make Boost.DLL use C++17's std::filesystem::path and std::system_error.
#define BOOST_DLL_USE_STD_FS BOOST_DLL_USE_STD_FS

/// This namespace contains aliases to the Boost or C++17 classes. Aliases are configured using BOOST_DLL_USE_STD_FS macro.
Expand All @@ -38,38 +38,32 @@ using system_error = std::conditional_t<BOOST_DLL_USE_STD_FS, std::system_error,

#endif


#ifdef BOOST_DLL_USE_STD_FS
#include <filesystem>

#include <system_error>

namespace boost { namespace dll { namespace fs {

using namespace std::filesystem;

using std::error_code;
using std::system_error;
using std::make_error_code;
using std::errc;
using std::system_category;

}}}

#else // BOOST_DLL_USE_STD_FS

#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
#include <boost/system/error_code.hpp>

namespace boost { namespace dll { namespace fs {

using namespace boost::filesystem;

using boost::system::error_code;
using boost::system::system_error;
using boost::system::errc::make_error_code;
namespace errc = boost::system::errc;
using boost::system::system_category;

}}}

Expand Down
Loading
Loading