Merge tag 'drm-fixes-v4.7-rc1' of git://people.freedesktop.org/~airlied/linux
[linux-2.6-block.git] / tools / perf / util / strlist.h
CommitLineData
8b40f521
JK
1#ifndef __PERF_STRLIST_H
2#define __PERF_STRLIST_H
25903407 3
43cbcd8a 4#include <linux/rbtree.h>
25903407
ACM
5#include <stdbool.h>
6
ee8dd3ca
DA
7#include "rblist.h"
8
25903407
ACM
9struct str_node {
10 struct rb_node rb_node;
11 const char *s;
12};
13
14struct strlist {
ee8dd3ca 15 struct rblist rblist;
dd8232bc
NK
16 bool dupstr;
17 bool file_only;
25903407
ACM
18};
19
dd8232bc
NK
20/*
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
24 */
4a77e218
ACM
25struct strlist_config {
26 bool dont_dupstr;
dd8232bc 27 bool file_only;
8ff9daf3 28 const char *dirname;
4a77e218
ACM
29};
30
31struct strlist *strlist__new(const char *slist, const struct strlist_config *config);
d8639f06 32void strlist__delete(struct strlist *slist);
25903407 33
d8639f06
ACM
34void strlist__remove(struct strlist *slist, struct str_node *sn);
35int strlist__load(struct strlist *slist, const char *filename);
36int strlist__add(struct strlist *slist, const char *str);
25903407 37
d8639f06
ACM
38struct str_node *strlist__entry(const struct strlist *slist, unsigned int idx);
39struct str_node *strlist__find(struct strlist *slist, const char *entry);
3e340590 40
d8639f06 41static inline bool strlist__has_entry(struct strlist *slist, const char *entry)
3e340590 42{
d8639f06 43 return strlist__find(slist, entry) != NULL;
3e340590 44}
25903407 45
d8639f06 46static inline bool strlist__empty(const struct strlist *slist)
25903407 47{
d8639f06 48 return rblist__empty(&slist->rblist);
27d0fd41
ACM
49}
50
d8639f06 51static inline unsigned int strlist__nr_entries(const struct strlist *slist)
27d0fd41 52{
d8639f06 53 return rblist__nr_entries(&slist->rblist);
25903407
ACM
54}
55
abf5ef72 56/* For strlist iteration */
d8639f06 57static inline struct str_node *strlist__first(struct strlist *slist)
abf5ef72 58{
d8639f06 59 struct rb_node *rn = rb_first(&slist->rblist.entries);
abf5ef72
MH
60 return rn ? rb_entry(rn, struct str_node, rb_node) : NULL;
61}
62static inline struct str_node *strlist__next(struct str_node *sn)
63{
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;
69}
70
71/**
72 * strlist_for_each - iterate over a strlist
73 * @pos: the &struct str_node to use as a loop cursor.
d8639f06 74 * @slist: the &struct strlist for loop.
abf5ef72 75 */
d8639f06
ACM
76#define strlist__for_each(pos, slist) \
77 for (pos = strlist__first(slist); pos; pos = strlist__next(pos))
abf5ef72
MH
78
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.
d8639f06 84 * @slist: the &struct strlist for loop.
abf5ef72 85 */
d8639f06
ACM
86#define strlist__for_each_safe(pos, n, slist) \
87 for (pos = strlist__first(slist), n = strlist__next(pos); pos;\
abf5ef72 88 pos = n, n = strlist__next(n))
8b40f521 89#endif /* __PERF_STRLIST_H */