Merge "master" branch into "db".
[sliver-openvswitch.git] / lib / svec.h
1 /*
2  * Copyright (c) 2008, 2009 Nicira Networks.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef SVEC_H
18 #define SVEC_H 1
19
20 #include <stdbool.h>
21 #include <stddef.h>
22
23 struct svec {
24     char **names;
25     size_t n;
26     size_t allocated;
27 };
28
29 #define SVEC_EMPTY_INITIALIZER { NULL, 0, 0 }
30
31 void svec_init(struct svec *);
32 void svec_clone(struct svec *, const struct svec *);
33 void svec_destroy(struct svec *);
34 void svec_clear(struct svec *);
35 bool svec_is_empty(const struct svec *);
36 void svec_add(struct svec *, const char *);
37 void svec_add_nocopy(struct svec *, char *);
38 void svec_del(struct svec *, const char *);
39 void svec_append(struct svec *, const struct svec *);
40 void svec_terminate(struct svec *);
41 void svec_sort(struct svec *);
42 void svec_sort_unique(struct svec *);
43 void svec_unique(struct svec *);
44 void svec_compact(struct svec *);
45 void svec_diff(const struct svec *a, const struct svec *b,
46                struct svec *a_only, struct svec *both, struct svec *b_only);
47 bool svec_contains(const struct svec *, const char *);
48 size_t svec_find(const struct svec *, const char *);
49 bool svec_is_sorted(const struct svec *);
50 bool svec_is_unique(const struct svec *);
51 const char *svec_get_duplicate(const struct svec *);
52 void svec_swap(struct svec *a, struct svec *b);
53 void svec_print(const struct svec *svec, const char *title);
54 void svec_parse_words(struct svec *svec, const char *words);
55 bool svec_equal(const struct svec *, const struct svec *);
56 void svec_split(struct svec *, const char *s, const char *delimiters);
57 char *svec_join(const struct svec *,
58                 const char *delimiter, const char *terminator);
59 const char *svec_back(const struct svec *);
60 void svec_pop_back(struct svec *);
61
62 /* Iterates over the names in SVEC, assigning each name in turn to NAME and its
63  * index to INDEX. */
64 #define SVEC_FOR_EACH(INDEX, NAME, SVEC)        \
65     for ((INDEX) = 0;                           \
66          ((INDEX) < (SVEC)->n                   \
67           ? (NAME) = (SVEC)->names[INDEX], 1    \
68           : 0);                                 \
69          (INDEX)++)
70
71 #endif /* svec.h */