xref: /haiku/src/bin/filteredquery/FilteredQuery.h (revision 7eab6b486ebadb54ca3c306601f4b04dd92359fa)
1 #ifndef __FILTEREDQUERY_H
2 #define __FILTEREDQUERY_H
3 
4 #include <Query.h>
5 
6 #include "ObjectList.h"
7 
8 typedef bool (*filter_function)(const entry_ref *ref, void *arg);
9 
10 struct filter_pair {
11 	filter_function filter;
12 	void *args;
13 
14 	filter_pair(filter_function function, void *arguments)
15 	{
16 		filter = function;
17 		args = arguments;
18 	}
19 };
20 
21 
22 class TFilteredQuery : public BQuery {
23 public:
24 	TFilteredQuery();
25 
26 	// BQuery doesn't have a copy constructor. We supply
27 	// this method to workaround this problem
28 	TFilteredQuery(const BQuery &query);
29 	TFilteredQuery(const TFilteredQuery &query);
30 	virtual ~TFilteredQuery();
31 
32 	bool AddFilter(filter_function function, void *arg);
33 	void RemoveFilter(filter_function function);
34 
35 	virtual status_t GetNextRef(entry_ref *ref);
36 	virtual status_t GetNextEntry(BEntry *entry, bool traverse = false);
37 
38 	status_t Clear();
39 
40 private:
41 	BObjectList<filter_pair> fFilters;
42 };
43 
44 #endif //__FILTEREDQUERY_H
45