Advertisement
Guest User

Untitled

a guest
Mar 28th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Eiffel 1.59 KB | None | 0 0
  1. note
  2.     description: "History operations for undo/redo design pattern"
  3.     author: "JSO"
  4.     date: "$Date$"
  5.     revision: "$Revision$"
  6.  
  7. class
  8.     HISTORY
  9.  
  10. create
  11.     make
  12.  
  13. feature{NONE} -- create
  14.     make
  15.         do
  16.             create {ARRAYED_LIST[MOVE]}history.make (10)
  17.         end
  18.  
  19.     history: LIST[MOVE]
  20.         -- a history list of user invoked operations
  21.         -- implementation
  22.  
  23.  
  24. feature -- queries
  25.     item: MOVE
  26.             -- Cursor points to this user operation
  27.         require
  28.             on_item
  29.         do
  30.             Result := history.item
  31.         end
  32.  
  33.     on_item: BOOLEAN
  34.             -- cursor points to a valid operation
  35.             -- cursor is not before or after
  36.         do
  37.             Result := not history.before and not history.after
  38.         end
  39.  
  40.  
  41.     after: BOOLEAN
  42.             -- Is there no valid cursor position to the right of cursor?
  43.         do
  44.             Result := history.index = history.count + 1
  45.         end
  46.  
  47.     before: BOOLEAN
  48.             -- Is there no valid cursor position to the left of cursor?
  49.         do
  50.             Result := history.index = 0
  51.         end
  52.  
  53. feature -- comands
  54.     extend_history(a_op: MOVE)
  55.             -- remove all operations to the right of the current
  56.             -- cursor in history, then extend with `a_op'
  57.         do
  58.             remove_right
  59.             history.extend(a_op)
  60.             history.finish
  61.         ensure
  62.             history[history.count] = a_op
  63.         end
  64.  
  65.     remove_right
  66.             --remove all elements
  67.             -- to the right of the current cursor in history
  68.         do
  69.             if not history.islast and not history.after then
  70.                 from
  71.                     history.forth
  72.                 until
  73.                     history.after
  74.                 loop
  75.                     history.remove
  76.                 end
  77.             end
  78.         end
  79.  
  80.  
  81.  
  82.     forth
  83.         require
  84.             not after
  85.         do
  86.             history.forth
  87.         end
  88.  
  89.     back
  90.         require
  91.             not before
  92.         do
  93.             history.back
  94.         end
  95.  
  96.  
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement