summaryrefslogtreecommitdiff
path: root/lib/smap.h
diff options
context:
space:
mode:
authorBen Pfaff <blp@ovn.org>2016-03-29 15:04:04 -0700
committerBen Pfaff <blp@ovn.org>2016-10-07 15:04:16 -0700
commit64982ba24c78ea2139c6cb93a4def61df6f8512c (patch)
tree7587ea47d2c5f1a0ce0cb25d5347bdd238ed78f5 /lib/smap.h
parent9784ffaf354042897d6f6e9a5b6d9ecf3cbbe1fb (diff)
downloadopenvswitch-64982ba24c78ea2139c6cb93a4def61df6f8512c.tar.gz
smap: New macro SMAP_CONST2 for an immutable map of 2 key-value pairs.
Future commits will add a user. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Andy Zhou <azhou@ovn.org>
Diffstat (limited to 'lib/smap.h')
-rw-r--r--lib/smap.h26
1 files changed, 17 insertions, 9 deletions
diff --git a/lib/smap.h b/lib/smap.h
index 49d31cbfd..37eac4731 100644
--- a/lib/smap.h
+++ b/lib/smap.h
@@ -54,16 +54,24 @@ struct smap_node {
*
* An smap initialized this way must not be modified or destroyed.
*
- * The 'KEY' argument is evaluated multiple times.
+ * The 'KEY', 'K1', 'K2' arguments are 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) }
+#define SMAP_CONST1(SMAP, KEY, VALUE) (const struct smap) { \
+ HMAP_CONST(&(SMAP)->map, 1, SMAP_NODE(KEY, VALUE, NULL)) \
+ }
+#define SMAP_CONST2(SMAP, K1, V1, K2, V2) (const struct smap) { \
+ HMAP_CONST(&(SMAP)->map, 2, \
+ SMAP_NODE(K1, V1, SMAP_NODE(K2, V2, NULL))) \
+ }
+#define SMAP_NODE(KEY, VALUE, NEXT) \
+ &(struct smap_node) { \
+ .node = { \
+ .hash = hash_string(KEY, 0), \
+ .next = (NEXT), \
+ }, \
+ .key = CONST_CAST(char *, KEY), \
+ .value = CONST_CAST(char *, VALUE), \
+ }.node
void smap_init(struct smap *);