PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/signal/example3.e

http://github.com/tybor/Liberty
Specman e | 51 lines | 37 code | 7 blank | 7 comment | 0 complexity | b946ff13de0aac07a9059e2d33a65279 MD5 | raw file
 1class EXAMPLE3
 2   -- This example shows that by using TUPLE you are able to send a signal
 3   -- with an arbitrary amount of information using SIGNAL_1
 4   -- Of course it is simpler to use SIGNAL_2 for 2 variables.
 5   -- NOTE: you can un-register your procedure from the signal. Have a look
 6   -- at `last_connect_id' and `disconnect' in signal_*.e
 7   -- `last_connect_id' has to be called just after `connect' call. Principle
 8   -- is based on the same ideas as `last_string' in TEXT_FILE_READ.
 9
10create {ANY}
11   make
12
13feature {ANY}
14   value_changed: SIGNAL_1[TUPLE[STRING, INTEGER, INTEGER]] --declare variable of SIGNAL type, never inherit form SIGNAL.
15
16   value: INTEGER
17
18   desc: STRING
19
20feature {}
21   make
22      do
23         create value_changed.make
24         value_changed.connect(agent foo(?))
25         value_changed.connect(agent foo(?))
26         value_changed.connect(agent foo(?))
27         io.put_string("Enter description: ")
28         io.read_line
29         desc := io.last_string.twin
30         io.put_string("Enter integer value: ")
31         io.read_integer
32         value := io.last_integer
33         value_changed.emit([desc, value, value * value])
34         value := value + 1
35         value_changed.emit([desc, value, value * value])
36         value := value + 1
37         value_changed.emit([desc, value, value * value])
38      end
39
40feature {ANY}
41   foo (v: TUPLE[STRING, INTEGER, INTEGER])
42      do
43         io.put_string(v.first)
44         io.put_string(once ": ")
45         io.put_integer(v.second)
46         io.put_string(once " ")
47         io.put_integer(v.third)
48         io.put_new_line
49      end
50
51end -- class EXAMPLE3