Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > is it possible to possible to create an iterator from a callback interace?

Reply
Thread Tools

is it possible to possible to create an iterator from a callback interace?

 
 
aninnymouse@gmail.com
Guest
Posts: n/a
 
      02-21-2006
I'm using a library that provides the following function which
traverses the graph and calls a provided callback function on each
visited vertex:
void depth_first_search(Graph *graph, VertexCB callback, void *data);

Can somebody tell me how I can create a function that implements an
interator iterface using the above function. I'm hoping it's possible
to use it like so:
Vertex *v;
while (v = dfs_iterator()) { }

 
Reply With Quote
 
 
 
 
Jack Klein
Guest
Posts: n/a
 
      02-21-2006
On 20 Feb 2006 21:55:38 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in
comp.lang.c:

> I'm using a library that provides the following function which
> traverses the graph and calls a provided callback function on each
> visited vertex:
> void depth_first_search(Graph *graph, VertexCB callback, void *data);
>
> Can somebody tell me how I can create a function that implements an
> interator iterface using the above function. I'm hoping it's possible
> to use it like so:
> Vertex *v;
> while (v = dfs_iterator()) { }


The C language doesn't define anything called an "iterator". Are you
looking for comp.lang.c++, down the hall to the left? If not, you had
best define exactly what you mean by "iterator" in this context.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
 
Reply With Quote
 
 
 
 
aninnymouse@gmail.com
Guest
Posts: n/a
 
      02-21-2006
I meant iterator as a design pattern (e.g. method of access
controllable by a loop). The callback approach will visit each vertex
and advance without any control. I need to control when to advance to
the next node. The naive approach would be to simply have the original
callback add the elements to a list and iterate over the list, but it's
possible there may be many elements, so that wouldn't be efficient.
Basically I want to have depth_first_search "pause" after calling the
callback, until I explicitly call it to resume the flow.

 
Reply With Quote
 
suresh
Guest
Posts: n/a
 
      02-21-2006
(E-Mail Removed) wrote:

> I meant iterator as a design pattern (e.g. method of access
> controllable by a loop). The callback approach will visit each vertex
> and advance without any control. I need to control when to advance to
> the next node. The naive approach would be to simply have the original
> callback add the elements to a list and iterate over the list, but it's
> possible there may be many elements, so that wouldn't be efficient.
> Basically I want to have depth_first_search "pause" after calling the
> callback, until I explicitly call it to resume the flow.


That does not look like purely implementable in C. You need some
platform specific functions to accomplish this.
<OT>
The call back should wait on a semaphore and the resume function
should release the semaphore.
</OT>

If you explain your original problem little more (for example - what
do you want to do in the while loop) you might find the pure C solution
here.

 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      02-21-2006
In article <(E-Mail Removed). com>,
<(E-Mail Removed)> wrote:
>I meant iterator as a design pattern (e.g. method of access
>controllable by a loop). The callback approach will visit each vertex
>and advance without any control. I need to control when to advance to
>the next node. The naive approach would be to simply have the original
>callback add the elements to a list and iterate over the list, but it's
>possible there may be many elements, so that wouldn't be efficient.
>Basically I want to have depth_first_search "pause" after calling the
>callback, until I explicitly call it to resume the flow.


Allow me to be the first to say this - and I say it from the deepness of my
heart, with all the kindness and love one has come to associate with the
helpful posts you get in this newsgroup:

Not portable. Can't discuss it here. Blah, blah, blah.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I overload an iterator/create an iterator Pranav C++ 3 08-08-2008 06:49 AM
Difference between Java iterator and iterator in Gang of Four Hendrik Maryns Java 18 12-22-2005 05:14 AM
How to convert from std::list<T*>::iterator to std::list<const T*>::iterator? PengYu.UT@gmail.com C++ 6 10-30-2005 03:31 AM
item callback on container or why STL does not have pointer to iterator conversion open? forester C++ 16 08-25-2005 03:37 PM
Iterator doubts, Decision on Iterator usage greg C++ 6 07-17-2003 01:26 PM



Advertisments