PageRenderTime 18ms CodeModel.GetById 14ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 1ms

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