diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/signals2/example/passing_slots.cpp | |
parent | Initial commit. (diff) | |
download | ceph-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/signals2/example/passing_slots.cpp')
-rw-r--r-- | src/boost/libs/signals2/example/passing_slots.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/boost/libs/signals2/example/passing_slots.cpp b/src/boost/libs/signals2/example/passing_slots.cpp new file mode 100644 index 00000000..d2c098cb --- /dev/null +++ b/src/boost/libs/signals2/example/passing_slots.cpp @@ -0,0 +1,55 @@ +// Example program showing passing of slots through an interface. +// +// Copyright Douglas Gregor 2001-2004. +// Copyright Frank Mori Hess 2009. +// +// Use, modification and +// distribution is subject to 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) +// For more information, see http://www.boost.org + +#include <iostream> +#include <boost/signals2/signal.hpp> + +//[ passing_slots_defs_code_snippet +// a pretend GUI button +class Button +{ + typedef boost::signals2::signal<void (int x, int y)> OnClick; +public: + typedef OnClick::slot_type OnClickSlotType; + // forward slots through Button interface to its private signal + boost::signals2::connection doOnClick(const OnClickSlotType & slot); + + // simulate user clicking on GUI button at coordinates 52, 38 + void simulateClick(); +private: + OnClick onClick; +}; + +boost::signals2::connection Button::doOnClick(const OnClickSlotType & slot) +{ + return onClick.connect(slot); +} + +void Button::simulateClick() +{ + onClick(52, 38); +} + +void printCoordinates(long x, long y) +{ + std::cout << "(" << x << ", " << y << ")\n"; +} +//] + +int main() +{ +//[ passing_slots_usage_code_snippet + Button button; + button.doOnClick(&printCoordinates); + button.simulateClick(); +//] + return 0; +} |