cdts creado, refinando ctype y cvalue

master
dev 1 year ago
parent c11ba8fdb4
commit aed26728b3

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

@ -0,0 +1,10 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

@ -0,0 +1,141 @@
// =============================================================================
// GO·AT Framework
// Copyright (c) 2025 ActiveThing (https://activething.com)
// Author: Juan V. Navarro juanvnl@activething.com
// =============================================================================
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// =============================================================================
// Date Create 13/06/2025
// =============================================================================
package cdts
import (
"reflect"
"sync"
)
type (
cBTypeInfos struct {
types []*cBTypeInfo
mux sync.RWMutex
cache map[reflect.Type]func(reflect.Value) CValue
}
)
func newCBTypeInfos() *cBTypeInfos {
vi := &cBTypeInfos{}
vi.types = []*cBTypeInfo{
/* 01 */ newCVTypeInfo(CBTypeInvalid ,"invalid" , optInvalidCreators()),
/* 02 */ newCVTypeInfo(CBTypeAny ,"any" , optAnyCreators [any ](nil)),
/* 03 */ newCVTypeInfo(CBTypeBool ,"bool" , optNormalCreators [bool ](CreateCBool)),
/* 04 */ newCVTypeInfo(CBTypeInt ,"int" , optNormalCreators [int ](CreateCInt)),
/* 05 */ newCVTypeInfo(CBTypeInt8 ,"int8" , optNormalCreators [int8 ](CreateCInt8)),
/* 06 */ newCVTypeInfo(CBTypeInt16 ,"int16" , optNormalCreators [int16 ](CreateCInt16)),
/* 07 */ newCVTypeInfo(CBTypeInt64 ,"int64" , optNormalCreators [int64 ](CreateCInt64)),
/* 08 */ newCVTypeInfo(CBTypeUint ,"uint" , optNormalCreators [uint ](CreateCUint)),
/* 09 */ newCVTypeInfo(CBTypeUint8 ,"uint8" ,
optNormalCreators[uint8](CreateCUint8),
// el creador de []uint8 debe de reportar el tipo Bytes y debe de llamar a su creador CreateCBytes
func(i *cBTypeInfo) { i.cByList = func(v any) CValue { return CreateCBytes(v.(Bytes)) } }),
/* 10 */ newCVTypeInfo(CBTypeUint16 ,"uint16" , optNormalCreators[uint16 ](CreateCUint16)),
/* 11 */ newCVTypeInfo(CBTypeUint32 ,"uint32" , optNormalCreators[uint32 ](CreateCUint32)),
/* 12 */ newCVTypeInfo(CBTypeUint64 ,"uint64" , optNormalCreators[uint64 ](CreateCUint64)),
/* 13 */ newCVTypeInfo(CBTypeUintptr ,"uintptr" , optNormalCreators[uintptr ](CreateCUintptr)),
/* 14 */ newCVTypeInfo(CBTypeDuration ,"duration" , optNormalCreators[Duration ](CreateCDuration)),
/* 15 */ newCVTypeInfo(CBTypeFloat32 ,"float32" , optNormalCreators[float32 ](CreateCFloat32)),
/* 16 */ newCVTypeInfo(CBTypeFloat64 ,"float64" , optNormalCreators[float64 ](CreateCFloat64)),
/* 17 */ newCVTypeInfo(CBTypeComplex64 ,"complex64" , optNormalCreators[complex64 ](CreateCComplex64 )),
/* 18 */ newCVTypeInfo(CBTypeComplex128 ,"complex128" , optNormalCreators[complex128 ](CreateCComplex128)),
// Big Int tiene una forma canonica de *big.Int, lo cual hace cambiar los constructores de Ptr ya que no lo
// debe des referenciar, en caso de que se pase por valor, debemos de convertirlo a un *BigInt, copiar su
// valor y una vez pasado llamar a la funcion de creacion CreateCBigInt
/* 19 */ newCVTypeInfo(CBTypeBigInt ,"bigint" , func(i *cBTypeInfo) {
i.cByVal = func (v any) CValue {
bv := v.(BigInt)
return CreateCBigInt(new(BigInt).Set(&bv))
}
i.cByPtr = func (v any) CValue { return CreateCBigInt(v.(*BigInt)) }
i.cByLazy= buildCreatorPByLazy[BigInt](CBTypeBigInt)
i.cByList= buildCreatorPByList[BigInt](CBTypeBigInt)
}),
/* 20 */ newCVTypeInfo(CBTypeHashAlg ,"hashalg" , optNormalCreators[HashAlg ](CreateCHashAlg)),
/* 21 */ newCVTypeInfo(CBTypeString ,"string" , optNormalCreators[string ](CreateCString)),
/* 22 */ newCVTypeInfo(CBTypeUUID ,"uuid" , optNormalCreators[UUID ](CreateCUUID)),
/* 23 */ newCVTypeInfo(CBTypeBytes ,"bytes" , optNormalCreators[Bytes ](CreateCBytes)),
/* 24 */ newCVTypeInfo(CBTypeStack ,"stack" , optNormalCreators[Stack ](CreateCStack)),
/* 25 */ newCVTypeInfo(CBTypeDate ,"date" , optNormalCreators[Date ](CreateCDate)),
/* 26 */ newCVTypeInfo(CBTypeCValue ,"cvalue" , optNormalCreators[CValue ](CreateCCValue)),
/* 27 */ newCVTypeInfo(CBTypeReflect ,"cvalue" , optNormalCreators[Reflect ](CreateCReflect)),
// Los interfaces solo se evaluate en su forma canonical
/* 28 */ newCVTypeInfo(CBTypeMapPackable,"mappackable", optAnyCreators [MapPackable](CreateCMapPackable)),
/* 29 */ newCVTypeInfo(CBTypeMapPackable,"mappackable", optAnyCreators [MapPackable](CreateCMapPackable)),
/* 30 */ newCVTypeInfo(CBTypeObjPackable,"objpackable", optAnyCreators [ObjPackable](CreateCObjectPackable)),
/* 31 */ newCVTypeInfo(CBTypePackable ,"packable" , optAnyCreators [Packable ](CreateCPackable)),
/* 32 */ newCVTypeInfo(CBTypeContext ,"context" , optAnyCreators [Context ](CreateCContext)),
/* 33 */ newCVTypeInfo(CBTypeError ,"error" , optNormalCreators [error ](CreateCError)),
/* 34 */ newCVTypeInfo(CBTypeStringer ,"stringer" , optNormalCreators [Stringer ](CreateCStringer)) ,
/* 35 */ newCVTypeInfo(CBTypeNil , "nil" , optSameCreators (CreateCNil)),
}
return vi
}
func (i *cBTypeInfos) createByReflection (value any) CValue {
rv := reflect.ValueOf(value)
if !rv.IsValid() {
return createCInvalidError(rv,CStateReflected,E.InvalidReflectValue)
}
rt := rv.Type()
i.mux.RLock()
rf,ok := i.cache[rt]
i.mux.RUnlock()
if ok {
return rf(rv)
}
tn := rt.String()
i.mux.Lock()
i.cache[rt]=rf
i.mux.RUnlock()
return rf(rv)
}

@ -0,0 +1,2 @@
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
Loading…
Cancel
Save

Powered by TurnKey Linux.