github.com/goplus/reflectx@v1.2.2/abi/abi.go (about)

     1  package abi
     2  
     3  import (
     4  	"reflect"
     5  	"unsafe"
     6  )
     7  
     8  type MethodInfo struct {
     9  	Name     string
    10  	Func     reflect.Value
    11  	Type     reflect.Type
    12  	InTyp    reflect.Type
    13  	OutTyp   reflect.Type
    14  	InSize   uintptr
    15  	OutSize  uintptr
    16  	Pointer  bool
    17  	Indirect bool
    18  	Variadic bool
    19  	OnePtr   bool
    20  }
    21  
    22  type MethodProvider interface {
    23  	Insert(info *MethodInfo) (ifn unsafe.Pointer, index int) // insert method info
    24  	Remove(index []int)                                      // remove method info
    25  	Available() int                                          // available count
    26  	Used() int                                               // methods used
    27  	Cap() int                                                // methods capacity
    28  	Clear()                                                  // clear all methods
    29  }
    30  
    31  type MethodProviderList struct {
    32  	list   []MethodProvider
    33  	maxCap int
    34  }
    35  
    36  func (p *MethodProviderList) List() []MethodProvider {
    37  	return p.list
    38  }
    39  
    40  func (p *MethodProviderList) Clear() {
    41  	for _, v := range p.list {
    42  		v.Clear()
    43  	}
    44  }
    45  
    46  func (p *MethodProviderList) Add(mp MethodProvider) {
    47  	for _, v := range p.list {
    48  		if v == mp {
    49  			return
    50  		}
    51  	}
    52  	p.list = append(p.list, mp)
    53  	p.maxCap += mp.Cap()
    54  }
    55  
    56  func (p *MethodProviderList) Used() int {
    57  	var n int
    58  	for _, mp := range p.list {
    59  		n += mp.Used()
    60  	}
    61  	return n
    62  }
    63  
    64  func (p *MethodProviderList) Available() int {
    65  	var n int
    66  	for _, mp := range p.list {
    67  		n += mp.Available()
    68  	}
    69  	return n
    70  }
    71  
    72  func (p *MethodProviderList) Cap() int {
    73  	return p.maxCap
    74  }
    75  
    76  func AddMethodProvider(mp MethodProvider) {
    77  	Default.Add(mp)
    78  }
    79  
    80  var (
    81  	Default = &MethodProviderList{}
    82  )