lib: Adapt headers for use in C++.
authorCasey Barker <crbarker@google.com>
Thu, 4 Aug 2011 23:18:59 +0000 (16:18 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 4 Aug 2011 23:20:04 +0000 (16:20 -0700)
This commit makes several library headers suitable for inclusion in C++.

It adds [extern "C"] guards and makes minor changes to fix casting and
keyword issues.

AUTHORS
lib/classifier.h
lib/hash.h
lib/hmap.h
lib/ofp-util.h
lib/sset.h
lib/vconn.h

diff --git a/AUTHORS b/AUTHORS
index aeb3262..cf75c79 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -6,6 +6,7 @@ Andrew Lambeth          wal@nicira.com
 Andy Southgate          andy.southgate@citrix.com
 Ben Pfaff               blp@nicira.com
 Bryan Phillippe         bp@toroki.com
+Casey Barker            crbarker@google.com
 Dan Wendlandt           dan@nicira.com
 David Erickson          derickso@stanford.edu
 Ethan Jackson           ethan@nicira.com
index b1162ae..2e6d8b9 100644 (file)
 #include "openflow/nicira-ext.h"
 #include "openflow/openflow.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* A flow classifier. */
 struct classifier {
     int n_rules;                /* Total number of rules. */
@@ -164,4 +168,8 @@ struct cls_rule *cls_cursor_next(struct cls_cursor *, struct cls_rule *);
           : 0);                                                         \
          (RULE) = (NEXT))
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* classifier.h */
index 109612f..026eeda 100644 (file)
 #include <string.h>
 #include "util.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* This is the public domain lookup3 hash by Bob Jenkins from
  * http://burtleburtle.net/bob/c/lookup3.c, modified for style. */
 
@@ -81,8 +85,8 @@ static inline uint32_t hash_int(uint32_t x, uint32_t basis)
  * quality. */
 static inline uint32_t hash_boolean(bool x, uint32_t basis)
 {
-    enum { P0 = 0xc2b73583 };   /* This is hash_int(1, 0). */
-    enum { P1 = 0xe90f1258 };   /* This is hash_int(2, 0). */
+    const uint32_t P0 = 0xc2b73583;   /* This is hash_int(1, 0). */
+    const uint32_t P1 = 0xe90f1258;   /* This is hash_int(2, 0). */
     return (x ? P0 : P1) ^ HASH_ROT(basis, 1);
 }
 
@@ -108,4 +112,8 @@ static inline uint32_t hash_pointer(const void *p, uint32_t basis)
     return hash_int((uint32_t) (uintptr_t) p, basis);
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* hash.h */
index a987fa4..ed2d78d 100644 (file)
@@ -89,7 +89,7 @@ static inline void hmap_remove(struct hmap *, struct hmap_node *);
 
 void hmap_node_moved(struct hmap *, struct hmap_node *, struct hmap_node *);
 static inline void hmap_replace(struct hmap *, const struct hmap_node *old,
-                                struct hmap_node *new);
+                                struct hmap_node *new_node);
 
 struct hmap_node *hmap_random_node(const struct hmap *);
 
index 7ee3e69..dfd47be 100644 (file)
@@ -315,7 +315,8 @@ enum ofputil_action_code ofputil_decode_action_unsafe(
 static inline union ofp_action *
 ofputil_action_next(const union ofp_action *a)
 {
-    return (void *) ((uint8_t *) a + ntohs(a->header.len));
+    return ((union ofp_action *) (void *)
+            ((uint8_t *) a + ntohs(a->header.len)));
 }
 
 static inline bool
index 8810067..a739fce 100644 (file)
 
 #include "hmap.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct sset_node {
     struct hmap_node hmap_node;
     char name[1];
@@ -85,4 +89,8 @@ bool sset_equals(const struct sset *, const struct sset *);
     SSET_NAME_FROM_HMAP_NODE(                                           \
         hmap_next(&(SSET)->map, &SSET_NODE_FROM_NAME(NAME)->hmap_node))
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* sset.h */
index 3f8bc47..3c1ffe9 100644 (file)
 
 #include "flow.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct list;
 struct ofpbuf;
 struct ofp_action_header;
@@ -78,4 +82,8 @@ void pvconn_close(struct pvconn *);
 int pvconn_accept(struct pvconn *, int min_version, struct vconn **);
 void pvconn_wait(struct pvconn *);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* vconn.h */