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

Discussion in 'C Programming' started by aninnymouse@gmail.com, Feb 21, 2006.

  1. Guest

    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()) { }
     
    , Feb 21, 2006
    #1
    1. Advertising

  2. Jack Klein Guest

    On 20 Feb 2006 21:55:38 -0800, 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/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Feb 21, 2006
    #2
    1. Advertising

  3. Guest

    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.
     
    , Feb 21, 2006
    #3
  4. suresh Guest

    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.
     
    suresh, Feb 21, 2006
    #4
  5. In article <>,
    <> 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.
     
    Kenny McCormack, Feb 21, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hendrik Maryns
    Replies:
    18
    Views:
    1,466
  2. Replies:
    1
    Views:
    358
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=
    Feb 17, 2006
  3. Bill Scherer

    Re: Python Oracle Interace on Solaris

    Bill Scherer, Feb 17, 2006, in forum: Python
    Replies:
    1
    Views:
    342
    Kenny
    Feb 17, 2006
  4. forester
    Replies:
    16
    Views:
    735
    Howard Hinnant
    Aug 25, 2005
  5. Pranav
    Replies:
    3
    Views:
    743
    ManicQin
    Aug 8, 2008
Loading...

Share This Page