cursor/stream/c++ iterator class?

E

Eric Mahurin

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
 
S

Simon Strandgaard

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.
[snip]

I have made a lib containing some external iterators, see:
http://aeditor.rubyforge.org/iterator/

download it here:
http://rubyforge.org/frs/download.php/704/iterator-0.8.zip
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top