/tutorial/backtracking/logigram/item_collector.e
Specman e | 83 lines | 48 code | 9 blank | 26 comment | 1 complexity | 4138077cbc9769fdd3a7637d47100ae5 MD5 | raw file
1-- See the Copyright notice at the end of this file. 2-- 3class ITEM_COLLECTOR 4 -- 5 -- collector of items in the constraints 6 -- 7 8creation {ANY} 9 make 10 11feature {ANY} 12 item_set: HASHED_SET[ITEM_ITEM] 13 -- the collected items 14 15 var_set: HASHED_SET[ITEM_VAR] 16 -- the collected vars 17 18 make is 19 do 20 create item_set.with_capacity(10) 21 create var_set.with_capacity(10) 22 ensure 23 not (has_item or has_var) 24 end 25 26 clear is 27 do 28 item_set.clear_count 29 var_set.clear_count 30 ensure 31 not (has_item or has_var) 32 end 33 34 has_var: BOOLEAN is 35 do 36 Result := var_set.count > 0 37 ensure 38 Result = (var_set.count > 0) 39 end 40 41 has_item: BOOLEAN is 42 do 43 Result := item_set.count > 0 44 ensure 45 Result = (item_set.count > 0) 46 end 47 48 put (item: ITEM) is 49 -- records the item in item_set or in var_set 50 -- depending on the real type of item that can 51 -- be ITEM_VAR or ITEM_ITEM 52 local 53 itm: ITEM_ITEM; var: ITEM_VAR 54 do 55 itm ?= item 56 if itm /= Void then 57 item_set.add(itm) 58 else 59 var ?= item 60 check 61 var /= Void 62 end 63 var_set.add(var) 64 end 65 end 66 67end -- class ITEM_COLLECTOR 68-- 69-- ------------------------------------------------------------------------------------------------------------------------------ 70-- Copyright notice below. Please read. 71-- 72-- This file is free software, which comes along with SmartEiffel. This software is distributed in the hope that it will be 73-- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 74-- You can modify it as you want, provided this footer is kept unaltered, and a notification of the changes is added. 75-- You are allowed to redistribute it and sell it, alone or as a part of another product. 76-- 77-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE 78-- Copyright(C) 2003-2005: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE 79-- 80-- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN 81-- 82-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr 83-- ------------------------------------------------------------------------------------------------------------------------------