[RBMetacode] Need some code design help
Status: Planning
Brought to you by:
jstrout
From: Thomas T. <tt...@te...> - 2008-03-14 14:39:35
|
So, you know, I'm working on this editor... It can now open a RB file (binary only so far), load it into a tree that consists of classes representing the different types (module, class, control, method, property etc.), most of which have common properties (a name or label, parent and children) while some have special properties (source code, method declaration, variable declaration, note, icon, external file reference and so on). Saving works as well, of course. The editor provides an interface that looks similar to the RB IDE, where the user can already edit source and declarations. Now I like to add Find & Replace functionality and I am looking for suggestions on how to do this best. To search, I need to iterate over all items. Currently, not every text item of interest has its own node in the tree. Instead, as explained above, the name/label is a property of any node's base class, and some classes have accessor methods for reading and settings source, declaration and notes. To iterate over these, I'd currently have to iterate over the nodes, then add special handling for the special properties. But how would the iterator remember where it's at? If I code it so that it uses a callback (delegate) function to handle the finding, it would implicitly remember where it's at, but what if the callback function decides to alter the tree so that the iteration loop is now working on obsolete items? Therefore, I believe it's better to have a "smarter" iterator that one calls from one's own loop, getting the next found item, then process this item, then proceed in the loop to get the next item from the iterator. But then, the iterator has to know where it's at. See the problem? So, one problem might be to change my tree design so that every item, including the source, declaration and name, are tree nodes as well. Then the iterator has to deal only with remembering nodes. Would that be the best solution or are there other approaches that come to mind? Thomas |