1 #ifndef __PERF_STRLIST_H
2 #define __PERF_STRLIST_H
4 #include <linux/rbtree.h>
8 struct rb_node rb_node;
13 struct rb_root entries;
14 unsigned int nr_entries;
18 struct strlist *strlist__new(bool dupstr, const char *slist);
19 void strlist__delete(struct strlist *self);
21 void strlist__remove(struct strlist *self, struct str_node *sn);
22 int strlist__load(struct strlist *self, const char *filename);
23 int strlist__add(struct strlist *self, const char *str);
25 struct str_node *strlist__entry(const struct strlist *self, unsigned int idx);
26 struct str_node *strlist__find(struct strlist *self, const char *entry);
28 static inline bool strlist__has_entry(struct strlist *self, const char *entry)
30 return strlist__find(self, entry) != NULL;
33 static inline bool strlist__empty(const struct strlist *self)
35 return self->nr_entries == 0;
38 static inline unsigned int strlist__nr_entries(const struct strlist *self)
40 return self->nr_entries;
43 /* For strlist iteration */
44 static inline struct str_node *strlist__first(struct strlist *self)
46 struct rb_node *rn = rb_first(&self->entries);
47 return rn ? rb_entry(rn, struct str_node, rb_node) : NULL;
49 static inline struct str_node *strlist__next(struct str_node *sn)
54 rn = rb_next(&sn->rb_node);
55 return rn ? rb_entry(rn, struct str_node, rb_node) : NULL;
59 * strlist_for_each - iterate over a strlist
60 * @pos: the &struct str_node to use as a loop cursor.
61 * @self: the &struct strlist for loop.
63 #define strlist__for_each(pos, self) \
64 for (pos = strlist__first(self); pos; pos = strlist__next(pos))
67 * strlist_for_each_safe - iterate over a strlist safe against removal of
69 * @pos: the &struct str_node to use as a loop cursor.
70 * @n: another &struct str_node to use as temporary storage.
71 * @self: the &struct strlist for loop.
73 #define strlist__for_each_safe(pos, n, self) \
74 for (pos = strlist__first(self), n = strlist__next(pos); pos;\
75 pos = n, n = strlist__next(n))
77 int strlist__parse_list(struct strlist *self, const char *s);
78 #endif /* __PERF_STRLIST_H */