Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux...
[linux/fpc-iii.git] / tools / perf / util / strlist.h
blobca990029e2430a5681d56682ae6176d66fc3ee0a
1 #ifndef __PERF_STRLIST_H
2 #define __PERF_STRLIST_H
4 #include <linux/rbtree.h>
5 #include <stdbool.h>
7 #include "rblist.h"
9 struct str_node {
10 struct rb_node rb_node;
11 const char *s;
14 struct strlist {
15 struct rblist rblist;
16 bool dupstr;
17 bool file_only;
21 * @file_only: When dirname is present, only consider entries as filenames,
22 * that should not be added to the list if dirname/entry is not
23 * found
25 struct strlist_config {
26 bool dont_dupstr;
27 bool file_only;
28 const char *dirname;
31 struct strlist *strlist__new(const char *slist, const struct strlist_config *config);
32 void strlist__delete(struct strlist *slist);
34 void strlist__remove(struct strlist *slist, struct str_node *sn);
35 int strlist__load(struct strlist *slist, const char *filename);
36 int strlist__add(struct strlist *slist, const char *str);
38 struct str_node *strlist__entry(const struct strlist *slist, unsigned int idx);
39 struct str_node *strlist__find(struct strlist *slist, const char *entry);
41 static inline bool strlist__has_entry(struct strlist *slist, const char *entry)
43 return strlist__find(slist, entry) != NULL;
46 static inline bool strlist__empty(const struct strlist *slist)
48 return rblist__empty(&slist->rblist);
51 static inline unsigned int strlist__nr_entries(const struct strlist *slist)
53 return rblist__nr_entries(&slist->rblist);
56 /* For strlist iteration */
57 static inline struct str_node *strlist__first(struct strlist *slist)
59 struct rb_node *rn = rb_first(&slist->rblist.entries);
60 return rn ? rb_entry(rn, struct str_node, rb_node) : NULL;
62 static inline struct str_node *strlist__next(struct str_node *sn)
64 struct rb_node *rn;
65 if (!sn)
66 return NULL;
67 rn = rb_next(&sn->rb_node);
68 return rn ? rb_entry(rn, struct str_node, rb_node) : NULL;
71 /**
72 * strlist_for_each - iterate over a strlist
73 * @pos: the &struct str_node to use as a loop cursor.
74 * @slist: the &struct strlist for loop.
76 #define strlist__for_each(pos, slist) \
77 for (pos = strlist__first(slist); pos; pos = strlist__next(pos))
79 /**
80 * strlist_for_each_safe - iterate over a strlist safe against removal of
81 * str_node
82 * @pos: the &struct str_node to use as a loop cursor.
83 * @n: another &struct str_node to use as temporary storage.
84 * @slist: the &struct strlist for loop.
86 #define strlist__for_each_safe(pos, n, slist) \
87 for (pos = strlist__first(slist), n = strlist__next(pos); pos;\
88 pos = n, n = strlist__next(n))
89 #endif /* __PERF_STRLIST_H */