[ovs-dev] [PATCH 2/2] idl: New helpers for accessing string maps.

Ethan Jackson ethan at nicira.com
Wed Mar 21 20:26:53 UTC 2012


Here's an incremental.

---
 ovsdb/ovsdb-idlc.in |   32 +++++++++++++-------------------
 1 file changed, 13 insertions(+), 19 deletions(-)

diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in
index 79e3d1e..2775d93 100755
--- a/ovsdb/ovsdb-idlc.in
+++ b/ovsdb/ovsdb-idlc.in
@@ -512,25 +512,19 @@ const struct ovsdb_datum *
             if not is_string_map(column):
                 continue
 
-            print
-            print "const char *"
-            print "%(s)s_get_%(c)s_value(const struct %(s)s *row," \
-                    " const char *key, const char *default_value)" \
-                    % {'s': structName, 'c': columnName}
-            print "{"
-            print "    char **keys = row->key_%s;" % columnName
-            print "    char **values = row->value_%s;" % columnName
-            print "    size_t n = row->n_%s;" % columnName
-            print "    size_t i;"
-            print
-            print "    assert(inited);"
-            print "    for (i = 0; i < n; i++) {"
-            print "        if (!strcmp(keys[i], key)) {"
-            print "            return values[i];"
-            print "        }"
-            print "    }"
-            print "    return default_value;"
-            print "}"
+            print """
+const char * %(s)s_get_%(c)s_value(const struct %(s)s *row, const char *key, const char *default_value)
+{
+    size_t i;
+
+    assert(inited);
+    for (i = 0; i < row->n_%(c)s; i++) {
+        if (!strcmp(row->key_%(c)s[i], key)) {
+            return row->value_%(c)s[i];
+        }
+    }
+    return default_value;
+}""" % {'s': structName, 'c': columnName}
 
         # Table columns.
         print "\nstruct ovsdb_idl_column %s_columns[%s_N_COLUMNS];" % (
-- 
1.7.9.4




More information about the dev mailing list