From 73b4c1b3885bacb3a0ec5be645dbfbbefb99b658 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 14 Apr 2005 23:00:34 +0000 Subject: Refactor the handling of the '(true | false)' enumerated attributes. --- src/mesa/glapi/glX_XML.py | 30 +++++----------------------- src/mesa/glapi/gl_XML.py | 51 ++++++++++++++++++++--------------------------- 2 files changed, 27 insertions(+), 54 deletions(-) (limited to 'src/mesa') diff --git a/src/mesa/glapi/glX_XML.py b/src/mesa/glapi/glX_XML.py index 4c16a68cb6b..e48955e34e7 100644 --- a/src/mesa/glapi/glX_XML.py +++ b/src/mesa/glapi/glX_XML.py @@ -359,31 +359,11 @@ class glXFunction(gl_XML.glFunction): else: raise RuntimeError('Invalid handcode mode "%s" in function "%s".' % (handcode, self.name)) - - if attrs.get('ignore', "false") == "true": - self.ignore = 1 - else: - self.ignore = 0 - - if attrs.get('large', "false") == "true": - self.can_be_large = 1 - else: - self.can_be_large = 0 - - if attrs.get('doubles_in_order', "false") == "true": - self.glx_doubles_in_order = 1 - else: - self.glx_doubles_in_order = 0 - - if attrs.get('always_array', "false") == "true": - self.reply_always_array = 1 - else: - self.reply_always_array = 0 - - if attrs.get('dimensions_in_reply', "false") == "true": - self.dimensions_in_reply = 1 - else: - self.dimensions_in_reply = 0 + self.ignore = gl_XML.is_attr_true( attrs, 'ignore' ) + self.can_be_large = gl_XML.is_attr_true( attrs, 'large' ) + self.glx_doubles_in_order = gl_XML.is_attr_true( attrs, 'doubles_in_order' ) + self.reply_always_array = gl_XML.is_attr_true( attrs, 'always_array' ) + self.dimensions_in_reply = gl_XML.is_attr_true( attrs, 'dimensions_in_reply' ) else: gl_XML.glFunction.startElement(self, name, attrs) diff --git a/src/mesa/glapi/gl_XML.py b/src/mesa/glapi/gl_XML.py index 04890af3e54..8b7b400d9a4 100644 --- a/src/mesa/glapi/gl_XML.py +++ b/src/mesa/glapi/gl_XML.py @@ -31,6 +31,23 @@ from xml.sax.handler import feature_namespaces import re +def is_attr_true( attrs, name ): + """Read a name value from an element's attributes. + + The value read from the attribute list must be either 'true' or + 'false'. If the value is 'false', zero will be returned. If the + value is 'true', non-zero will be returned. An exception will be + raised for any other value.""" + + value = attrs.get(name, "false") + if value == "true": + return 1 + elif value == "false": + return 0 + else: + raise RuntimeError('Invalid value "%s" for boolean "%s".' % (value, name)) + + class glItem: """Generic class on which all other API entity types are based.""" @@ -178,17 +195,10 @@ class glParameter( glItem ): self.count_scale = int(attrs.get('count_scale', "1")) - if attrs.get('counter', "false") == "true": - self.is_counter = 1 - else: - self.is_counter = 0 + self.is_counter = is_attr_true( attrs, 'counter' ) + self.is_output = is_attr_true( attrs, 'output' ) - if attrs.get('output', "false") == "true": - self.is_output = 1 - else: - self.is_output = 0 - # Pixel data has special parameters. self.width = attrs.get('img_width', None) @@ -205,26 +215,9 @@ class glParameter( glItem ): self.img_type = attrs.get('img_type', None) self.img_target = attrs.get('img_target', None) - pad = attrs.get('img_pad_dimensions', "false") - if pad == "true": - self.img_pad_dimensions = 1 - else: - self.img_pad_dimensions = 0 - - - null_flag = attrs.get('img_null_flag', "false") - if null_flag == "true": - self.img_null_flag = 1 - else: - self.img_null_flag = 0 - - send_null = attrs.get('img_send_null', "false") - if send_null == "true": - self.img_send_null = 1 - else: - self.img_send_null = 0 - - + self.img_pad_dimensions = is_attr_true( attrs, 'img_pad_dimensions' ) + self.img_null_flag = is_attr_true( attrs, 'img_null_flag' ) + self.img_send_null = is_attr_true( attrs, 'img_send_null' ) if self.p_count > 0 or self.counter or self.count_parameter_list: has_count = 1 -- cgit v1.2.3