Search code examples
eiffel

How can I run a cursor tree in Eiffel?


I need a cursor tree and I found CURSOR_TREE and RECURSIVE_CURSOR_TREE classes in EiffelStudio but they are deferred and I don't know how to implement them. Isn'it strange?


Solution

  • Source code of some classes implementing CURSOR_TREE is available in your installation in .../library/base/elks/structures/cursor_tree. Unfortunately, the classes (as they were implemented) are incompatible with void safety. You can try copying the following classes to your project and compile:

    library/base/elks/structures/cursor_tree/compact_cursor_tree.e
    library/base/elks/structures/cursor_tree/linked_cursor_tree.e
    library/base/elks/structures/cursor_tree/two_way_cursor_tree.e
    library/base/elks/structures/cursors/compact_tree_cursor.e
    library/base/elks/structures/cursors/linked_cursor_tree_cursor.e
    library/base/elks/structures/cursors/two_way_cursor_tree_cursor.e
    

    The process would involve several changes:

    • your project void safety capability should be set to none (and the project should be recompiled from scratch);

    • depending on the version of the compiler you may need to fix some validity errors in the library classes (e.g., remove put_right from redefine clauses);

    • implementations of the feature new_cursor have to be provided, a quick-and-dirty fix could be a dummy stub:

      new_cursor: ITERATION_CURSOR [G]
          do
              Result := (create {SPECIAL [G]}.make_empty (0)).new_cursor
          end
      

    After that you should be able to use effective classes COMPACT_CURSOR_TREE, LINKED_CURSOR_TREE and TWO_WAY_CURSOR_TREE.

    I would suggest collaborating with Eiffel Software if you plan to use the classes in a void-safe project because the implementation and the interface requires substantial changes to make the code void-safe.