public SimpleType(CodeContext /*!*/ context, string name, PythonTuple bases, PythonDictionary dict) : base(context, name, bases, dict) { object val; string sVal; const string allowedTypes = "?cbBghHiIlLdfuzZqQPXOv"; if (!TryGetBoundCustomMember(context, "_type_", out val) || (sVal = StringOps.AsString(val)) == null || sVal.Length != 1 || allowedTypes.IndexOf(sVal[0]) == -1) { throw PythonOps.AttributeError("AttributeError: class must define a '_type_' attribute which must be a single character string containing one of '{0}'.", allowedTypes); } _charType = sVal[0]; switch (sVal[0]) { case '?': _type = SimpleTypeKind.Boolean; break; case 'c': _type = SimpleTypeKind.Char; break; case 'b': _type = SimpleTypeKind.SignedByte; break; case 'B': _type = SimpleTypeKind.UnsignedByte; break; case 'h': _type = SimpleTypeKind.SignedShort; break; case 'H': _type = SimpleTypeKind.UnsignedShort; break; case 'i': _type = SimpleTypeKind.SignedInt; break; case 'I': _type = SimpleTypeKind.UnsignedInt; break; case 'l': _type = SimpleTypeKind.SignedLong; break; case 'L': _type = SimpleTypeKind.UnsignedLong; break; case 'f': _type = SimpleTypeKind.Single; break; case 'g': // long double, new in 2.6 case 'd': _type = SimpleTypeKind.Double; break; case 'q': _type = SimpleTypeKind.SignedLongLong; break; case 'Q': _type = SimpleTypeKind.UnsignedLongLong; break; case 'O': _type = SimpleTypeKind.Object; break; case 'P': _type = SimpleTypeKind.Pointer; break; case 'z': _type = SimpleTypeKind.CharPointer; break; case 'Z': _type = SimpleTypeKind.WCharPointer; break; case 'u': _type = SimpleTypeKind.WChar; break; case 'v': _type = SimpleTypeKind.VariantBool; break; case 'X': throw new NotImplementedException("simple type " + sVal); } }
public SimpleType(CodeContext /*!*/ context, string name, PythonTuple bases, PythonDictionary dict) : base(context, name, bases, dict) { string sVal; const string allowedTypes = "?cbBghHiIlLdfuzZqQPXOv"; const string swappedTypes = "fdhHiIlLqQ"; if (!TryGetBoundCustomMember(context, "_type_", out object val) || (sVal = StringOps.AsString(val)) == null || sVal.Length != 1 || allowedTypes.IndexOf(sVal[0]) == -1) { throw PythonOps.AttributeError("AttributeError: class must define a '_type_' attribute which must be a single character string containing one of '{0}'.", allowedTypes); } _charType = sVal[0]; switch (_charType) { case '?': _type = SimpleTypeKind.Boolean; break; case 'c': _type = SimpleTypeKind.Char; break; case 'b': _type = SimpleTypeKind.SignedByte; break; case 'B': _type = SimpleTypeKind.UnsignedByte; break; case 'h': _type = SimpleTypeKind.SignedShort; break; case 'H': _type = SimpleTypeKind.UnsignedShort; break; case 'i': _type = SimpleTypeKind.SignedInt; break; case 'I': _type = SimpleTypeKind.UnsignedInt; break; case 'l': _type = SimpleTypeKind.SignedLong; break; case 'L': _type = SimpleTypeKind.UnsignedLong; break; case 'f': _type = SimpleTypeKind.Single; break; case 'g': // long double, new in 2.6 case 'd': _type = SimpleTypeKind.Double; break; case 'q': _type = SimpleTypeKind.SignedLongLong; break; case 'Q': _type = SimpleTypeKind.UnsignedLongLong; break; case 'O': _type = SimpleTypeKind.Object; break; case 'P': _type = SimpleTypeKind.Pointer; break; case 'z': _type = SimpleTypeKind.CharPointer; break; case 'Z': _type = SimpleTypeKind.WCharPointer; break; case 'u': _type = SimpleTypeKind.WChar; break; case 'v': _type = SimpleTypeKind.VariantBool; break; case 'X': _type = SimpleTypeKind.BStr; break; default: throw new NotImplementedException("simple type " + sVal); } if (!name.EndsWith("_be", StringComparison.Ordinal) && !name.EndsWith("_le", StringComparison.Ordinal) && swappedTypes.IndexOf(_charType) != -1) { CreateSwappedType(context, name, bases, dict); } _format = (BitConverter.IsLittleEndian ? '<' : '>') + _charType.ToString(); }