diff --git a/doc/tutorial.qbk b/doc/tutorial.qbk index f5abb97f..17a7cf54 100644 --- a/doc/tutorial.qbk +++ b/doc/tutorial.qbk @@ -27,7 +27,7 @@ Now let's make a DLL/DSO library that will holds implementation of plugin interf [import ../example/tutorial1/my_plugin_sum.cpp] [plugcpp_my_plugin_sum] -Simple application that loads plugin using the [funcref boost::dll::import] +Simple application that loads plugin using the [funcref boost::dll::import_symbol] and [enumref boost::dll::load_mode::type append_decorations]: [import ../example/tutorial1/tutorial1.cpp] @@ -312,7 +312,7 @@ __to_top [section Advanced library reference counting] -As noted in documentation to the [funcref boost::dll::import] +As noted in documentation to the [funcref boost::dll::import_symbol] variables and functions returned from those functions hold a reference to the shared library. However nested objects and objects that are returned by `import*` functions do not hold a reference to the shared library. There's no way to solve this issue on the Boost.DLL library level, but you can take care of this problem by your own. Here's an example how this @@ -339,7 +339,7 @@ Now let's define the plugin: This plugin does not differ much from our previous examples except the additional method that calls [funcref boost::dll::this_line_location] and `create()` function that returns a simple pointer instead of -`boost::shared_ptr`. +`std::shared_ptr`. Now lets make a function that binds a newly created instance of `my_refcounting_api` to a shared library: [plugcpp_library_holding_deleter_api_bind] @@ -348,7 +348,7 @@ In `bind` method we call `plugin->location()`. This call results in a call to [funcref boost::dll::this_line_location] and returns the plugin location. Then a `shared_ptr` that holds a `shared_library` is created using the `make_shared` call. -After that we construct a `boost::shared_ptr` with a `library_holding_deleter` that keeps an instance of the shared library. +After that we construct a `std::shared_ptr` with a `library_holding_deleter` that keeps an instance of the shared library. [note Use `std::unique_ptr` instead of `my_refcounting_api*` in production code to avoid memory leaks when `plugin->location()` throws or when some other class rises an exception.] @@ -389,7 +389,7 @@ __to_top [section Importing a C function from Windows dll] This a trivial example, but it has one tricky place. When you are importing a C function by *it's name* -you must use [funcref boost::dll::import], not [funcref boost::dll::import_alias]: +you must use [funcref boost::dll::import_symbol], not [funcref boost::dll::import_alias]: [import ../example/tutorial9/tutorial9.cpp] [callplugcpp_tutorial9] diff --git a/example/tutorial1/my_plugin_sum.cpp b/example/tutorial1/my_plugin_sum.cpp index fa42275e..e8b8af2d 100644 --- a/example/tutorial1/my_plugin_sum.cpp +++ b/example/tutorial1/my_plugin_sum.cpp @@ -14,17 +14,17 @@ namespace my_namespace { -class my_plugin_sum : public my_plugin_api { +class my_plugin_sum final: public my_plugin_api { public: my_plugin_sum() { std::cout << "Constructing my_plugin_sum" << std::endl; } - std::string name() const { + std::string name() const override { return "sum"; } - float calculate(float x, float y) { + float calculate(float x, float y) override { return x + y; } diff --git a/example/tutorial1/tutorial1.cpp b/example/tutorial1/tutorial1.cpp index bcc034d5..528830b7 100644 --- a/example/tutorial1/tutorial1.cpp +++ b/example/tutorial1/tutorial1.cpp @@ -17,10 +17,9 @@ namespace dll = boost::dll; int main(int argc, char* argv[]) { /*<-*/ b2_workarounds::argv_to_path_guard guard(argc, argv); /*->*/ boost::dll::fs::path lib_path(argv[1]); // argv[1] contains path to directory with our plugin library - boost::shared_ptr plugin; // variable to hold a pointer to plugin variable std::cout << "Loading the plugin" << std::endl; - plugin = dll::import_symbol( // type of imported symbol is located between `<` and `>` + auto plugin = dll::import_symbol( // type of imported symbol is located between `<` and `>` lib_path / "my_plugin_sum", // path to the library and library name "plugin", // name of the symbol to import dll::load_mode::append_decorations // makes `libmy_plugin_sum.so` or `my_plugin_sum.dll` from `my_plugin_sum` diff --git a/example/tutorial2/my_plugin_aggregator.cpp b/example/tutorial2/my_plugin_aggregator.cpp index 67738dfa..15b54646 100644 --- a/example/tutorial2/my_plugin_aggregator.cpp +++ b/example/tutorial2/my_plugin_aggregator.cpp @@ -6,7 +6,7 @@ // or copy at http://www.boost.org/LICENSE_1_0.txt) #include -#include +#include // MinGW related workaround #define BOOST_DLL_FORCE_ALIAS_INSTANTIATION @@ -17,23 +17,23 @@ namespace my_namespace { -class my_plugin_aggregator : public my_plugin_api { +class my_plugin_aggregator final: public my_plugin_api { float aggr_; my_plugin_aggregator() : aggr_(0) {} public: - std::string name() const { + std::string name() const override { return "aggregator"; } - float calculate(float x, float y) { + float calculate(float x, float y) override { aggr_ += x + y; return aggr_; } // Factory method - static boost::shared_ptr create() { - return boost::shared_ptr( + static std::shared_ptr create() { + return std::shared_ptr( new my_plugin_aggregator() ); } diff --git a/example/tutorial2/tutorial2.cpp b/example/tutorial2/tutorial2.cpp index 29e6d256..15151733 100644 --- a/example/tutorial2/tutorial2.cpp +++ b/example/tutorial2/tutorial2.cpp @@ -9,7 +9,6 @@ //[callplugcpp_tutorial2 #include // for import_alias -#include #include #include "../tutorial_common/my_plugin_api.hpp" @@ -20,14 +19,14 @@ int main(int argc, char* 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"; - using pluginapi_create_t = boost::shared_ptr(); + using pluginapi_create_t = std::shared_ptr(); auto creator = boost::dll::import_alias( // 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 ); - boost::shared_ptr plugin = creator(); + std::shared_ptr plugin = creator(); std::cout << "plugin->calculate(1.5, 1.5) call: " << plugin->calculate(1.5, 1.5) << std::endl; std::cout << "plugin->calculate(1.5, 1.5) second call: " << plugin->calculate(1.5, 1.5) << std::endl; std::cout << "Plugin Name: " << plugin->name() << std::endl; diff --git a/example/tutorial3/tutorial3.cpp b/example/tutorial3/tutorial3.cpp index 165956f3..a73ab679 100644 --- a/example/tutorial3/tutorial3.cpp +++ b/example/tutorial3/tutorial3.cpp @@ -8,9 +8,8 @@ #include "../b2_workarounds.hpp" //[callplugcpp_tutorial3 #include // for import_alias -#include -#include #include +#include #include "../tutorial_common/my_plugin_api.hpp" namespace dll = boost::dll; @@ -27,7 +26,7 @@ std::size_t search_for_symbols(const std::vector& plugins) } // library has symbol, importing... - using pluginapi_create_t = boost::shared_ptr(); + using pluginapi_create_t = std::shared_ptr(); auto creator = dll::import_alias( std::move(lib), "create_plugin" ); diff --git a/example/tutorial4/load_self.cpp b/example/tutorial4/load_self.cpp index 7b8e83a4..c2bd0ab9 100644 --- a/example/tutorial4/load_self.cpp +++ b/example/tutorial4/load_self.cpp @@ -12,8 +12,8 @@ #include // for shared_library #include // for program_location() #include "static_plugin.hpp" // without this headers some compilers may optimize out the `create_plugin` symbol -#include #include +#include namespace dll = boost::dll; @@ -21,7 +21,7 @@ int main() { dll::shared_library self(dll::program_location()); std::cout << "Call function" << std::endl; - auto creator = self.get_alias()>("create_plugin"); + auto creator = self.get_alias()>("create_plugin"); std::cout << "Computed Value: " << creator()->calculate(2, 2) << std::endl; //<- diff --git a/example/tutorial4/static_plugin.cpp b/example/tutorial4/static_plugin.cpp index f1095407..72da73f7 100644 --- a/example/tutorial4/static_plugin.cpp +++ b/example/tutorial4/static_plugin.cpp @@ -8,22 +8,22 @@ //[plugcpp_my_plugin_staic_impl #include "static_plugin.hpp" // this is essential, BOOST_SYMBOL_ALIAS must be seen in this file -#include #include +#include namespace my_namespace { -class my_plugin_static : public my_plugin_api { +class my_plugin_static final : public my_plugin_api { public: my_plugin_static() { std::cout << "Constructing my_plugin_static" << std::endl; } - std::string name() const { + std::string name() const override { return "static"; } - float calculate(float x, float y) { + float calculate(float x, float y) override { return x - y; } @@ -32,8 +32,8 @@ class my_plugin_static : public my_plugin_api { } }; -boost::shared_ptr create_plugin() { - return boost::make_shared(); +std::shared_ptr create_plugin() { + return std::make_shared(); } } // namespace my_namespace diff --git a/example/tutorial4/static_plugin.hpp b/example/tutorial4/static_plugin.hpp index e51374ea..e236207b 100644 --- a/example/tutorial4/static_plugin.hpp +++ b/example/tutorial4/static_plugin.hpp @@ -7,11 +7,11 @@ //[plugcpp_my_plugin_static #include // for BOOST_DLL_ALIAS -#include +#include #include "../tutorial_common/my_plugin_api.hpp" namespace my_namespace { - boost::shared_ptr create_plugin(); // Forward declaration + std::shared_ptr create_plugin(); // Forward declaration } // namespace my_namespace BOOST_DLL_ALIAS( diff --git a/example/tutorial5/load_all.cpp b/example/tutorial5/load_all.cpp index 4a1464c1..9d68002b 100644 --- a/example/tutorial5/load_all.cpp +++ b/example/tutorial5/load_all.cpp @@ -87,7 +87,7 @@ void plugins_collector::load_all() { void plugins_collector::insert_plugin(dll::shared_library&& lib) { std::string plugin_name; if (lib.has("create_plugin")) { - plugin_name = lib.get_alias()>("create_plugin")()->name(); + plugin_name = lib.get_alias()>("create_plugin")()->name(); } else if (lib.has("plugin")) { plugin_name = lib.get("plugin").name(); } else { diff --git a/example/tutorial8/refcounting_api.hpp b/example/tutorial8/refcounting_api.hpp index b06d06e7..88b75821 100644 --- a/example/tutorial8/refcounting_api.hpp +++ b/example/tutorial8/refcounting_api.hpp @@ -19,30 +19,28 @@ class my_refcounting_api: public my_plugin_api { //[plugcpp_library_holding_deleter_api_bind -#include -#include +#include #include struct library_holding_deleter { - boost::shared_ptr lib_; + std::shared_ptr lib_; void operator()(my_refcounting_api* p) const { delete p; } }; -inline boost::shared_ptr bind(my_refcounting_api* plugin) { +inline std::shared_ptr bind(my_refcounting_api* plugin) { // getting location of the shared library that holds the plugin boost::dll::fs::path location = plugin->location(); // `make_shared` is an efficient way to create a shared pointer - boost::shared_ptr lib - = boost::make_shared(location); + auto lib = std::make_shared(location); library_holding_deleter deleter; deleter.lib_ = lib; - return boost::shared_ptr( + return std::shared_ptr( plugin, deleter ); } @@ -50,8 +48,7 @@ inline boost::shared_ptr bind(my_refcounting_api* plugin) { //[plugcpp_get_plugin_refcounting #include -#include -inline boost::shared_ptr get_plugin( +inline std::shared_ptr get_plugin( boost::dll::fs::path path, const char* func_name) { using func_t = my_refcounting_api*(); diff --git a/example/tutorial8/refcounting_plugin.cpp b/example/tutorial8/refcounting_plugin.cpp index b4b5d78f..5e6d4377 100644 --- a/example/tutorial8/refcounting_plugin.cpp +++ b/example/tutorial8/refcounting_plugin.cpp @@ -14,21 +14,21 @@ namespace my_namespace { -class my_plugin_refcounting : public my_refcounting_api { +class my_plugin_refcounting final: public my_refcounting_api { public: // Must be instantiated in plugin boost::dll::fs::path location() const { return boost::dll::this_line_location(); // location of this plugin } - std::string name() const { + std::string name() const override { return "refcounting"; } // ... //<- // This block is invisible for Quickbook documentation - float calculate(float /*x*/, float /*y*/) { + float calculate(float /*x*/, float /*y*/) override { return 0; } //-> diff --git a/example/tutorial8/tutorial8.cpp b/example/tutorial8/tutorial8.cpp index b537cd3b..d350e5b5 100644 --- a/example/tutorial8/tutorial8.cpp +++ b/example/tutorial8/tutorial8.cpp @@ -13,7 +13,7 @@ int main(int argc, char* argv[]) { /*<-*/ b2_workarounds::argv_to_path_guard guard(argc, argv); /*->*/ - boost::shared_ptr plugin = get_plugin( + std::shared_ptr plugin = get_plugin( boost::dll::fs::path(argv[1]) / "refcounting_plugin", "create_refc_plugin" ); diff --git a/example/tutorial8/tutorial8_static.cpp b/example/tutorial8/tutorial8_static.cpp index 46e61dc3..ab6d291f 100644 --- a/example/tutorial8/tutorial8_static.cpp +++ b/example/tutorial8/tutorial8_static.cpp @@ -11,7 +11,7 @@ #include "refcounting_plugin.hpp" int main() { - boost::shared_ptr plugin = get_plugin( + std::shared_ptr plugin = get_plugin( boost::dll::program_location(), "create_refc_plugin" ); diff --git a/example/tutorial_common/my_plugin_api.hpp b/example/tutorial_common/my_plugin_api.hpp index 41898115..254abeca 100644 --- a/example/tutorial_common/my_plugin_api.hpp +++ b/example/tutorial_common/my_plugin_api.hpp @@ -16,7 +16,7 @@ class BOOST_SYMBOL_VISIBLE my_plugin_api { virtual std::string name() const = 0; virtual float calculate(float x, float y) = 0; - virtual ~my_plugin_api() {} + virtual ~my_plugin_api() = default; }; //]