indexing description: "[ A container box that provides list operations to modify its contents. No cursors support provided. Use as_linear or infix "@", item to access the contents of the list. Arrangement of contents is the responsibility of subclasses. ]" author: "" date: "$Date$" revision: "$Revision$" deferred class EM_VIZ_LIST_BOX [B -> EM_VIZ_BOX] inherit EM_VIZ_COLLECTION_BOX [B] feature -- Initialization make_list is -- Make new list do make_collection create contents.make (1) end feature -- Access as_linear: DS_LINEAR [B] is -- Linear access do Result := contents end infix "@", item (i: INTEGER): B is -- Item at `i' require valid_index: valid_index (i) do Result := contents @ i end feature -- Measurement count: INTEGER is -- Number of elements in list do Result := contents.count end feature -- Status report is_empty: BOOLEAN is -- List empty? do Result := contents.is_empty end has (b: B): BOOLEAN is -- Has box `b' in list? do Result := contents.has (b) end valid_index (i: INTEGER): BOOLEAN is -- Is `i' valid integer? do Result := 1 <= i and i <= count end feature -- Element change put_first (b: B) is -- Put `b' at beginning of list require orphan_box: b /= Void implies b.parent = Void do contents.force_first (b) adopt (b) ensure adopted: b /= Void implies b.parent = Current and has (b) expired: needs_update end put_last (b: B) is -- Put `b' at end of list require orphan_box: b /= Void implies b.parent = Void do contents.force_last (b) adopt (b) ensure adopted: b /= Void implies b.parent = Current and has (b) expired: needs_update end put (b: B; i: INTEGER) is -- Insert `b' at `i'-th position in list require valid_index: valid_index (i) orphan_box: b /= Void implies b.parent = Void do contents.force (b, i) adopt (b) ensure adopted: b /= Void implies b.parent = Current and has (b) expired: needs_update end replace (b: B; i: INTEGER) is -- Replace list item at `i'-th position require valid_index: valid_index (i) do cast_out (item (i)) contents.replace (b, i) adopt (b) ensure adopted: b /= Void implies b.parent = Current and has (b) expired: needs_update end feature -- Removal remove_first is -- Remove first item in list require not_empty: not is_empty do cast_out (contents.first) contents.remove_first ensure expired: needs_update end remove_last is -- Remove last item in list require not_empty: not is_empty do cast_out (contents.last) contents.remove_last ensure expired: needs_update end remove (i: INTEGER) is -- Remove list item at `i'-th postion require valid_index: valid_index (i) do cast_out (contents.item (i)) contents.remove (i) ensure expired: needs_update end wipe_out is -- Wipe out list do from until contents.is_empty loop remove_last end ensure empty: is_empty expired: needs_update end feature -- Basic operations append_first (other: DS_LINEAR [B]) is -- Append boxes to beginning of list require other_exists: other /= Void -- all_orphaned: ... do contents.append_first (other) from other.start until other.off loop adopt (other.item_for_iteration) other.forth end ensure expired: needs_update end append_last (other: DS_LINEAR [B]) is -- Append boxes to end of list require other_exists: other /= Void -- all_orphaned: ... do contents.append_last (other) from other.start until other.off loop adopt (other.item_for_iteration) other.forth end ensure expired: needs_update end feature {EM_VIZ_LIST_BOX} -- Rendering (Implementation) render_contents (viewing_direction: EM_VECTOR3D; reverse: BOOLEAN) is -- Render contents, use `reverse' to control traversal local b: B do if reverse then from contents.finish until contents.off loop b := contents.item_for_iteration if b /= Void then b.render (viewing_direction) end contents.back end else from contents.start until contents.off loop b := contents.item_for_iteration if b /= Void then b.render (viewing_direction) end contents.forth end end end feature {NONE} -- Implementation contents: DS_ARRAYED_LIST [B] -- List of contents of box end