]> git.decadent.org.uk Git - ion3.git/blob - libtu/iterable.c
[svn-inject] Installing original source of ion3
[ion3.git] / libtu / iterable.c
1 /*
2  * libtu/iterable.c
3  *
4  * Copyright (c) Tuomo Valkonen 2005.
5  *
6  * You may distribute and modify this library under the terms of either
7  * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
8  */
9
10 #include "iterable.h"
11
12
13 void *iterable_nth(uint n, VoidIterator *iter, void *st)
14 {
15     void *p;
16     
17     while(1){
18         p=iter(st);
19         if(p==NULL || n==0)
20             break;
21         n--;
22     }
23     
24     return p;
25 }
26
27
28 bool iterable_is_on(void *p, VoidIterator *iter, void *st)
29 {
30     while(1){
31         void *p2=iter(st);
32         if(p2==NULL)
33             return FALSE;
34         if(p==p2)
35             return TRUE;
36     }
37 }
38
39
40 void *iterable_find(BoolFilter *f, void *fparam, 
41                     VoidIterator *iter, void *st)
42 {
43     while(1){
44         void *p=iter(st);
45         if(p==NULL)
46             return NULL;
47         if(f(p, fparam))
48             return p;
49     }
50 }
51