From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/signals2/example/passing_slots.cpp | 55 +++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/boost/libs/signals2/example/passing_slots.cpp (limited to 'src/boost/libs/signals2/example/passing_slots.cpp') 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 +#include + +//[ passing_slots_defs_code_snippet +// a pretend GUI button +class Button +{ + typedef boost::signals2::signal 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; +} -- cgit v1.2.3