1 /* Copyright (c) 2012 Nicira, Inc.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License. */
20 /* A map from string to string. */
22 struct hmap map; /* Contains "struct smap_node"s. */
26 struct hmap_node node; /* In struct smap's 'map' hmap. */
31 #define SMAP_INITIALIZER(SMAP) { HMAP_INITIALIZER(&(SMAP)->map) }
33 #define SMAP_FOR_EACH(SMAP_NODE, SMAP) \
34 HMAP_FOR_EACH (SMAP_NODE, node, &(SMAP)->map)
36 #define SMAP_FOR_EACH_SAFE(SMAP_NODE, NEXT, SMAP) \
37 HMAP_FOR_EACH_SAFE (SMAP_NODE, NEXT, node, &(SMAP)->map)
39 void smap_init(struct smap *);
40 void smap_destroy(struct smap *);
42 struct smap_node *smap_add(struct smap *, const char *, const char *);
43 bool smap_add_once(struct smap *, const char *, const char *);
44 void smap_add_format(struct smap *, const char *key, const char *, ...)
46 void smap_replace(struct smap *, const char *, const char *);
48 void smap_remove(struct smap *, const char *);
49 void smap_remove_node(struct smap *smap, struct smap_node *);
50 void smap_clear(struct smap *);
52 const char *smap_get(const struct smap *, const char *);
53 struct smap_node *smap_get_node(const struct smap *, const char *);
54 bool smap_get_bool(const struct smap *smap, const char *key, bool def);
55 int smap_get_int(const struct smap *smap, const char *key, int def);
57 bool smap_is_empty(const struct smap *);
58 size_t smap_count(const struct smap *);
60 void smap_clone(struct smap *dst, const struct smap *src);
61 const struct smap_node **smap_sort(const struct smap *);