]>
git.proxmox.com Git - mirror_ovs.git/blob - lib/smap.h
1 /* Copyright (c) 2012, 2014, 2015 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. */
23 /* A map from string to string. */
25 struct hmap map
; /* Contains "struct smap_node"s. */
29 struct hmap_node node
; /* In struct smap's 'map' hmap. */
34 #define SMAP_INITIALIZER(SMAP) { HMAP_INITIALIZER(&(SMAP)->map) }
36 #define SMAP_FOR_EACH(SMAP_NODE, SMAP) \
37 HMAP_FOR_EACH (SMAP_NODE, node, &(SMAP)->map)
39 #define SMAP_FOR_EACH_SAFE(SMAP_NODE, NEXT, SMAP) \
40 HMAP_FOR_EACH_SAFE (SMAP_NODE, NEXT, node, &(SMAP)->map)
42 /* Initializer for an immutable struct smap 'SMAP' that contains a single
43 * 'KEY'-'VALUE' pair, e.g.
45 * const struct smap smap = SMAP1_CONST1(&smap, "key", "value");
47 * An smap initialized this way must not be modified or destroyed.
49 * The 'KEY' argument is evaluated multiple times.
51 #define SMAP_CONST1(SMAP, KEY, VALUE) { \
52 HMAP_CONST1(&(SMAP)->map, \
53 (&(struct smap_node) SMAP_NODE_INIT(KEY, VALUE).node)) \
55 #define SMAP_NODE_INIT(KEY, VALUE) { \
56 HMAP_NODE_INIT(hash_string(KEY, 0)), \
57 CONST_CAST(char *, KEY), \
58 CONST_CAST(char *, VALUE) }
61 void smap_init(struct smap
*);
62 void smap_destroy(struct smap
*);
64 struct smap_node
*smap_add(struct smap
*, const char *, const char *);
65 struct smap_node
*smap_add_nocopy(struct smap
*, char *, char *);
66 bool smap_add_once(struct smap
*, const char *, const char *);
67 void smap_add_format(struct smap
*, const char *key
, const char *, ...)
68 OVS_PRINTF_FORMAT(3, 4);
69 void smap_replace(struct smap
*, const char *, const char *);
71 void smap_remove(struct smap
*, const char *);
72 void smap_remove_node(struct smap
*, struct smap_node
*);
73 void smap_steal(struct smap
*, struct smap_node
*, char **keyp
, char **valuep
);
74 void smap_clear(struct smap
*);
76 const char *smap_get(const struct smap
*, const char *);
77 struct smap_node
*smap_get_node(const struct smap
*, const char *);
78 bool smap_get_bool(const struct smap
*smap
, const char *key
, bool def
);
79 int smap_get_int(const struct smap
*smap
, const char *key
, int def
);
80 bool smap_get_uuid(const struct smap
*, const char *key
, struct uuid
*);
82 bool smap_is_empty(const struct smap
*);
83 size_t smap_count(const struct smap
*);
85 void smap_clone(struct smap
*dst
, const struct smap
*src
);
86 const struct smap_node
**smap_sort(const struct smap
*);
88 void smap_from_json(struct smap
*, const struct json
*);
89 struct json
*smap_to_json(const struct smap
*);
91 bool smap_equal(const struct smap
*, const struct smap
*);