Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
strlist.h
Go to the documentation of this file.
1 #ifndef __PERF_STRLIST_H
2 #define __PERF_STRLIST_H
3 
4 #include <linux/rbtree.h>
5 #include <stdbool.h>
6 
7 #include "rblist.h"
8 
9 struct str_node {
10  struct rb_node rb_node;
11  const char *s;
12 };
13 
14 struct strlist {
15  struct rblist rblist;
16  bool dupstr;
17 };
18 
19 struct strlist *strlist__new(bool dupstr, const char *slist);
20 void strlist__delete(struct strlist *self);
21 
22 void strlist__remove(struct strlist *self, struct str_node *sn);
23 int strlist__load(struct strlist *self, const char *filename);
24 int strlist__add(struct strlist *self, const char *str);
25 
26 struct str_node *strlist__entry(const struct strlist *self, unsigned int idx);
27 struct str_node *strlist__find(struct strlist *self, const char *entry);
28 
29 static inline bool strlist__has_entry(struct strlist *self, const char *entry)
30 {
31  return strlist__find(self, entry) != NULL;
32 }
33 
34 static inline bool strlist__empty(const struct strlist *self)
35 {
36  return rblist__empty(&self->rblist);
37 }
38 
39 static inline unsigned int strlist__nr_entries(const struct strlist *self)
40 {
41  return rblist__nr_entries(&self->rblist);
42 }
43 
44 /* For strlist iteration */
45 static inline struct str_node *strlist__first(struct strlist *self)
46 {
47  struct rb_node *rn = rb_first(&self->rblist.entries);
48  return rn ? rb_entry(rn, struct str_node, rb_node) : NULL;
49 }
50 static inline struct str_node *strlist__next(struct str_node *sn)
51 {
52  struct rb_node *rn;
53  if (!sn)
54  return NULL;
55  rn = rb_next(&sn->rb_node);
56  return rn ? rb_entry(rn, struct str_node, rb_node) : NULL;
57 }
58 
64 #define strlist__for_each(pos, self) \
65  for (pos = strlist__first(self); pos; pos = strlist__next(pos))
66 
74 #define strlist__for_each_safe(pos, n, self) \
75  for (pos = strlist__first(self), n = strlist__next(pos); pos;\
76  pos = n, n = strlist__next(n))
77 
78 int strlist__parse_list(struct strlist *self, const char *s);
79 #endif /* __PERF_STRLIST_H */