diff options
author | Dylan Baker <baker.dylan.c@gmail.com> | 2015-01-13 16:28:51 -0800 |
---|---|---|
committer | Dylan Baker <baker.dylan.c@gmail.com> | 2015-01-28 12:08:10 -0800 |
commit | d57e9116ff6e80de96bdf54ef81277111cc7631b (patch) | |
tree | 4956513f53faaf9e2f7ee7e17b8ed6dad8f9993f /registry | |
parent | 5fda6adfbaebe74962337c193ace342f352d24dc (diff) |
gen_dispatch.py: remove use of cmp.
gen_dispatch.py contains a function used to sort Enums, and uses cmp.
This patch moves that logic into the Enum class using rich comparison
methods instead.
Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
Diffstat (limited to 'registry')
-rw-r--r-- | registry/gl.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/registry/gl.py b/registry/gl.py index 99f4a410a..2f8cda0e3 100644 --- a/registry/gl.py +++ b/registry/gl.py @@ -1076,6 +1076,7 @@ class EnumGroup(object): self.type = 'special' +@functools.total_ordering class Enum(object): """An <enum> XML element. @@ -1122,6 +1123,67 @@ class Enum(object): ' value={self.str_value!r})') return templ.format(self=self) + def __eq__(self, other): + if self.num_value != other.num_value: + return False + elif (self.vendor_namespace is None) != (other.vendor_namespace is None): + return False + elif (self.vendor_namespace in Extension.RATIFIED_NAMESPACES) != \ + (other.vendor_namespace in Extension.RATIFIED_NAMESPACES): + return False + elif (self.vendor_namespace == 'EXT') != \ + (other.vendor_namespace == 'EXT'): + return False + elif self.name != other.name: + return False + return self.api == other.api + + def __lt__(self, other): # pylint: disable=too-many-return-statements + """Less than. + + Sort by numerical value, then vendor_namspace (ratified first, then + EXT), then by full name, and finally by api. + + This sort order ensures that names provided by core specifications + precede those provided by ratified extensions, which proceed those + provided by unratified extensions. + + For example: GL_RED < GL_RED_EXT < GL_RED_INTEL + + """ + if self.num_value != other.num_value: + if self.num_value < other.num_value: + return True + return False + + x = self.vendor_namespace is None + y = other.vendor_namespace is None + if x != y: + if x and not y: + return True + return False + + x = self.vendor_namespace in Extension.RATIFIED_NAMESPACES + y = other.vendor_namespace in Extension.RATIFIED_NAMESPACES + if x != y: + if x and not y: + return True + return False + + x = self.vendor_namespace == 'EXT' + y = other.vendor_namespace == 'EXT' + if x != y: + if x and not y: + return True + return False + + if self.name != other.name: + if self.name < other.name: + return True + return False + + return self.api < other.api + @property def vendor_namespace(self): if self.__vendor_namespace is None: |