summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/dll/example/tutorial8
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/dll/example/tutorial8
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/dll/example/tutorial8')
-rw-r--r--src/boost/libs/dll/example/tutorial8/refcounting_api.hpp77
-rw-r--r--src/boost/libs/dll/example/tutorial8/refcounting_plugin.cpp47
-rw-r--r--src/boost/libs/dll/example/tutorial8/refcounting_plugin.hpp17
-rw-r--r--src/boost/libs/dll/example/tutorial8/tutorial8.cpp25
-rw-r--r--src/boost/libs/dll/example/tutorial8/tutorial8_static.cpp23
5 files changed, 189 insertions, 0 deletions
diff --git a/src/boost/libs/dll/example/tutorial8/refcounting_api.hpp b/src/boost/libs/dll/example/tutorial8/refcounting_api.hpp
new file mode 100644
index 00000000..c9178110
--- /dev/null
+++ b/src/boost/libs/dll/example/tutorial8/refcounting_api.hpp
@@ -0,0 +1,77 @@
+// Copyright 2014 Renato Tegon Forti, Antony Polukhin.
+// Copyright 2015-2019 Antony Polukhin.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+//[plugcpp_my_plugin_refcounting_api
+#include "../tutorial_common/my_plugin_api.hpp"
+#include <boost/dll/config.hpp>
+
+class my_refcounting_api: public my_plugin_api {
+public:
+ // Returns path to shared object that holds a plugin.
+ // Must be instantiated in plugin.
+ virtual boost::dll::fs::path location() const = 0;
+};
+//]
+
+
+//[plugcpp_library_holding_deleter_api_bind
+#include <boost/shared_ptr.hpp>
+#include <boost/make_shared.hpp>
+#include <boost/dll/shared_library.hpp>
+
+struct library_holding_deleter {
+ boost::shared_ptr<boost::dll::shared_library> lib_;
+
+ void operator()(my_refcounting_api* p) const {
+ delete p;
+ }
+};
+
+inline boost::shared_ptr<my_refcounting_api> 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<boost::dll::shared_library> lib
+ = boost::make_shared<boost::dll::shared_library>(location);
+
+ library_holding_deleter deleter;
+ deleter.lib_ = lib;
+
+ return boost::shared_ptr<my_refcounting_api>(
+ plugin, deleter
+ );
+}
+//]
+
+//[plugcpp_get_plugin_refcounting
+#include <boost/dll/import.hpp>
+#include <boost/function.hpp>
+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>(
+ path,
+ func_name,
+ boost::dll::load_mode::append_decorations // will be ignored for executable
+ );
+
+ // `plugin` does not hold a reference to shared library. If `creator` will go out of scope,
+ // then `plugin` can not be used.
+ my_refcounting_api* plugin = creator();
+
+ // Returned variable holds a reference to
+ // shared_library and it is safe to use it.
+ return bind( plugin );
+
+ // `creator` goes out of scope here and will be destroyed.
+}
+
+//]
+
+
diff --git a/src/boost/libs/dll/example/tutorial8/refcounting_plugin.cpp b/src/boost/libs/dll/example/tutorial8/refcounting_plugin.cpp
new file mode 100644
index 00000000..bb52cdfa
--- /dev/null
+++ b/src/boost/libs/dll/example/tutorial8/refcounting_plugin.cpp
@@ -0,0 +1,47 @@
+// Copyright 2014 Renato Tegon Forti, Antony Polukhin.
+// Copyright 2015-2019 Antony Polukhin.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// MinGW related workaround
+#define BOOST_DLL_FORCE_ALIAS_INSTANTIATION
+
+//[plugcpp_my_plugin_refcounting
+#include "refcounting_plugin.hpp"
+#include <boost/dll/runtime_symbol_info.hpp> // for this_line_location()
+
+namespace my_namespace {
+
+class my_plugin_refcounting : 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 {
+ return "refcounting";
+ }
+
+ // ...
+ //<-
+ // This block is invisible for Quickbook documentation
+ float calculate(float /*x*/, float /*y*/) {
+ return 0;
+ }
+ //->
+};
+
+} // namespace my_namespace
+
+// Factory method. Returns *simple pointer*!
+my_refcounting_api* create() {
+ return new my_namespace::my_plugin_refcounting();
+}
+
+//]
+
+
+
diff --git a/src/boost/libs/dll/example/tutorial8/refcounting_plugin.hpp b/src/boost/libs/dll/example/tutorial8/refcounting_plugin.hpp
new file mode 100644
index 00000000..990bd214
--- /dev/null
+++ b/src/boost/libs/dll/example/tutorial8/refcounting_plugin.hpp
@@ -0,0 +1,17 @@
+// Copyright 2014 Renato Tegon Forti, Antony Polukhin.
+// Copyright 2015-2019 Antony Polukhin.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+//[plugcpp_my_plugin_refcounting_hpp
+#include "refcounting_api.hpp"
+#include <boost/dll/alias.hpp> // for BOOST_DLL_ALIAS
+
+my_refcounting_api* create(); // defined in plugin
+BOOST_DLL_ALIAS(create, create_refc_plugin)
+//]
+
+
+
diff --git a/src/boost/libs/dll/example/tutorial8/tutorial8.cpp b/src/boost/libs/dll/example/tutorial8/tutorial8.cpp
new file mode 100644
index 00000000..ef169a99
--- /dev/null
+++ b/src/boost/libs/dll/example/tutorial8/tutorial8.cpp
@@ -0,0 +1,25 @@
+// Copyright 2014 Renato Tegon Forti, Antony Polukhin.
+// Copyright 2015-2019 Antony Polukhin.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include "../b2_workarounds.hpp"
+
+//[callplugcpp_tutorial8
+#include <iostream>
+#include "refcounting_api.hpp"
+
+int main(int argc, char* argv[]) {
+ /*<-*/ b2_workarounds::argv_to_path_guard guard(argc, argv); /*->*/
+ boost::shared_ptr<my_refcounting_api> plugin = get_plugin(
+ boost::dll::fs::path(argv[1]) / "refcounting_plugin",
+ "create_refc_plugin"
+ );
+
+ std::cout << "Plugin name: " << plugin->name()
+ << ", \nlocation: " << plugin->location()
+ << std::endl;
+}
+//]
diff --git a/src/boost/libs/dll/example/tutorial8/tutorial8_static.cpp b/src/boost/libs/dll/example/tutorial8/tutorial8_static.cpp
new file mode 100644
index 00000000..810d322f
--- /dev/null
+++ b/src/boost/libs/dll/example/tutorial8/tutorial8_static.cpp
@@ -0,0 +1,23 @@
+// Copyright 2014 Renato Tegon Forti, Antony Polukhin.
+// Copyright 2015-2019 Antony Polukhin.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+//[callplugcpp_tutorial8_static
+#include <boost/dll/runtime_symbol_info.hpp> // program_location()
+#include <iostream>
+#include "refcounting_plugin.hpp"
+
+int main() {
+ boost::shared_ptr<my_refcounting_api> plugin = get_plugin(
+ boost::dll::program_location(),
+ "create_refc_plugin"
+ );
+
+ std::cout << "Plugin name: " << plugin->name()
+ << ", \nlocation: " << plugin->location()
+ << std::endl;
+}
+//]