1 /*
2  * Copyright 2008-2013 Various Authors
3  * Copyright 2005 Timo Hirvonen
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef CMUS_SEARCH_H
20 #define CMUS_SEARCH_H
21 
22 #include "iter.h"
23 
24 enum search_direction { SEARCH_FORWARD, SEARCH_BACKWARD };
25 
26 struct searchable_ops {
27 	int (*get_prev)(struct iter *iter);
28 	int (*get_next)(struct iter *iter);
29 	int (*get_current)(void *data, struct iter *iter);
30 	int (*matches)(void *data, struct iter *iter, const char *text);
31 };
32 
33 struct searchable;
34 
35 struct searchable *searchable_new(void *data, const struct iter *head, const struct searchable_ops *ops);
36 void searchable_free(struct searchable *s);
37 void searchable_set_head(struct searchable *s, const struct iter *head);
38 
39 int search(struct searchable *s, const char *text, enum search_direction dir, int beginning);
40 int search_next(struct searchable *s, const char *text, enum search_direction dir);
41 
42 #endif
43