]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/dll/example/tutorial6/on_unload_lib.cpp
1 // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
2 // Copyright 2015 Antony Polukhin.
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt
6 // or copy at http://www.boost.org/LICENSE_1_0.txt)
8 // MinGW related workaround
9 #define BOOST_DLL_FORCE_ALIAS_INSTANTIATION
12 #include <boost/dll/alias.hpp> // for BOOST_DLL_ALIAS
13 #include <boost/function.hpp>
16 namespace my_namespace
{
19 typedef boost::function
<void()> callback_t
;
20 typedef on_unload this_type
;
23 for (std::size_t i
= 0; i
< callbacks_
.size(); ++i
) {
24 callback_t
& function
= callbacks_
[i
];
25 function(); // calling the callback
30 static void add(const callback_t
& function
) {
31 static this_type instance
;
32 instance
.callbacks_
.push_back(function
);
36 std::vector
<callback_t
> callbacks_
;
37 on_unload() {} // prohibit construction outside of the `add` function
40 // Exporting the static "add" function with name "on_unload"
41 BOOST_DLL_ALIAS(my_namespace::on_unload::add
, on_unload
)
43 } // namespace my_namespace