/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

  1. class 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. create {ANY}
  10. make
  11. feature {ANY}
  12. value_changed: SIGNAL_1[TUPLE[STRING, INTEGER, INTEGER]] --declare variable of SIGNAL type, never inherit form SIGNAL.
  13. value: INTEGER
  14. desc: STRING
  15. feature {}
  16. make
  17. do
  18. create value_changed.make
  19. value_changed.connect(agent foo(?))
  20. value_changed.connect(agent foo(?))
  21. value_changed.connect(agent foo(?))
  22. io.put_string("Enter description: ")
  23. io.read_line
  24. desc := io.last_string.twin
  25. io.put_string("Enter integer value: ")
  26. io.read_integer
  27. value := io.last_integer
  28. value_changed.emit([desc, value, value * value])
  29. value := value + 1
  30. value_changed.emit([desc, value, value * value])
  31. value := value + 1
  32. value_changed.emit([desc, value, value * value])
  33. end
  34. feature {ANY}
  35. foo (v: TUPLE[STRING, INTEGER, INTEGER])
  36. do
  37. io.put_string(v.first)
  38. io.put_string(once ": ")
  39. io.put_integer(v.second)
  40. io.put_string(once " ")
  41. io.put_integer(v.third)
  42. io.put_new_line
  43. end
  44. end -- class EXAMPLE3