X-Git-Url: http://git.cascardo.eti.br/?a=blobdiff_plain;f=lib%2Fsmap.h;h=489497a0ff9363a65d946fa8d4caa79ccc5c1d85;hb=4adaf1828a88e0859f1eab1074216da9ba82a71a;hp=cac3878990081285a7267c99b33b3ae9f47a3166;hpb=7962b7f0168ef7d041ff820d66553b30b15b106f;p=cascardo%2Fovs.git diff --git a/lib/smap.h b/lib/smap.h index cac387899..489497a0f 100644 --- a/lib/smap.h +++ b/lib/smap.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2012, 2014 Nicira, Inc. +/* Copyright (c) 2012, 2014, 2015 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ #include "hmap.h" struct json; +struct uuid; /* A map from string to string. */ struct smap { @@ -38,6 +39,25 @@ struct smap_node { #define SMAP_FOR_EACH_SAFE(SMAP_NODE, NEXT, SMAP) \ HMAP_FOR_EACH_SAFE (SMAP_NODE, NEXT, node, &(SMAP)->map) +/* Initializer for an immutable struct smap 'SMAP' that contains a single + * 'KEY'-'VALUE' pair, e.g. + * + * const struct smap smap = SMAP1_CONST1(&smap, "key", "value"); + * + * An smap initialized this way must not be modified or destroyed. + * + * The 'KEY' argument is evaluated multiple times. + */ +#define SMAP_CONST1(SMAP, KEY, VALUE) { \ + HMAP_CONST1(&(SMAP)->map, \ + (&(struct smap_node) SMAP_NODE_INIT(KEY, VALUE).node)) \ + } +#define SMAP_NODE_INIT(KEY, VALUE) { \ + HMAP_NODE_INIT(hash_string(KEY, 0)), \ + CONST_CAST(char *, KEY), \ + CONST_CAST(char *, VALUE) } + + void smap_init(struct smap *); void smap_destroy(struct smap *); @@ -46,6 +66,7 @@ struct smap_node *smap_add_nocopy(struct smap *, char *, char *); bool smap_add_once(struct smap *, const char *, const char *); void smap_add_format(struct smap *, const char *key, const char *, ...) OVS_PRINTF_FORMAT(3, 4); +void smap_add_ipv6(struct smap *, const char *, struct in6_addr *); void smap_replace(struct smap *, const char *, const char *); void smap_remove(struct smap *, const char *); @@ -57,6 +78,7 @@ const char *smap_get(const struct smap *, const char *); struct smap_node *smap_get_node(const struct smap *, const char *); bool smap_get_bool(const struct smap *smap, const char *key, bool def); int smap_get_int(const struct smap *smap, const char *key, int def); +bool smap_get_uuid(const struct smap *, const char *key, struct uuid *); bool smap_is_empty(const struct smap *); size_t smap_count(const struct smap *);