parser: Remove the unused attribute alignment from struct declaration_specifiers_t.
[cparser] / adt / strset.h
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2012 Matthias Braun <matze@braunis.de>
4  */
5 #ifndef _FIRM_STRSET_H_
6 #define _FIRM_STRSET_H_
7
8 #define HashSet          strset_t
9 #define HashSetIterator  strset_iterator_t
10 #define HashSetEntry     strset_entry_t
11 #define ValueType        const char*
12 #include "hashset.h"
13 #undef ValueType
14 #undef HashSetEntry
15 #undef HashSetIterator
16 #undef HashSet
17
18 typedef struct strset_t           strset_t;
19 typedef struct strset_iterator_t  strset_iterator_t;
20
21 /**
22  * Initializes a strset
23  *
24  * @param strset   Pointer to allocated space for the strset
25  */
26 void strset_init(strset_t *strset);
27
28 /**
29  * Initializes a strset
30  *
31  * @param strset                Pointer to allocated space for the strset
32  * @param expected_elements   Number of elements expected in the strset (rougly)
33  */
34 void strset_init_size(strset_t *strset, size_t expected_elements);
35
36 /**
37  * Destroys a strset and frees the memory allocated for hashtable. The memory of
38  * the strset itself is not freed.
39  *
40  * @param strset   Pointer to the strset
41  */
42 void strset_destroy(strset_t *strset);
43
44 /**
45  * Inserts a string into a strset.
46  *
47  * @param strset   Pointer to the strset
48  * @param ptr      Pointer to insert into the strset
49  * @returns        @p ptr if the string was inserted into the set,
50  *                 otherwise a pointer to the string already in the set
51  */
52 const char *strset_insert(strset_t *strset, const char *ptr);
53
54 /**
55  * Removes an element from a strset. Does nothing if the strset doesn't contain the
56  * element.
57  *
58  * @param strset   Pointer to the strset
59  * @param ptr    Pointer to remove from the strset
60  */
61 void strset_remove(strset_t *strset, const char *ptr);
62
63 /**
64  * Tests whether a strset contains a pointer
65  *
66  * @param strset   Pointer to the strset
67  * @param ptr    The pointer to test
68  * @returns      1 @p strset contains the @p ptr, 0 otherwise
69  */
70 const char* strset_find(const strset_t *strset, const char *ptr);
71
72 /**
73  * Returns the number of pointers contained in the strset
74  *
75  * @param strset   Pointer to the strset
76  * @returns      Number of pointers contained in the strset
77  */
78 size_t strset_size(const strset_t *strset);
79
80 /**
81  * Initializes a strset iterator. Sets the iterator before the first element in
82  * the strset.
83  *
84  * @param iterator   Pointer to already allocated iterator memory
85  * @param strset       Pointer to the strset
86  */
87 void strset_iterator_init(strset_iterator_t *iterator, const strset_t *strset);
88
89 /**
90  * Advances the iterator and returns the current element or NULL if all elements
91  * in the strset have been processed.
92  * @attention It is not allowed to use strset_insert or strset_remove while
93  *            iterating over a strset.
94  *
95  * @param iterator  Pointer to the strset iterator.
96  * @returns         Next element in the strset or NULL
97  */
98 const char *strset_iterator_next(strset_iterator_t *iterator);
99
100 /**
101  * Removes the string from the set that the iterator currently points to
102  *
103  * @param strset    Pointer to the strset
104  * @param iter      Pointer to the iterator
105  */
106 void strset_remove_iterator(strset_t *strset,
107                             const strset_iterator_t *iterator);
108
109 #endif