def literal(value, typename, complex=False): if complex: # Parse real and imaginary components real, imag = parseComplexString(value, typename) # Convert real and imaginary into type-specific literals real, imag = (literal(str(x), typename) for x in (real, imag)) return "%s(%s,%s)" % (cppType(typename, complex), real, imag) elif typename == CorbaTypes.STRING: if type(value) == list: return else: return stringLiteral(value) elif typename == CorbaTypes.BOOLEAN: if parseBoolean(value): return TRUE else: return FALSE elif typename in (CorbaTypes.LONGLONG, CorbaTypes.ULONGLONG): # Explicitly mark the literal as a 'long long' for 32-bit systems if not isinstance(value, list): return value + 'LL' elif typename == CorbaTypes.CHAR: return charLiteral(value) else: return value
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 literal(value, typename, complex=False): if typename in _typeMap: if complex: real, imag = parseComplexString(value, typename) value = 'complex({0},{1})'.format(real, imag) else: value = _typeMap[typename](value) return value
def literal(value, typename, complex=False): if isinstance(value, (list,tuple)): return '[%s]' % ','.join(literal(v, typename, complex) for v in value) if typename in _typeMap: if complex: real, imag = parseComplexString(value, typename) value = 'complex({0},{1})'.format(real, imag) else: value = _typeMap[typename](value) return value
def literal(value, typename, complex=False): if isinstance(value, (list, tuple)): return '[%s]' % ','.join(literal(v, typename, complex) for v in value) if typename in _typeMap: if complex: real, imag = parseComplexString(value, typename) value = 'complex({0},{1})'.format(real, imag) else: value = _typeMap[typename](value) return value
def literal(value, typename, complex=False): if complex: real, imag = parseComplexString(value, typename) return cppType(typename, complex) + "(" + str(real) + "," + str(imag) + ")" elif typename == CorbaTypes.STRING: return stringLiteral(value) elif typename == CorbaTypes.BOOLEAN: if parseBoolean(value): return TRUE else: return FALSE elif typename == CorbaTypes.CHAR: return charLiteral(value) else: return value
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) + ")"
def stringToComplex(value, type): real, imag = parseComplexString(value, type) if isinstance(real, basestring): real = int(real) imag = int(imag) return complex(real, imag)