Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/signals/example/button_click.cpp @ 69

Last change on this file since 69 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 1.3 KB
Line 
1// Boost.Signals library
2
3// Copyright Douglas Gregor 2001-2003. Use, modification and
4// distribution is subject to the Boost Software License, Version
5// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt)
7
8// For more information, see http://www.boost.org
9
10#include <boost/bind.hpp>
11#include <boost/signals/signal1.hpp>
12#include <iostream>
13
14struct print_string : public boost::signals::trackable {
15  typedef void result_type;
16
17  void print(const std::string& s) const { std::cout << s << std::endl; }
18};
19
20struct my_button {
21  typedef boost::signal1<void, const std::string&> click_signal_type;
22  typedef click_signal_type::slot_type click_slot_type;
23
24  boost::signals::connection on_click_connect(const click_slot_type& s)
25    { return on_click.connect(s); }
26
27  my_button(const std::string& l) : label(l) {}
28
29  virtual ~my_button() {}
30
31  void click();
32
33protected:
34  virtual void clicked() { on_click(label); }
35
36private:
37  std::string label;
38  click_signal_type on_click;
39};
40
41void my_button::click()
42{
43  clicked();
44}
45
46int main()
47{
48  my_button* b = new my_button("OK!");
49  print_string* ps = new print_string();
50  b->on_click_connect(boost::bind(&print_string::print, ps, _1));
51
52  b->click(); // prints OK!
53
54  delete ps;
55
56  b->click(); // prints nothing
57
58  return 0;
59}
Note: See TracBrowser for help on using the repository browser.