~ubuntu-branches/debian/sid/boost1.49/sid

« back to all changes in this revision

Viewing changes to libs/signals2/example/passing_slots.cpp

  • Committer: Package Import Robot
  • Author(s): Steve M. Robbins
  • Date: 2012-02-26 00:31:44 UTC
  • Revision ID: package-import@ubuntu.com-20120226003144-eaytp12cbf6ubpms
Tags: upstream-1.49.0
ImportĀ upstreamĀ versionĀ 1.49.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Example program showing passing of slots through an interface.
 
2
//
 
3
// Copyright Douglas Gregor 2001-2004.
 
4
// Copyright Frank Mori Hess 2009.
 
5
//
 
6
// Use, modification and
 
7
// distribution is subject to the Boost Software License, Version
 
8
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
 
9
// http://www.boost.org/LICENSE_1_0.txt)
 
10
// For more information, see http://www.boost.org
 
11
 
 
12
#include <iostream>
 
13
#include <boost/signals2/signal.hpp>
 
14
 
 
15
//[ passing_slots_defs_code_snippet
 
16
// a pretend GUI button
 
17
class Button
 
18
{
 
19
  typedef boost::signals2::signal<void (int x, int y)> OnClick;
 
20
public:
 
21
  typedef OnClick::slot_type OnClickSlotType;
 
22
  // forward slots through Button interface to its private signal
 
23
  boost::signals2::connection doOnClick(const OnClickSlotType & slot);
 
24
 
 
25
  // simulate user clicking on GUI button at coordinates 52, 38
 
26
  void simulateClick();
 
27
private:
 
28
  OnClick onClick;
 
29
};
 
30
 
 
31
boost::signals2::connection Button::doOnClick(const OnClickSlotType & slot)
 
32
{
 
33
  return onClick.connect(slot);
 
34
}
 
35
 
 
36
void Button::simulateClick()
 
37
{
 
38
  onClick(52, 38);
 
39
}
 
40
 
 
41
void printCoordinates(long x, long y)
 
42
{
 
43
  std::cout << "(" << x << ", " << y << ")\n";
 
44
}
 
45
//]
 
46
 
 
47
int main()
 
48
{
 
49
//[ passing_slots_usage_code_snippet
 
50
  Button button;
 
51
  button.doOnClick(&printCoordinates);
 
52
  button.simulateClick();
 
53
//]
 
54
  return 0;
 
55
}