ovsdb-idlc: Make no-op writes to write-only columns cheaper.
[sliver-openvswitch.git] / python / ovs / db / types.py
index 96cdae8..c858471 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
+# Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -287,7 +287,9 @@ class BaseType(object):
         if self.enum:
             literals = [value.toEnglish(escapeLiteral)
                         for value in self.enum.values]
-            if len(literals) == 2:
+            if len(literals) == 1:
+                english = 'must be %s' % (literals[0])
+            elif len(literals) == 2:
                 english = 'either %s or %s' % (literals[0], literals[1])
             else:
                 english = 'one of %s, %s, or %s' % (literals[0],
@@ -351,6 +353,15 @@ class BaseType(object):
         else:
             return "%(dst)s = %(src)s;" % args
 
+    def assign_c_value_casting_away_const(self, dst, src):
+        args = {'dst': dst, 'src': src}
+        if self.ref_table_name:
+            return ("%(dst)s = %(src)s->header_.uuid;") % args
+        elif self.type == StringType:
+            return "%(dst)s = CONST_CAST(char *, %(src)s);" % args
+        else:
+            return "%(dst)s = %(src)s;" % args
+
     def initCDefault(self, var, is_optional):
         if self.ref_table_name:
             return "%s = NULL;" % var
@@ -450,6 +461,11 @@ class Type(object):
     def is_map(self):
         return self.value is not None
 
+    def is_smap(self):
+        return (self.is_map()
+                and self.key.type == StringType
+                and self.value.type == StringType)
+
     def is_optional_pointer(self):
         return (self.is_optional() and not self.value
                 and (self.key.type == StringType or self.key.ref_table_name))