]> git.proxmox.com Git - ovs.git/blame - lib/smap.h
lib: Move compiler.h to <openvswitch/compiler.h>
[ovs.git] / lib / smap.h
CommitLineData
ff929935 1/* Copyright (c) 2012, 2014 Nicira, Inc.
79f1cbe9
EJ
2 *
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:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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. */
14
15#ifndef SMAP_H
16#define SMAP_H 1
17
18#include "hmap.h"
19
cccc1356
BP
20struct json;
21
79f1cbe9
EJ
22/* A map from string to string. */
23struct smap {
24 struct hmap map; /* Contains "struct smap_node"s. */
25};
26
27struct smap_node {
28 struct hmap_node node; /* In struct smap's 'map' hmap. */
29 char *key;
30 char *value;
31};
32
33#define SMAP_INITIALIZER(SMAP) { HMAP_INITIALIZER(&(SMAP)->map) }
34
35#define SMAP_FOR_EACH(SMAP_NODE, SMAP) \
36 HMAP_FOR_EACH (SMAP_NODE, node, &(SMAP)->map)
37
38#define SMAP_FOR_EACH_SAFE(SMAP_NODE, NEXT, SMAP) \
39 HMAP_FOR_EACH_SAFE (SMAP_NODE, NEXT, node, &(SMAP)->map)
40
41void smap_init(struct smap *);
42void smap_destroy(struct smap *);
43
44struct smap_node *smap_add(struct smap *, const char *, const char *);
ff929935 45struct smap_node *smap_add_nocopy(struct smap *, char *, char *);
79f1cbe9
EJ
46bool smap_add_once(struct smap *, const char *, const char *);
47void smap_add_format(struct smap *, const char *key, const char *, ...)
cab50449 48 OVS_PRINTF_FORMAT(3, 4);
79f1cbe9
EJ
49void smap_replace(struct smap *, const char *, const char *);
50
51void smap_remove(struct smap *, const char *);
51c82a49 52void smap_remove_node(struct smap *, struct smap_node *);
57c8677b 53void smap_steal(struct smap *, struct smap_node *, char **keyp, char **valuep);
79f1cbe9
EJ
54void smap_clear(struct smap *);
55
56const char *smap_get(const struct smap *, const char *);
57struct smap_node *smap_get_node(const struct smap *, const char *);
58bool smap_get_bool(const struct smap *smap, const char *key, bool def);
59int smap_get_int(const struct smap *smap, const char *key, int def);
60
61bool smap_is_empty(const struct smap *);
62size_t smap_count(const struct smap *);
63
4512aaa7 64void smap_clone(struct smap *dst, const struct smap *src);
79f1cbe9
EJ
65const struct smap_node **smap_sort(const struct smap *);
66
cccc1356
BP
67void smap_from_json(struct smap *, const struct json *);
68struct json *smap_to_json(const struct smap *);
69
79f1cbe9 70#endif /* smap.h */