Automatic generation produced by ISE Eiffel
indexing description: "A sequence of actions to be performed on `call'" instructions: "[ Use features inherited from LIST to add/remove actions. An action is a procedure of ANY class that takes EVENT_DATA. When `call' is called the actions in the list will be executed in order stating at `first'. An action may call `abort' which will cause `call' to stop executing actions in the sequence. (Until the next call to `call'). Descendants may redefine `initialize' to arrange for `call' to be called by an event source. Use `block', `pause', `flush' and `resume' to change the behavior of `call'. eg. birthday_data: TUPLE [INTEGER, STRING] -- (age, name) birthday_actions: ACTIONS_SEQUENCE [like birthday_data] create birthday_actions.make ("birthday", <<"age","name">>) send_card (age: INTEGER, name, from: STRING) is ... buy_gift (age: INTEGER, name, gift, from: STRING) is ... birthday_actions.extend (~send_card (?, ?, "Sam") birthday_actions.extend (~buy_gift (?, ?, "Wine", "Sam") birthday_actions.call ([35, "Julia"]) causes call to: send_card (35, "Julia", "Sam") buy_gift (35, "Julia", "Wine", "Sam") ]" status: "See notice at end of class" keywords: "event, action" date: "$Date: 2001/11/16 20:34:10 $" revision: "$Revision: 1.1.1.1 $" class ACTION_SEQUENCE [EVENT_DATA -> TUPLE create make end] create default_create, make feature {NONE} -- Initialization default_create is -- Begin in Normal_state. do linked_list_make create is_aborted_stack.make create call_buffer.make state := normal_state create not_empty_actions.make create empty_actions.make end make is obsolete "use default_create" do default_create end feature -- Initialization linked_list_make is -- Create an empty list. -- (from LINKED_LIST) do before := True ensure -- from LINKED_LIST is_before: before end feature -- Access cursor: CURSOR is -- Current cursor position -- (from LINKED_LIST) do create {LINKED_LIST_CURSOR [PROCEDURE [ANY, EVENT_DATA]]} Result.make (active, after, before) end dummy_event_data: EVENT_DATA is -- Attribute of the generic type. -- Useful for introspection and use in like statements. do if dummy_event_data_internal = void then create dummy_event_data_internal.make end Result := dummy_event_data_internal end event_data_names: ARRAY [STRING] is -- Textual description of each event datum. do Result := deep_clone (event_data_names_internal) ensure equal_to_event_data_names_internal: deep_equal (Result, event_data_names_internal) end first: like item is -- Item at first position -- (from LINKED_LIST) require -- from CHAIN not_empty: not is_empty do Result := first_element.item end has (v: like item): BOOLEAN is -- Does chain include v? -- (Reference or object equality, -- based on object_comparison.) -- (from CHAIN) local pos: CURSOR do pos := cursor Result := sequential_has (v) go_to (pos) ensure -- from CONTAINER not_found_in_empty: Result implies not is_empty end i_th (i: INTEGER): like item is -- Item at i-th position -- Was declared in CHAIN as synonym of @. -- (from CHAIN) require -- from TABLE valid_key: valid_index (k) local pos: CURSOR do pos := cursor go_i_th (i) Result := item go_to (pos) end index: INTEGER is -- Index of current position -- (from LINKED_LIST) local p: LINKED_LIST_CURSOR [PROCEDURE [ANY, EVENT_DATA]] do if after then Result := count + 1 elseif not before then p ?= cursor; check p /= void end; from start Result := 1 until p.active = active loop forth Result := Result + 1 end; go_to (p) end end index_of (v: like item; i: INTEGER): INTEGER is -- Index of i-th occurrence of item identical to v. -- (Reference or object equality, -- based on object_comparison.) -- 0 if none. -- (from CHAIN) require -- from LINEAR positive_occurrences: i > 0 local pos: CURSOR do pos := cursor Result := sequential_index_of (v, i) go_to (pos) ensure -- from LINEAR non_negative_result: Result >= 0 end item: PROCEDURE [ANY, EVENT_DATA] is -- Current item -- (from LINKED_LIST) require -- from TRAVERSABLE not_off: not off require -- from ACTIVE readable: readable do Result := active.item end last: like item is -- Item at last position -- (from LINKED_LIST) require -- from CHAIN not_empty: not is_empty do Result := last_element.item end name: STRING is -- Textual description. do Result := clone (name_internal) ensure equal_to_name_internal: Result.is_equal (name_internal) end sequential_occurrences (v: PROCEDURE [ANY, EVENT_DATA]): INTEGER is -- Number of times v appears. -- (Reference or object equality, -- based on object_comparison.) -- (from LINEAR) do from start search (v) until exhausted loop Result := Result + 1 forth search (v) end ensure -- from BAG non_negative_occurrences: Result >= 0 end infix "@" (i: INTEGER): like item is -- Item at i-th position -- Was declared in CHAIN as synonym of i_th. -- (from CHAIN) require -- from TABLE valid_key: valid_index (k) local pos: CURSOR do pos := cursor go_i_th (i) Result := item go_to (pos) end feature {NONE} -- Access sequential_has (v: like item): BOOLEAN is -- Does structure include an occurrence of v? -- (Reference or object equality, -- based on object_comparison.) -- (from LINEAR) do start if not off then search (v) end Result := not exhausted ensure -- from CONTAINER not_found_in_empty: Result implies not is_empty end sequential_index_of (v: like item; i: INTEGER): INTEGER is -- Index of i-th occurrence of v. -- 0 if none. -- (Reference or object equality, -- based on object_comparison.) -- (from LINEAR) require -- from LINEAR positive_occurrences: i > 0 local occur, pos: INTEGER do if object_comparison and v /= void then from start pos := 1 until off or (occur = i) loop if item /= void and then v.is_equal (item) then occur := occur + 1 end forth pos := pos + 1 end else from start pos := 1 until off or (occur = i) loop if item = v then occur := occur + 1 end forth pos := pos + 1 end end if occur = i then Result := pos - 1 end ensure -- from LINEAR non_negative_result: Result >= 0 end sequential_search (v: like item) is -- Move to first position (at or after current -- position) where item and v are equal. -- (Reference or object equality, -- based on object_comparison.) -- If no such position ensure that exhausted will be true. -- (from LINEAR) do if object_comparison and v /= void then from until exhausted or else (item /= void and then v.is_equal (item)) loop forth end else from until exhausted or else v = item loop forth end end ensure -- from LINEAR object_found: (not exhausted and object_comparison) implies equal (v, item) item_found: (not exhausted and not object_comparison) implies v = item end feature -- Measurement count: INTEGER -- Number of items -- (from LINKED_LIST) index_set: INTEGER_INTERVAL is -- Range of acceptable indexes -- (from CHAIN) do create Result.make (1, count) ensure -- from INDEXABLE not_void: Result /= void ensure then -- from CHAIN count_definition: Result.count = count end occurrences (v: like item): INTEGER is -- Number of times v appears. -- (Reference or object equality, -- based on object_comparison.) -- (from CHAIN) local pos: CURSOR do pos := cursor Result := sequential_occurrences (v) go_to (pos) ensure -- from BAG non_negative_occurrences: Result >= 0 end occurrences (v: like item): INTEGER is -- Number of times v appears. -- (Reference or object equality, -- based on object_comparison.) -- (from CHAIN) local pos: CURSOR do pos := cursor Result := sequential_occurrences (v) go_to (pos) ensure -- from BAG non_negative_occurrences: Result >= 0 end feature -- Comparison is_equal (other: like Current): BOOLEAN is -- Does other contain the same elements? -- (from LIST) require -- from ANY other_not_void: other /= void local c1, c2: CURSOR do if Current = other then Result := True else Result := (is_empty = other.is_empty) and (object_comparison = other.object_comparison) if Result and not is_empty then c1 ?= cursor c2 ?= other.cursor check cursors_exist: c1 /= void and c2 /= void end from start other.start until after or not Result loop if object_comparison then Result := equal (item, other.item) else Result := (item = other.item) end forth other.forth end go_to (c1) other.go_to (c2) elseif is_empty and other.is_empty and object_comparison = other.object_comparison then Result := True end end ensure -- from ANY symmetric: Result implies other.is_equal (Current) consistent: standard_is_equal (other) implies Result ensure then -- from LIST indices_unchanged: index = old index and other.index = old other.index true_implies_same_size: Result implies count = other.count end feature -- Status report after: BOOLEAN -- Is there no valid cursor position to the right of cursor? -- (from LINKED_LIST) before: BOOLEAN -- Is there no valid cursor position to the left of cursor? -- (from LINKED_LIST) Blocked_state: INTEGER is 3 call_is_underway: BOOLEAN is -- Is call currently being executed? do Result := not is_aborted_stack.is_empty ensure Result = not is_aborted_stack.is_empty end changeable_comparison_criterion: BOOLEAN is -- May object_comparison be changed? -- (Answer: yes by default.) -- (from CONTAINER) do Result := True end empty: BOOLEAN is obsolete "ELKS 2000: Use `is_empty' instead" -- Is there no element? -- (from CONTAINER) do Result := is_empty end exhausted: BOOLEAN is -- Has structure been completely explored? -- (from LINEAR) do Result := off ensure -- from LINEAR exhausted_when_off: off implies Result end Extendible: BOOLEAN is True -- May new items be added? (Answer: yes.) -- (from DYNAMIC_CHAIN) Full: BOOLEAN is False -- Is structured filled to capacity? (Answer: no.) -- (from LINKED_LIST) is_empty: BOOLEAN is -- Is structure empty? -- (from FINITE) do Result := (count = 0) end is_inserted (v: PROCEDURE [ANY, EVENT_DATA]): BOOLEAN is -- Has v been inserted at the end by the most recent put or -- extend? -- (from LINKED_LIST) do check put_constraint: (v /= last_element.item) implies not off end Result := (v = last_element.item) or else (v = item) end isfirst: BOOLEAN is -- Is cursor at first position? -- (from LINKED_LIST) do Result := not after and not before and (active = first_element) ensure -- from CHAIN valid_position: Result implies not is_empty end islast: BOOLEAN is -- Is cursor at last position? -- (from LINKED_LIST) do Result := not after and not before and (active /= void) and then (active.right = void) ensure -- from CHAIN valid_position: Result implies not is_empty end Normal_state: INTEGER is 1 object_comparison: BOOLEAN -- Must search operations use equal rather than = -- for comparing references? (Default: no, use =.) -- (from CONTAINER) off: BOOLEAN is -- Is there no current item? -- (from LINKED_LIST) do Result := after or before end Paused_state: INTEGER is 2 prunable: BOOLEAN is -- May items be removed? (Answer: yes.) -- (from DYNAMIC_CHAIN) do Result := True end readable: BOOLEAN is -- Is there a current item that may be read? -- (from LINKED_LIST) do Result := not off end state: INTEGER -- One of Normal_state Paused_state or Blocked_state valid_cursor (p: CURSOR): BOOLEAN is -- Can the cursor be moved to position p? -- (from LINKED_LIST) local ll_c: LINKED_LIST_CURSOR [PROCEDURE [ANY, EVENT_DATA]] temp, sought: like first_element do ll_c ?= p if ll_c /= void then from temp := first_element sought := ll_c.active Result := ll_c.after or else ll_c.before until Result or else temp = void loop Result := (temp = sought) temp := temp.right end end end valid_cursor_index (i: INTEGER): BOOLEAN is -- Is i correctly bounded for cursor movement? -- (from CHAIN) do Result := (i >= 0) and (i <= count + 1) ensure -- from CHAIN valid_cursor_index_definition: Result = ((i >= 0) and (i <= count + 1)) end valid_index (i: INTEGER): BOOLEAN is -- Is i within allowable bounds? -- (from CHAIN) do Result := (i >= 1) and (i <= count) ensure then -- from INDEXABLE only_if_in_index_set: Result implies ((i >= index_set.lower) and (i <= index_set.upper)) ensure then -- from CHAIN valid_index_definition: Result = ((i >= 1) and (i <= count)) end writable: BOOLEAN is -- Is there a current item that may be modified? -- (from SEQUENCE) do Result := not off end feature -- Status setting abort is -- Abort the current call. -- (The current item.call will be completed.) require call_is_underway: call_is_underway do is_aborted_stack.replace (True) ensure is_aborted_set: is_aborted_stack.item end block is -- Ignore subsequent calls. do state := blocked_state ensure blocked_state: state = blocked_state end compare_objects is -- Ensure that future search operations will use equal -- rather than = for comparing references. -- (from CONTAINER) require -- from CONTAINER changeable_comparison_criterion do object_comparison := True ensure -- from CONTAINER object_comparison end compare_references is -- Ensure that future search operations will use = -- rather than equal for comparing references. -- (from CONTAINER) require -- from CONTAINER changeable_comparison_criterion do object_comparison := False ensure -- from CONTAINER reference_comparison: not object_comparison end flush is -- Discard any buffered calls. do call_buffer.wipe_out ensure call_buffer_empty: call_buffer.is_empty end pause is -- Buffer subsequent calls for later execution. -- If is_blocked calls will simply be ignored. do state := paused_state ensure paused_state: state = paused_state end resume is -- Used after block or pause to resume normal call -- execution. Executes any buffered calls. do state := normal_state from until call_buffer.is_empty loop call (call_buffer.item) call_buffer.remove end ensure normal_state: state = normal_state end feature -- Cursor movement back is -- Move to previous item. -- (from LINKED_LIST) require -- from BILINEAR not_before: not before do if is_empty then before := True after := False elseif after then after := False elseif isfirst then before := True else active := previous end end finish is -- Move cursor to last position. -- (Go before if empty) -- (from LINKED_LIST) local p: like first_element do if not is_empty then from p := active until p.right = void loop p := p.right end active := p after := False before := False else before := True after := False end ensure then -- from CHAIN at_last: not is_empty implies islast ensure then -- from LINKED_LIST empty_convention: is_empty implies before end forth is -- Move cursor to next position. -- (from LINKED_LIST) require -- from LINEAR not_after: not after local old_active: like first_element do if before then before := False if is_empty then after := True end else old_active := active active := active.right if active = void then active := old_active after := True end end ensure then -- from LIST moved_forth: index = old index + 1 end go_i_th (i: INTEGER) is -- Move cursor to i-th position. -- (from LINKED_LIST) require -- from CHAIN valid_cursor_index: valid_cursor_index (i) do if i = 0 then before := True after := False active := first_element elseif i = count + 1 then before := False; after := True; active := last_element else move (i - index) end ensure -- from