xclass

package
v1.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TDemo1Class = ClassOf((*TDemo1)(nil))
View Source
var TDemo2Class = ClassOf((*TDemo2)(nil), NewClassTagByMap(map[string]string{
	"filter":  "11111",
	"summary": "this is Demo2 class tag test",
}))
View Source
var TObjectClass = ClassOf((*TObject)(nil))

Functions

func Create

func Create(class Class, props ...interface{}) interface{}

func FieldGetBoolFunc

func FieldGetBoolFunc(inst reflect.Value, field *classVTField) (v interface{}, err error)

func FieldGetComplex128Func

func FieldGetComplex128Func(inst reflect.Value, field *classVTField) (v interface{}, err error)

func FieldGetComplex64Func

func FieldGetComplex64Func(inst reflect.Value, field *classVTField) (v interface{}, err error)

func FieldGetFloat32Func

func FieldGetFloat32Func(inst reflect.Value, field *classVTField) (v interface{}, err error)

func FieldGetFloat64Func

func FieldGetFloat64Func(inst reflect.Value, field *classVTField) (v interface{}, err error)

func FieldGetInt16Func

func FieldGetInt16Func(inst reflect.Value, field *classVTField) (v interface{}, err error)

func FieldGetInt32Func

func FieldGetInt32Func(inst reflect.Value, field *classVTField) (v interface{}, err error)

func FieldGetInt64Func

func FieldGetInt64Func(inst reflect.Value, field *classVTField) (v interface{}, err error)

func FieldGetInt8Func

func FieldGetInt8Func(inst reflect.Value, field *classVTField) (v interface{}, err error)

func FieldGetIntFunc

func FieldGetIntFunc(inst reflect.Value, field *classVTField) (v interface{}, err error)

func FieldGetInterfaceFunc

func FieldGetInterfaceFunc(inst reflect.Value, field *classVTField) (v interface{}, err error)

func FieldGetStringFunc

func FieldGetStringFunc(inst reflect.Value, field *classVTField) (v interface{}, err error)

func FieldGetUint16Func

func FieldGetUint16Func(inst reflect.Value, field *classVTField) (v interface{}, err error)

func FieldGetUint32Func

func FieldGetUint32Func(inst reflect.Value, field *classVTField) (v interface{}, err error)

func FieldGetUint64Func

func FieldGetUint64Func(inst reflect.Value, field *classVTField) (v interface{}, err error)

func FieldGetUint8Func

func FieldGetUint8Func(inst reflect.Value, field *classVTField) (v interface{}, err error)

func FieldGetUintFunc

func FieldGetUintFunc(inst reflect.Value, field *classVTField) (v interface{}, err error)

func FieldSetAnyFunc

func FieldSetAnyFunc(inst reflect.Value, field *classVTField, value interface{}) error

func FieldSetBoolFunc

func FieldSetBoolFunc(inst reflect.Value, field *classVTField, value interface{}) error

func FieldSetChanFunc

func FieldSetChanFunc(inst reflect.Value, field *classVTField, value interface{}) error

func FieldSetComplex128Func

func FieldSetComplex128Func(inst reflect.Value, field *classVTField, value interface{}) error

func FieldSetComplex64Func

func FieldSetComplex64Func(inst reflect.Value, field *classVTField, value interface{}) error

func FieldSetFloat32Func

func FieldSetFloat32Func(inst reflect.Value, field *classVTField, value interface{}) error

func FieldSetFloat64Func

func FieldSetFloat64Func(inst reflect.Value, field *classVTField, value interface{}) error

func FieldSetInt16Func

func FieldSetInt16Func(inst reflect.Value, field *classVTField, value interface{}) error

func FieldSetInt32Func

func FieldSetInt32Func(inst reflect.Value, field *classVTField, value interface{}) error

func FieldSetInt64Func

func FieldSetInt64Func(inst reflect.Value, field *classVTField, value interface{}) error

func FieldSetInt8Func

func FieldSetInt8Func(inst reflect.Value, field *classVTField, value interface{}) error

func FieldSetIntFunc

func FieldSetIntFunc(inst reflect.Value, field *classVTField, value interface{}) error

func FieldSetMapFunc

func FieldSetMapFunc(inst reflect.Value, field *classVTField, value interface{}) (err error)

func FieldSetPtrFunc

func FieldSetPtrFunc(inst reflect.Value, field *classVTField, value interface{}) (err error)

func FieldSetSliceFunc

func FieldSetSliceFunc(inst reflect.Value, field *classVTField, value interface{}) (err error)

func FieldSetStringFunc

func FieldSetStringFunc(inst reflect.Value, field *classVTField, value interface{}) error

func FieldSetStructFunc

func FieldSetStructFunc(inst reflect.Value, field *classVTField, value interface{}) (err error)

func FieldSetUint16Func

func FieldSetUint16Func(inst reflect.Value, field *classVTField, value interface{}) error

func FieldSetUint32Func

func FieldSetUint32Func(inst reflect.Value, field *classVTField, value interface{}) error

func FieldSetUint64Func

func FieldSetUint64Func(inst reflect.Value, field *classVTField, value interface{}) error

func FieldSetUint8Func

func FieldSetUint8Func(inst reflect.Value, field *classVTField, value interface{}) error

func FieldSetUintFunc

func FieldSetUintFunc(inst reflect.Value, field *classVTField, value interface{}) error

func FieldSetUintPtrFunc

func FieldSetUintPtrFunc(inst reflect.Value, field *classVTField, value interface{}) error

func Free

func Free(obj *Object)

Types

type Class

type Class = *TClass

func ClassOf

func ClassOf(class Object, tag ...ClassTag) Class

classTag为class对象设置备注标记

type ClassField

type ClassField struct {
	// contains filtered or unexported fields
}

func (*ClassField) Name

func (cf *ClassField) Name() string

func (*ClassField) String

func (cf *ClassField) String() string

func (*ClassField) Tag

func (cf *ClassField) Tag() ClassTag

func (*ClassField) Type

func (cf *ClassField) Type() reflect.Type

type ClassMethod

type ClassMethod struct {
	// contains filtered or unexported fields
}

func (*ClassMethod) Name

func (cm *ClassMethod) Name() string

func (*ClassMethod) ParamTypes

func (cm *ClassMethod) ParamTypes() []reflect.Type

func (*ClassMethod) ResultTypes

func (cm *ClassMethod) ResultTypes() []reflect.Type

func (*ClassMethod) String

func (cm *ClassMethod) String() string

type ClassTag

type ClassTag = *TClassTag

func GetClassTag

func GetClassTag(classType reflect.Type) ClassTag

func NewClassTag

func NewClassTag(szTag ...string) ClassTag

func NewClassTagByMap

func NewClassTagByMap(items map[string]string) ClassTag

type Object

type Object interface {
	// 类对象构造方法
	// inst:为类实例指定, props参数由实现子类管理参数个数
	Constructor(props ...interface{}) interface{}
	// 析构方法
	Destroy()
	// 类实例指针
	This() interface{}
	// 创建新实例
	NewInstance(props ...interface{}) interface{}
	// 是否继承某类
	Implements(parent Class) bool
	// 转换成父类指针
	ToParent(parent Class) interface{}
	// 类名称
	ClassName() string
	// 类类型
	ClassType() reflect.Type
	// 设置字段值
	Set(fieldName string, value interface{}) error
	// 自动转换数据类型为字段类型后设置字段值
	SafeSet(fieldName string, value interface{}) (err error)
	// 获取字段值
	Get(fieldName string) interface{}
	GetVar(fieldName string) *_type.TVar
	// 设置动态字段值, 如果字段不存在则不设置,返回字段原来值
	DynamicSet(fieldName string, value interface{}) interface{}
	// 设置动态字段值,字段不存在时则创建,返回字段原来值
	DynamicTrySet(fieldName string, value interface{}) interface{}
	// 获取动态字段值
	DynamicGet(fieldName string) interface{}
	DynamicGetVar(fieldName string) *_type.TVar
	// 获取或设置动态字段, 如果不存在时,使使用setValue进行设置,setValue可以是实际值或func() interface{}类型的函数
	DynamicGetOrSet(fieldName string, setValue interface{}) interface{}
	DynamicGetOrSetVar(fieldName string, setValue interface{}) *_type.TVar
	// 调用类方法
	Call(method string, params ...interface{}) (results []interface{}, err error)
	// 检查类是否存在某方法
	HasMethod(method string) bool
	// 检查类是否存在某字段
	HasField(fieldName string) bool
	// 是否存在某动态字段
	HasDynamicField(fieldName string) bool
	// 动态字段值
	DynamicFieldCount() int
	// 遍历动态字段列表,fn返回false时结束遍历
	ForEachDynamicFields(fn func(k string, v interface{}) bool)
	// 类对象定义字段数
	FieldCount() int
	// 遍历对象字段列表
	ForEachFields(fn func(fieldName string, tag ClassTag, fieldType reflect.Type) bool)
	// 类对象定义方法数
	MethodCount() int
	// 类tag注解
	ClassTag() ClassTag
	// 获取类对象所有字段列表
	Fields() []*ClassField
	// 获取类对象方法列表
	Methods() []*ClassMethod
	// 遍历类对象方法
	ForEachMethods(fn func(methodName string, params []reflect.Type, results []reflect.Type) bool)
}

type ObjectDynamicFieldObserver

type ObjectDynamicFieldObserver interface {
	// 当设置动态字段值触发,仅在调用DynamicSet、DynamicTrySet、DynamicGetOrSet方法设置新值时发生, 如果返回false将取消设置
	OnDynamicFieldChanged(fieldName string, oldV, newV interface{}) bool
}

type ObjectFieldObserver

type ObjectFieldObserver interface {
	// 当设置字段值时触发,仅在调用Set、DynamicSet、DynamicTrySet、DynamicGetOrSet方法设置新值时发生.如果返回false将取消设置
	OnFieldChanged(fieldName string, oldV, newV interface{}) bool
}

类对象观察器

type ObjectHello

type ObjectHello interface {
	Hello() string
}

type TClass

type TClass struct {
	// contains filtered or unexported fields
}

func (*TClass) Create

func (cls *TClass) Create(props ...interface{}) interface{}

func (*TClass) Tag

func (cls *TClass) Tag() ClassTag

func (*TClass) Type

func (cls *TClass) Type() reflect.Type

type TClassTag

type TClassTag struct {
	// contains filtered or unexported fields
}

func (*TClassTag) Get

func (ft *TClassTag) Get(key string) TagValue

func (*TClassTag) HasKey

func (ft *TClassTag) HasKey(key string) bool

func (*TClassTag) Items

func (ft *TClassTag) Items() map[string]TagValue

func (*TClassTag) Parse

func (ft *TClassTag) Parse(szTag string) ClassTag

func (*TClassTag) String

func (ft *TClassTag) String() string

type TDemo1

type TDemo1 struct {
	*TObject

	AA string
	// contains filtered or unexported fields
}

func (*TDemo1) Constructor

func (d *TDemo1) Constructor(props ...interface{}) interface{}

func (*TDemo1) Hello

func (d *TDemo1) Hello() string

type TDemo2

type TDemo2 struct {
	*TDemo1

	Sex string
	// contains filtered or unexported fields
}

func (*TDemo2) Constructor

func (d2 *TDemo2) Constructor(props ...interface{}) interface{}

func (*TDemo2) Hello

func (d2 *TDemo2) Hello() string

func (*TDemo2) HelloName

func (d2 *TDemo2) HelloName(name string) string

func (*TDemo2) OnFieldChanged

func (d2 *TDemo2) OnFieldChanged(fieldName string, oldV, newV interface{}) bool

type TObject

type TObject struct {
	// contains filtered or unexported fields
}

func (*TObject) Call

func (o *TObject) Call(method string, params ...interface{}) (results []interface{}, err error)

调用类实例方法

func (*TObject) ClassName

func (o *TObject) ClassName() string

获取类名称

func (*TObject) ClassTag

func (o *TObject) ClassTag() ClassTag

func (*TObject) ClassType

func (o *TObject) ClassType() reflect.Type

获取类类型

func (*TObject) Constructor

func (o *TObject) Constructor(props ...interface{}) interface{}

func (*TObject) Destroy

func (o *TObject) Destroy()

func (*TObject) DynamicFieldCount

func (o *TObject) DynamicFieldCount() int

func (*TObject) DynamicGet

func (o *TObject) DynamicGet(fieldName string) interface{}

获取动态字段值

func (*TObject) DynamicGetOrSet

func (o *TObject) DynamicGetOrSet(fieldName string, setValue interface{}) interface{}

func (*TObject) DynamicGetOrSetVar

func (o *TObject) DynamicGetOrSetVar(fieldName string, setValue interface{}) *_type.TVar

func (*TObject) DynamicGetVar

func (o *TObject) DynamicGetVar(fieldName string) *_type.TVar

func (*TObject) DynamicSet

func (o *TObject) DynamicSet(fieldName string, value interface{}) interface{}

设置动态字段值,如果字段不存在则不进行设置

func (*TObject) DynamicTrySet

func (o *TObject) DynamicTrySet(fieldName string, value interface{}) interface{}

字段存不存在都设置新值

func (*TObject) FieldCount

func (o *TObject) FieldCount() int

获取类对像字段数

func (*TObject) Fields

func (o *TObject) Fields() []*ClassField

func (*TObject) ForEachDynamicFields

func (o *TObject) ForEachDynamicFields(fn func(k string, v interface{}) bool)

func (*TObject) ForEachFields

func (o *TObject) ForEachFields(fn func(fieldName string, tag ClassTag, fieldType reflect.Type) bool)

func (*TObject) ForEachMethods

func (o *TObject) ForEachMethods(fn func(methodName string, params []reflect.Type, results []reflect.Type) bool)

func (*TObject) Get

func (o *TObject) Get(fieldName string) interface{}

获取字段值

func (*TObject) GetVar

func (o *TObject) GetVar(fieldName string) *_type.TVar

func (*TObject) HasDynamicField

func (o *TObject) HasDynamicField(fieldName string) bool

func (*TObject) HasField

func (o *TObject) HasField(fieldName string) bool

检查类是否存在某字段

func (*TObject) HasMethod

func (o *TObject) HasMethod(method string) bool

检查类是否存在某方法

func (*TObject) Implements

func (o *TObject) Implements(parent Class) bool

检查是否继承自某类

func (*TObject) MethodCount

func (o *TObject) MethodCount() int

获取类对象方法数

func (*TObject) Methods

func (o *TObject) Methods() []*ClassMethod

func (*TObject) NewInstance

func (o *TObject) NewInstance(props ...interface{}) interface{}

func (*TObject) SafeSet

func (o *TObject) SafeSet(fieldName string, value interface{}) (err error)

数据类型自动转换的安全设置字段值

func (*TObject) SayHello

func (o *TObject) SayHello() string

func (*TObject) Set

func (o *TObject) Set(fieldName string, value interface{}) (err error)

设置字段值

func (*TObject) This

func (o *TObject) This() interface{}

func (*TObject) ToParent

func (o *TObject) ToParent(parent Class) interface{}

赋值给父类指针

type TagValue

type TagValue string

func (TagValue) IsEmpty

func (tv TagValue) IsEmpty() bool

func (TagValue) Map

func (tv TagValue) Map() map[string]string

func (TagValue) Raw

func (tv TagValue) Raw() string

func (TagValue) String

func (tv TagValue) String() string

func (TagValue) Value

func (tv TagValue) Value() string

func (TagValue) Values

func (tv TagValue) Values() []string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL