From: Eric Mahurin Date: 2005-04-28T07:42:53+09:00 Subject: cursor/stream/c++ iterator class? I've read a few discussions/comparisons between enumerators (internal iterators) vs. cursors (external iterators). From what I gather those discussions in favor of enumerators assume the application is a simple single pass read-only processing of all/some of the elements in a collection. You do this a lot with a collection and I like enumerators best for doing it. But when you are doing something more complex, enumerators don't cut it. I'm still working on some general parser classes (and a lexer is one of these parsers) where the collection is a sequence of characters (lexer/parser) or a sequence of tokens (parser). I started making my own API for accessing these, but now I'm just going ahead and making a general cursor API. Am I duplicating anything else? Here are the kinds of things you'll be able to do with this cursor interface: get Next/Prev/After/Before move Next/Prev replace Next/Prev/After/Before (optionally get what is replaced) delete After/Before (optionally retrieve what's deleted) insert After/Before get position (position could be any type of object) set position release position (release buffering needed for unidirection cursor - i.e IO pipe) buffered? - query whether there are any non-released positions The methods above that read/write at the cursor will work on one element at a time or a string/array/N of them. get/move/delete will even be able to get so many elements up to a certain string /array of them - like gets("\n"). I'm trying to make this have a superset of the functions in IO in addition to handling sequences of anything. I would hope this API could be used to access and modify a wide variety of ordered collections - strings, arrays, files/IO, single/double linked lists, circular buffers, text editor buffers, etc. It could possibly be used for unordered collections (i.e. hashes) in a read-only manner but I see no advantage over an enumerator in that case. Eric __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com