当前位置: 首页>>代码示例>>Golang>>正文


Golang TypeInfo.ArrayFixedSize方法代码示例

本文整理汇总了Golang中gobject/gi.TypeInfo.ArrayFixedSize方法的典型用法代码示例。如果您正苦于以下问题:Golang TypeInfo.ArrayFixedSize方法的具体用法?Golang TypeInfo.ArrayFixedSize怎么用?Golang TypeInfo.ArrayFixedSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gobject/gi.TypeInfo的用法示例。


在下文中一共展示了TypeInfo.ArrayFixedSize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TypeSize

// returns the size of a type, works only for TypeExact
func TypeSize(ti *gi.TypeInfo, flags TypeFlags) int {
	ptrsize := int(unsafe.Sizeof(unsafe.Pointer(nil)))
	switch tag := ti.Tag(); tag {
	case gi.TYPE_TAG_VOID:
		if ti.IsPointer() {
			return ptrsize
		}
		panic("Non-pointer void type is not supported")
	case gi.TYPE_TAG_UTF8, gi.TYPE_TAG_FILENAME, gi.TYPE_TAG_GLIST,
		gi.TYPE_TAG_GSLIST, gi.TYPE_TAG_GHASH:
		return ptrsize
	case gi.TYPE_TAG_ARRAY:
		size := ti.ArrayFixedSize()
		if size != -1 {
			return size * TypeSize(ti.ParamType(0), flags)
		}
		return ptrsize
	case gi.TYPE_TAG_INTERFACE:
		if ti.IsPointer() {
			flags |= TypePointer
		}
		return TypeSizeForInterface(ti.Interface(), flags)
	default:
		if ti.IsPointer() {
			flags |= TypePointer
		}
		return TypeSizeForTag(tag, flags)
	}
	panic("unreachable: " + ti.Tag().String())
}
开发者ID:gnanderson,项目名称:gogobject,代码行数:31,代码来源:type.go

示例2: TypeNeedsWrapper

func TypeNeedsWrapper(ti *gi.TypeInfo) bool {
	switch tag := ti.Tag(); tag {
	case gi.TYPE_TAG_VOID:
		if ti.IsPointer() {
			return false
		}
		panic("Non-pointer void type is not supported")
	case gi.TYPE_TAG_UTF8, gi.TYPE_TAG_FILENAME, gi.TYPE_TAG_GLIST,
		gi.TYPE_TAG_GSLIST, gi.TYPE_TAG_GHASH:
		return true
	case gi.TYPE_TAG_ARRAY:
		size := ti.ArrayFixedSize()
		if size != -1 {
			return TypeNeedsWrapper(ti.ParamType(0))
		}
		return true
	case gi.TYPE_TAG_ERROR:
		panic("not implemented")
	case gi.TYPE_TAG_INTERFACE:
		switch ti.Interface().Type() {
		case gi.INFO_TYPE_CALLBACK, gi.INFO_TYPE_ENUM, gi.INFO_TYPE_FLAGS,
			gi.INFO_TYPE_STRUCT, gi.INFO_TYPE_UNION:
			return false
		}
		return true
	}
	return false
}
开发者ID:gnanderson,项目名称:gogobject,代码行数:28,代码来源:type.go

示例3: GoType

func GoType(ti *gi.TypeInfo, flags TypeFlags) string {
	var out bytes.Buffer

	switch tag := ti.Tag(); tag {
	case gi.TYPE_TAG_VOID:
		if ti.IsPointer() {
			out.WriteString("unsafe.Pointer")
			break
		}
		panic("Non-pointer void type is not supported")
	case gi.TYPE_TAG_UTF8, gi.TYPE_TAG_FILENAME:
		if flags&TypeExact != 0 {
			out.WriteString("unsafe.Pointer")
		} else {
			out.WriteString("string")
		}
	case gi.TYPE_TAG_ARRAY:
		size := ti.ArrayFixedSize()
		if size != -1 {
			fmt.Fprintf(&out, "[%d]", size)
		} else {
			if flags&TypeExact != 0 {
				out.WriteString("unsafe.Pointer")
			} else {
				out.WriteString("[]")
			}
		}
		out.WriteString(GoType(ti.ParamType(0), flags))
	case gi.TYPE_TAG_GLIST:
		if flags&TypeExact != 0 {
			out.WriteString("unsafe.Pointer")
		} else {
			out.WriteString("[]")
			out.WriteString(GoType(ti.ParamType(0), flags|TypeListMember))
		}
	case gi.TYPE_TAG_GSLIST:
		if flags&TypeExact != 0 {
			out.WriteString("unsafe.Pointer")
		} else {
			out.WriteString("[]")
			out.WriteString(GoType(ti.ParamType(0), flags|TypeListMember))
		}
	case gi.TYPE_TAG_GHASH:
		if flags&TypeExact != 0 {
			out.WriteString("unsafe.Pointer")
		} else {
			out.WriteString("map[")
			out.WriteString(GoType(ti.ParamType(0), flags))
			out.WriteString("]")
			out.WriteString(GoType(ti.ParamType(1), flags))
		}
	case gi.TYPE_TAG_ERROR:
		// not used?
		out.WriteString("error")
	case gi.TYPE_TAG_INTERFACE:
		if ti.IsPointer() {
			flags |= TypePointer
		}
		out.WriteString(GoTypeForInterface(ti.Interface(), flags))
	default:
		if ti.IsPointer() {
			flags |= TypePointer
		}
		out.WriteString(GoTypeForTag(tag, flags))
	}

	return out.String()
}
开发者ID:gnanderson,项目名称:gogobject,代码行数:68,代码来源:type.go


注:本文中的gobject/gi.TypeInfo.ArrayFixedSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。