/test/language/unclassified/uw/aux_uw01yes_no_node.e

http://github.com/tybor/Liberty · Specman e · 137 lines · 89 code · 18 blank · 30 comment · 3 complexity · 4623fdbc64da58c1d23f18821dc57306 MD5 · raw file

  1. note
  2. description:
  3. "nodes with two actions, yes and no, and link to parent node"
  4. status:
  5. "See notice at end of class"
  6. author:
  7. "Ulrich Windl <Ulrich.Windl@rz.uni-regensburg.de>"
  8. version:
  9. "$Revision$"
  10. last_modification:
  11. "$Date$"
  12. deferred class AUX_UW01YES_NO_NODE
  13. inherit
  14. AUX_UW01ACTION_NODE
  15. redefine out
  16. end
  17. feature {ANY}
  18. yes: AUX_UW01YES_NO_NODE -- yes action
  19. no: AUX_UW01YES_NO_NODE -- no action
  20. parent: AUX_UW01YES_NO_NODE -- parent
  21. description: STRING -- description
  22. last_answer: BOOLEAN -- last answer
  23. feature {ANY} -- operations
  24. make_simple (desc: STRING)
  25. -- set minimum features of node
  26. require
  27. valid_desc: desc /= Void and then desc.count > 0
  28. do
  29. description := desc
  30. create {AUX_UW01PREFERRED_LANGUAGE} language
  31. end
  32. make_full (y, n, p: AUX_UW01YES_NO_NODE; desc: STRING)
  33. -- initialize node with name `nam', yes link `y',
  34. -- no link `n', and parent `p'
  35. require
  36. valid_desc: desc /= Void and then desc.count > 0
  37. do
  38. yes := y
  39. no := n
  40. parent := p
  41. description := desc
  42. create {AUX_UW01PREFERRED_LANGUAGE} language
  43. end
  44. set_yes_node (new_node: AUX_UW01YES_NO_NODE)
  45. -- change `yes' to `new_node'
  46. do
  47. yes := new_node
  48. end
  49. set_no_node (new_node: AUX_UW01YES_NO_NODE)
  50. -- change `no' to `new_node'
  51. do
  52. no := new_node
  53. end
  54. set_parent_node (new_node: AUX_UW01YES_NO_NODE)
  55. -- change `parent' to `new_node'
  56. do
  57. parent := new_node
  58. end
  59. yes_action
  60. -- perform "yes" action
  61. require
  62. valid_choice: yes /= Void
  63. do
  64. yes.execute
  65. end
  66. no_action
  67. -- perform "no" action
  68. require
  69. valid_choice: no /= Void
  70. do
  71. no.execute
  72. end
  73. read_answer
  74. -- Ask yes/no question and set `last_answer'
  75. deferred
  76. end
  77. decision: AUX_UW01YES_NO_NODE
  78. -- decide which action to take
  79. do
  80. if last_answer then
  81. Result := yes
  82. if yes /= Void then
  83. yes_action
  84. end
  85. else
  86. Result := no
  87. if no /= Void then
  88. no_action
  89. end
  90. end
  91. end
  92. feature {ANY} -- I/O
  93. out: STRING
  94. -- printable representation
  95. do
  96. Result := description.out
  97. end
  98. invariant
  99. valid_description: description /= Void and then description.count > 0
  100. --consistent_yes: yes /= Void implies yes.parent = Current;
  101. --consistent_no: no /= Void implies no.parent = Current
  102. end -- class AUX_UW01YES_NO_NODE
  103. -- Copyright (C) 1998-2017: by Ulrich Windl
  104. -- Copyright (C) 1998-2017: by Klinikum der Universität Regensburg,
  105. -- D-93042 Regensburg
  106. --
  107. -- This program is free software; you can redistribute it and/or modify
  108. -- it under the terms of the GNU General Public License as published by
  109. -- the Free Software Foundation; either version 2 of the License, or
  110. -- (at your option) any later version.
  111. --
  112. -- This program is distributed in the hope that it will be useful,
  113. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  114. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  115. -- GNU General Public License for more details.
  116. --
  117. -- You should have received a copy of the GNU General Public License
  118. -- along with this program; if not, write to the Free Software
  119. -- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA