def _convertType(propType, val): ''' Convert value from string form to the appropriate numeric type. ''' if propType in ['long', 'longlong', 'octet', 'short', 'ulong', 'ulonglong', 'ushort']: # If value contains an x, it is a hex value (base 16) if val.find('x') != -1: newValue = int(val,16) else: newValue = int(val) elif propType in ['double', 'float']: newValue = float(val) elif propType in ['char', 'string']: newValue = str(val) elif propType == 'boolean': newValue = {"TRUE": True, "FALSE": False}[val.strip().upper()] elif propType.find('complex') == 0: baseType = getMemberType(propType) real, imag = _prop_helpers.parseComplexString(val, baseType) if isinstance(real, basestring): real = int(real) imag = int(imag) newValue = complex(real, imag) else: newValue = None return newValue
def _complexLiteral(value, typename): memberType = properties.getMemberType(typename) real, imag = parseComplexString(value, memberType) if typename == "complexBoolean": real = translateBoolean(real) imag = translateBoolean(imag) elif typename == "complexFloat": real = str(real) + "F" imag = str(imag) + "F" elif typename in ["complexShort", "complexUShort"]: real = '(short)%d' % int(real) imag = '(short)%d' % int(imag) elif typename == "complexChar": real = charLiteral(str(real)) imag = charLiteral(str(imag)) elif typename == "complexOctet": real = '(byte)%d' % int(real) imag = '(byte)%d' % int(imag) return "new CF." + typename + "(" + str(real) + "," + str(imag) + ")"