diff --git a/src/app/main.go b/src/app/main.go index 1970d06..cf27aa9 100644 --- a/src/app/main.go +++ b/src/app/main.go @@ -29,7 +29,7 @@ package main import ( - "core/cflss" + "core/vals" "fmt" ) @@ -39,28 +39,28 @@ func main() { var m map[string]int = map[string]int{ "ss" : 22, "ds" : 434} - c := cflss.G.TypeInfos.CreateCValue(m) + c := vals.G.TypeInfos.CreateCValue(m) fmt.Printf("%v+ --> %s \n",c,c.Type().String()) - g := cflss.G.TypeInfos.CreateCValue(func() int { return 1 } ) + g := vals.G.TypeInfos.CreateCValue(func() int { return 1 } ) fmt.Printf("%v+ --> %s \n",g,g.Type().String()) var f func() int - g = cflss.G.TypeInfos.CreateCValue(f) + g = vals.G.TypeInfos.CreateCValue(f) fmt.Printf("%v+ --> %s %s \n",g,g.Type().String(),g.State().String()) type st struct { na string } var a *st - e := cflss.G.TypeInfos.CreateCValue(a) + e := vals.G.TypeInfos.CreateCValue(a) fmt.Printf("%v+ --> %s %s \n",e,e.Type().String(),e.State().String()) */ var an any an = 0 - e := cflss.G.TypeInfos.CreateCValue(an) + e := vals.G.TypeInfos.CreateCValue(an) fmt.Printf("%v+ --> tipo : %s estado :%s \n",e,e.Type().String(),e.State().String()) } diff --git a/src/core/cfls/a.go b/src/core/cfls/a.go deleted file mode 100644 index 54aca1f..0000000 --- a/src/core/cfls/a.go +++ /dev/null @@ -1,139 +0,0 @@ -// ============================================================================= -// 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 02/06/2025 -// ============================================================================= - -package cfls - -import ( - "core/blrs" - "core/excs" - "reflect" - "time" -) - - - - -var ( - - G = struct { - CValTypeNames [maxCValTypes+1]string - cValTypeCreators [maxCValTypes+1]cValTypeCreators - typeToCValTypes map[reflect.Type]cValTypeCacheEntry - }{ - CValTypeNames: [maxCValTypes+1]string { - /* 0: */ "invalid", - /* 1: */ "any", - /* 2: */ "bool", - /* 3: */ "int", - /* 4: */ "int8", - /* 5: */ "int16", - /* 6: */ "int32", - /* 7: */ "int64", - /* 8: */ "uint", - /* 9: */ "uint8", - /* 10: */ "uint16", - /* 11: */ "uint32", - /* 12: */ "uint64", - /* 13: */ "uintptr", - /* 14: */ "float32", - /* 15: */ "float64", - /* 16: */ "complex64", - /* 17: */ "complex128", - /* 18: */ "duration", - /* 19: */ "date", - /* 20: */ "string", - /* 21: */ "bytes", - /* 22: */ "stack", - /* 23: */ "baleable", - /* 24: */ "error", - /* 25: */ "nil", - /* 26: */ "cval", - /* 27: */ "fields", - /* 28: */ "object", - /* 29: */ "defer", - /* 30: */ "list", - /* 31: */ "map", - /* 32: */ "flag", - }, - - cValTypeCreators: [maxCValTypes+1]cValTypeCreators{ - /* 0: */ createGValTypeCreators[any](CValTypeInvalid, createCValInvalid), - /* 1: */ createGValTypeCreators[any](CValTypeAny, CreateCValAny), - /* 2: */ createGValTypeCreators[bool](CValTypeBool, CreateCValBool), - /* 3: */ createGValTypeCreators[int](CValTypeInt, CreateCValInt), - /* 4: */ createGValTypeCreators[int8](CValTypeInt8, CreateCValInt8), - /* 5: */ createGValTypeCreators[int16](CValTypeInt16, CreateCValInt16), - /* 6: */ createGValTypeCreators[int32](CValTypeInt32, CreateCValInt32), - /* 7: */ createGValTypeCreators[int64](CValTypeInt64, CreateCValInt64), - /* 8: */ createGValTypeCreators[uint](CValTypeUint, CreateCValUint), - /* - caso en el que []uint debe de establecerse como bytes procedemos a construirlo manualmente - */ - /* 9 :*/ { - valueCreator: func(v any) CVal { return CreateCValUint8(v.(uint8)) }, - pointerCreator: func(v any) CVal { return createGValTypePointer(CValTypeUint8, CreateCValUint8, v.(*uint8)) }, - listCreator: func(v any) CVal { return createGValTypeList(CValTypeBytes, v.([]uint8)) }, - deferCreator: func(v any) CVal { return createGValTypeDefer(CValTypeDefer|CValTypeUint8, v.(func() uint8))}, - }, - - /* 10:*/ createGValTypeCreators[uint16](CValTypeUint16, CreateCValUint16), - /* 11:*/ createGValTypeCreators[uint32](CValTypeUint32, CreateCValUint32), - /* 12:*/ createGValTypeCreators[uint64](CValTypeUint64, CreateCValUint64), - /* 13:*/ createGValTypeCreators[uintptr](CValTypeUintptr, CreateCValUintptr), - /* 14:*/ createGValTypeCreators[float32](CValTypeFloat32, CreateCValFloat32), - /* 15:*/ createGValTypeCreators[float64](CValTypeFloat64, CreateCValFloat64), - /* 16:*/ createGValTypeCreators[complex64](CValTypeComplex64, CreateCValComplex64), - /* 17:*/ createGValTypeCreators[complex128](CValTypeComplex128, CreateCValComplex128), - /* 18:*/ createGValTypeCreators[time.Duration](CValTypeDuration, CreateCValDuration), - /* 19:*/ createGValTypeCreators[time.Time](CValTypeDate, CreateCValDate), - /* 20:*/ createGValTypeCreators[string](CValTypeString, CreateCValString), - /* 21:*/ createGValTypeCreators[[]uint8](CValTypeBytes, CreateCValBytes), - /* 22:*/ createGValTypeCreators[excs.Stack](CValTypeStack, CreateCValStack), - /* 23:*/ createGValTypeCreators[blrs.Baleable](CValTypeBaleable, CreateCValBaleable), - /* 24:*/ createGValTypeCreators[error](CValTypeError, CreateCValError), - /* 25:*/ createGValTypeCreators[any](CValTypeNil, CreateCValNil), - /* 26:*/ createGValTypeCreators[CVal](CValTypeCVal, CreateCValCVal), - /* 27:*/ createGValTypeCreators[any](CValTypeCFields, CreateCValFields), - /* 28:*/ createGValTypeCreators[any](CValTypeObject, CreateCValObject), - /* 29:*/ createGValTypeCreators[any](CValTypeDefer, CreateCValDefer), - /* 30:*/ createGValTypeCreators[any](CValTypeList, CreateCValList), - /* 31:*/ createGValTypeCreators[any](CValTypeMap, CreateCValMap), - /* 32:*/ createGValTypeCreators[any](CValTypeObject, createCValInvalid), - }, - - typeToCValTypes: makeCacheCValTypes(), - } - - - E = struct { - invalidNilDefer string - }{ - invalidNilDefer: "::invalid_nil_defer", - } - -) diff --git a/src/core/cfls/cfields.go b/src/core/cfls/cfields.go deleted file mode 100644 index 5a7a63e..0000000 --- a/src/core/cfls/cfields.go +++ /dev/null @@ -1,34 +0,0 @@ -// ============================================================================= -// 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 04/06/2025 -// ============================================================================= - -package cfls - - - - -type CFields = map[string]CVal diff --git a/src/core/cfls/cval.go b/src/core/cfls/cval.go deleted file mode 100644 index 728a2bd..0000000 --- a/src/core/cfls/cval.go +++ /dev/null @@ -1,267 +0,0 @@ -// ============================================================================= -// 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 02/06/2025 -// ============================================================================= - -package cfls - -import ( - "core/blrs" - "core/excs" - "reflect" - "time" -) - -type ( - - CVal struct { - _ [0]func() - - cType CValType - cState CValState - intVal int64 - strVal string - anyVal any - } -) - - -func CreateCVal (value any) CVal { - var f cValTypeCreateFunc - - switch value.(type) { - - /* Valores simples */ - case any : f = G.cValTypeCreators[ 1/* CValTypeAny.Index() */].valueCreator - case bool : f = G.cValTypeCreators[ 2/* CValTypeBool.Index() */].valueCreator - case int : f = G.cValTypeCreators[ 3/* CValTypeInt.Index() */].valueCreator - case int8 : f = G.cValTypeCreators[ 4/* CValTypeInt8.Index() */].valueCreator - case int16 : f = G.cValTypeCreators[ 5/* CValTypeInt16.Index() */].valueCreator - case int32 : f = G.cValTypeCreators[ 6/* CValTypeInt32.Index() */].valueCreator - case int64 : f = G.cValTypeCreators[ 7/* CValTypeInt64.Index() */].valueCreator - case uint : f = G.cValTypeCreators[ 8/* CValTypeUint.Index() */].valueCreator - case uint8 : f = G.cValTypeCreators[ 9/* CValTypeUint8.Index() */].valueCreator - case uint16 : f = G.cValTypeCreators[10/* CValTypeUint16.Index() */].valueCreator - case uint32 : f = G.cValTypeCreators[11/* CValTypeUint32.Index() */].valueCreator - case uint64 : f = G.cValTypeCreators[12/* CValTypeUint64.Index() */].valueCreator - case uintptr : f = G.cValTypeCreators[13/* CValTypeUintptr.Index() */].valueCreator - case float32 : f = G.cValTypeCreators[14/* CValTypeFloat32.Index() */].valueCreator - case float64 : f = G.cValTypeCreators[15/* CValTypeFloat64.Index() */].valueCreator - case complex64 : f = G.cValTypeCreators[16/* CValTypeComplex64.Index() */].valueCreator - case complex128 : f = G.cValTypeCreators[17/* CValTypeComplex128.Index()*/].valueCreator - case time.Duration : f = G.cValTypeCreators[18/* CValTypeTime.Duration.Index() */].valueCreator - case time.Time : f = G.cValTypeCreators[19/* CValTypeTime.Time.Index() */].valueCreator - case string : f = G.cValTypeCreators[20/* CValTypeString.Index() */].valueCreator - case []uint8 : f = G.cValTypeCreators[21/* CValTypeBytes.Index() */].valueCreator - case excs.Stack : f = G.cValTypeCreators[22/* CValTypeStack.Index() */].valueCreator - case blrs.Baleable : f = G.cValTypeCreators[23/* CValTypeBaleable.Index() */].valueCreator - case error : f = G.cValTypeCreators[24/* CValTypeError.Index() */].valueCreator - case CVal : f = G.cValTypeCreators[26/* CValTypeCVal.Index() */].valueCreator - case map[string]CVal: f = G.cValTypeCreators[27/* CValTypeCVal.Index() */].valueCreator - - /* Valores Listas */ - // case []any : f = G.cValTypeCreators[ 1/* CValTypeAny.Index() */].listCreator - // case []bool : f = G.cValTypeCreators[ 2/* CValTypeBool.Index() */].listCreator - // case []int : f = G.cValTypeCreators[ 3/* CValTypeInt.Index() */].listCreator - // case []int8 : f = G.cValTypeCreators[ 4/* CValTypeInt8.Index() */].listCreator - // case []int16 : f = G.cValTypeCreators[ 5/* CValTypeInt16.Index() */].listCreator - // case []int32 : f = G.cValTypeCreators[ 6/* CValTypeInt32.Index() */].listCreator - // case []int64 : f = G.cValTypeCreators[ 7/* CValTypeInt64.Index() */].listCreator - // case []uint : f = G.cValTypeCreators[ 8/* CValTypeUint.Index() */].listCreator - // case []uint8 : f = G.cValTypeCreators[ 9/* CValTypeUint8.Index() */].listCreator - // case []uint16 : f = G.cValTypeCreators[10/* CValTypeUint16.Index() */].listCreator - // case []uint32 : f = G.cValTypeCreators[11/* CValTypeUint32.Index() */].listCreator - // case []uint64 : f = G.cValTypeCreators[12/* CValTypeUint64.Index() */].listCreator - // case func()uint64: f = G.cValTypeCreators[12/* CValTypeUint64.Index() */].deferCreator - // case []uintptr : f = G.cValTypeCreators[13/* CValTypeUintptr.Index() */].listCreator - // case []float32 : f = G.cValTypeCreators[14/* CValTypeFloat32.Index() */].listCreator - // case []float64 : f = G.cValTypeCreators[15/* CValTypeFloat64.Index() */].listCreator - // case []complex64 : f = G.cValTypeCreators[16/* CValTypeComplex64.Index() */].listCreator - // case []complex128: f = G.cValTypeCreators[17/* CValTypeComplex128.Index() */].listCreator - // case []time.Duration : f = G.cValTypeCreators[18/* CValTypeTime.Duration.Index() */].listCreator - // case []time.Time : f = G.cValTypeCreators[19/* CValTypeTime.Time.Index() */].listCreator - // case []string : f = G.cValTypeCreators[20/* CValTypeString.Index() */].listCreator - // case []excs.Stack: f = G.cValTypeCreators[22/* CValTypeStack.Index() */].listCreator - // case []blrs.Baleable : f = G.cValTypeCreators[23/* CValTypeBaleable.Index() */].listCreator - // case []error : f = G.cValTypeCreators[24/* CValTypeError.Index() */].listCreator - // case []CVal : f = G.cValTypeCreators[26/* CValTypeCVal.Index() */].listCreator - // case []map[string]CVal : f = G.cValTypeCreators[27]/* CValTypeCVal.Index() */].listCreator - - - - - - default: - rv := reflect.ValueOf(value) - if !rv.IsValid() { - return createCValInvalid(value) - } - - rt := rv.Type() - ti,ok := G.typeToCValTypes[rt] - if ok { - f = G.cValTypeCreators[ti.i].creatorByIndex(ti.c) - } else { - // --- Fallback para tipos NO mapeados explícitamente en typeToCValInfoMap --- - switch rt.Kind() { - case reflect.Ptr: - return createCValPointerByReflected(rv) - case reflect.Struct: - return createCValObjectByReflected(rv) - case reflect.Map: - return createCValMapByReflected(rv) - case reflect.Slice, - reflect.Array: - return createCValListByReflected(rv) - case reflect.Func: - return createCValDeferByReflected(rv) - default: - // Cualquier otro tipo que no se pudo identificar - return CreateCValAny(value) - } - } - } - - return f(value) -} - - - - -func CreateCValAny (value any ) CVal { return CVal{ } } -func CreateCValBool (value bool ) CVal { return CVal{ } } -func CreateCValInt (value int ) CVal { return CVal{ } } -func CreateCValInt8 (value int8 ) CVal { return CVal{ } } -func CreateCValInt16 (value int16 ) CVal { return CVal{ } } -func CreateCValInt32 (value int32 ) CVal { return CVal{ } } -func CreateCValInt64 (value int64 ) CVal { return CVal{ } } -func CreateCValUint (value uint ) CVal { return CVal{ } } -func CreateCValUint8 (value uint8 ) CVal { return CVal{ } } -func CreateCValUint16 (value uint16 ) CVal { return CVal{ } } -func CreateCValUint32 (value uint32 ) CVal { return CVal{ } } -func CreateCValUint64 (value uint64 ) CVal { return CVal{ } } -func CreateCValUintptr (value uintptr ) CVal { return CVal{ } } -func CreateCValFloat32 (value float32 ) CVal { return CVal{ } } -func CreateCValFloat64 (value float64 ) CVal { return CVal{ } } -func CreateCValComplex64 (value complex64 ) CVal { return CVal{ } } -func CreateCValComplex128 (value complex128) CVal { return CVal{ } } -func CreateCValDuration (value time.Duration) CVal { return CVal{ } } -func CreateCValDate (value time.Time ) CVal { return CVal{ } } -func CreateCValString (value string ) CVal { return CVal{ } } -func CreateCValBytes (value []uint8 ) CVal { return CVal{ } } -func CreateCValStack (value excs.Stack) CVal { return CVal{ } } -func CreateCValBaleable (value blrs.Baleable) CVal { return CVal{ } } -func CreateCValError (value error ) CVal { return CVal{ } } -func CreateCValNil (value any ) CVal { return CVal{ } } -func CreateCValCVal (value CVal ) CVal { return CVal{ } } -func CreateCValObject (value any) CVal { return CVal{ } } - - -func CreateCValDefer (value any) CVal { return CVal{ } } -func CreateCValList (value any) CVal { return CVal{ } } -func CreateCValFields (value any) CVal { return CVal{ } } -func CreateCValMap (value any) CVal { return CVal{ } } - - -func createCValInvalid (value any) CVal { - return CVal{} -} - - - - -func createCValPointerByReflected (value reflect.Value) CVal { - ti,ok := G.typeToCValTypes[value.Elem().Type()] - if !ok { - // - } - return G.cValTypeCreators[bt.Index()].pointerCreator(value) -} - -func createCValListByReflected (rvalue reflect.Value) CVal { - // asumimos que rvalue es valido y que es una slice ya que la llamada - // se ha hecho o bien a traves de CreateCVal o CreateCValList - if bt,ok := G.typeToCValTypes[rvalue.Type()]; ok { - return G.cValTypeCreators[bt.i]. bt.c(rvalue.Interface()) - } - if bt == CValTypeInvalid { - return createCValInvalid(rvalue) - } - bt|=CValTypeList - var cState CValState - if rvalue.IsNil() { // Aunque Kind sea Slice, el slice subyacente puede ser nil - cState = cValStateNil - return CVal{cType: bt, cState: cState} - } - cState = cValStateReflected - if rvalue.Len() == 0 { - cState |= cValStateZero - } - return CVal{cType: bt, cState: cState, anyVal: rvalue} -} - -func createCValMapByReflected (rvalue reflect.Value) CVal { - kt := reflectTypeToCValType(rvalue.Type().Key()) - if kt == CValTypeInvalid { - return createCValInvalid(rvalue) - } - vt := reflectTypeToCValType(rvalue.Type().Elem()) - if vt == CValTypeInvalid { - return createCValInvalid(rvalue) - } - - if kt == CValTypeString && vt == CValTypeCVal { - // Es un fields // debemos llamar a create fields - return CreateCValFields(rvalue.Interface().(map[string]CVal)) - } - bt := BuildMapType(kt,vt) - var cState CValState - if rvalue.IsNil() { - cState = cValStateNil - return CVal{cType: bt, cState: cState} - } - cState = cValStateReflected - if rvalue.Len() == 0 { - cState |= cValStateZero - } - return CVal{cType: bt, cState: cState, anyVal: rvalue} -} - -func createCValObjectByReflected (rvalue reflect.Value) CVal { - return CVal{cType: CValTypeObject, cState: cValStateReflected, anyVal: rvalue} -} - -func createCValDeferByReflected (rvalue reflect.Value) CVal { - rt := rvalue.Type() - if rt.NumIn() != 0 || rt.NumOut() != 1 { - return CVal{ cType: CValTypeAny, cState: cValStateReflected, anyVal: rvalue } - } - bt := reflectTypeToCValType(rt.Out(0)) - if bt == CValTypeInvalid { - return createCValInvalid(rvalue) - } - return G.cValTypeCreators[bt.Index()].deferCreator(rvalue.Interface()) -} diff --git a/src/core/cfls/cval_creators.go b/src/core/cfls/cval_creators.go deleted file mode 100644 index 6e2e271..0000000 --- a/src/core/cfls/cval_creators.go +++ /dev/null @@ -1,95 +0,0 @@ -// ============================================================================= -// 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 02/06/2025 -// ============================================================================= - -package cfls - - - -type ( - - cValTypeCreators struct { - valueCreator, - pointerCreator, - listCreator, - deferCreator cValTypeCreateFunc - } - - cValTypeCreateFunc func (v any) CVal -) - -func createGValTypeCreators [T any] (valType CValType, createFnc func(value T) CVal) cValTypeCreators { - return cValTypeCreators{ - valueCreator : func(v any) CVal { return createFnc(v.(T)) }, - pointerCreator : func(v any) CVal { return createGValTypePointer(valType,createFnc,v.(*T))}, - listCreator : func(v any) CVal { return createGValTypeList (CValTypeList |valType,v.([]T)) }, - deferCreator : func(v any) CVal { return createGValTypeDefer(CValTypeDefer|valType,v.(func() T)) }, - } -} - - -func (c cValTypeCreators) creatorByIndex (idx int) cValTypeCreateFunc { - switch idx { - case cvalCreatorByValue : return c.valueCreator - case cvalCreatorByPointer : return c.pointerCreator - case cvalCreatorByList : return c.listCreator - case cvalCreatorByDefer : return c.deferCreator - default: - return createCValInvalid - } -} - - -func createGValTypeList [T any](vType CValType, value []T) CVal { - if value == nil { - return CVal{cType : vType, cState: cValStateNil} - } - var state CValState - if len(value) == 0 { - state = cValStateZero - } - return CVal{cType : vType, cState: state,anyVal: value} -} - - -func createGValTypePointer[T any](vType CValType, createFnc func(value T) CVal, value *T) CVal { - if value == nil { - return CVal{cType : vType, cState: cValStateNil} - } - return createFnc(*value) -} - - -func createGValTypeDefer[T any](vType CValType,value func()T) CVal { - if value == nil { - return CVal{cType : vType, cState: cValStateInvalid|cValStateNil|cValStateError, strVal: E.invalidNilDefer} - } - return CVal{cType: vType,anyVal: value} -} - - - diff --git a/src/core/cfls/cval_type.go b/src/core/cfls/cval_type.go deleted file mode 100644 index bc2dccb..0000000 --- a/src/core/cfls/cval_type.go +++ /dev/null @@ -1,227 +0,0 @@ -// ============================================================================= -// 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 02/06/2025 -// ============================================================================= - -package cfls - -import ( - "math/bits" -) - - - - -const ( - - maxCValTypes int = 32 - - // CValType's definidos - CValTypeInvalid CValType = 0 - - CValTypeAny CValType = 1 << 0 - - CValTypeBool CValType = 1 << 1 - - CValTypeInt CValType = 1 << 2 - CValTypeInt8 CValType = 1 << 3 - CValTypeInt16 CValType = 1 << 4 - CValTypeInt32 CValType = 1 << 5 - CValTypeInt64 CValType = 1 << 6 - - CValTypeUint CValType = 1 << 7 - CValTypeUint8 CValType = 1 << 8 - CValTypeUint16 CValType = 1 << 9 - CValTypeUint32 CValType = 1 << 10 - CValTypeUint64 CValType = 1 << 11 - - CValTypeUintptr CValType = 1 << 12 - - CValTypeFloat32 CValType = 1 << 13 - CValTypeFloat64 CValType = 1 << 14 - - CValTypeComplex64 CValType = 1 << 15 - CValTypeComplex128 CValType = 1 << 16 - - CValTypeDuration CValType = 1 << 17 - CValTypeDate CValType = 1 << 18 - - CValTypeString CValType = 1 << 19 - CValTypeBytes CValType = 1 << 20 - CValTypeStack CValType = 1 << 21 - - CValTypeBaleable CValType = 1 << 22 - - CValTypeError CValType = 1 << 23 - CValTypeNil CValType = 1 << 24 - - CValTypeCVal CValType = 1 << 25 - CValTypeCFields CValType = 1 << 26 - CValTypeObject CValType = 1 << 27 - - CValTypeDefer CValType = 1 << 28 - CValTypeList CValType = 1 << 29 - CValTypeMap CValType = 1 << 30 - CValTypeMapKey CValType = 1 << 31 - - - maskCValTypeComposite= CValTypeDefer|CValTypeList|CValTypeMap - maskCValTypeBase = ^(maskCValTypeComposite | CValTypeMapKey) -) - - -type CValType uint32 - - - -func (t CValType) IsComposite() bool { return t&maskCValTypeComposite != 0 } - -func (t CValType) BaseType () CValType { - if t&CValTypeMap == 0 { - return t &maskCValTypeBase - } - _,vt := t.MapType() - return vt -} - -func (t CValType) DeferType() CValType { - if t&CValTypeDefer == 0 { - return CValTypeInvalid - } - return t &maskCValTypeBase -} - -func (t CValType) ListType () CValType { - if t&CValTypeList == 0 { - return CValTypeInvalid - } - return t &maskCValTypeBase -} - -func (t CValType) FieldsType() CValType { - if t&CValTypeCFields == 0 { - return CValTypeInvalid - } - return t &maskCValTypeBase -} - -func (t CValType) MapType () (CValType,CValType) { - if t&CValTypeMap == 0 { - return CValTypeInvalid, CValTypeInvalid - } - bs := t &maskCValTypeBase - switch bits.OnesCount32(uint32(bs)) { - case 1: return bs,bs - case 2: - if t&CValTypeMapKey == 0 { - return bs&-bs,bs&^(bs&-bs) - } - return bs&^(bs&-bs),bs&-bs - default: - return CValTypeInvalid,CValTypeInvalid - } -} - - -func (t CValType) IsTypeInvalid () bool { return t&maskCValTypeBase == CValTypeInvalid } -func (t CValType) IsTypeAny () bool { return t&maskCValTypeBase == CValTypeAny } -func (t CValType) IsTypeBool () bool { return t&maskCValTypeBase == CValTypeBool } -func (t CValType) IsTypeInt () bool { return t&maskCValTypeBase == CValTypeInt } -func (t CValType) IsTypeInt8 () bool { return t&maskCValTypeBase == CValTypeInt8 } -func (t CValType) IsTypeInt16 () bool { return t&maskCValTypeBase == CValTypeInt16 } -func (t CValType) IsTypeInt32 () bool { return t&maskCValTypeBase == CValTypeInt32 } -func (t CValType) IsTypeInt64 () bool { return t&maskCValTypeBase == CValTypeInt64 } -func (t CValType) IsTypeUint () bool { return t&maskCValTypeBase == CValTypeUint } -func (t CValType) IsTypeUint8 () bool { return t&maskCValTypeBase == CValTypeUint8 } -func (t CValType) IsTypeUint16 () bool { return t&maskCValTypeBase == CValTypeUint16 } -func (t CValType) IsTypeUint32 () bool { return t&maskCValTypeBase == CValTypeUint32 } -func (t CValType) IsTypeUint64 () bool { return t&maskCValTypeBase == CValTypeUint64 } -func (t CValType) IsTypeUintptr () bool { return t&maskCValTypeBase == CValTypeUintptr } -func (t CValType) IsTypeFloat32 () bool { return t&maskCValTypeBase == CValTypeFloat32 } -func (t CValType) IsTypeFloat64 () bool { return t&maskCValTypeBase == CValTypeFloat64 } -func (t CValType) IsTypeComplex64 () bool { return t&maskCValTypeBase == CValTypeComplex64} -func (t CValType) IsTypeComplex128 () bool { return t&maskCValTypeBase == CValTypeComplex128} -func (t CValType) IsTypeDuration () bool { return t&maskCValTypeBase == CValTypeDuration } -func (t CValType) IsTypeDate () bool { return t&maskCValTypeBase == CValTypeDate } -func (t CValType) IsTypeString () bool { return t&maskCValTypeBase == CValTypeString } -func (t CValType) IsTypeBytes () bool { return t&maskCValTypeBase == CValTypeBytes } -func (t CValType) IsTypeStack () bool { return t&maskCValTypeBase == CValTypeStack } -func (t CValType) IsTypeBaleable () bool { return t&maskCValTypeBase == CValTypeBaleable } -func (t CValType) IsTypeError () bool { return t&maskCValTypeBase == CValTypeError } -func (t CValType) IsTypeNil () bool { return t&maskCValTypeBase == CValTypeNil } -func (t CValType) IsTypeCVal () bool { return t&maskCValTypeBase == CValTypeCVal } -func (t CValType) IsFields () bool { return t&CValTypeCFields != 0 } -func (t CValType) IsTypeObject () bool { return t&maskCValTypeBase == CValTypeObject } - -func (t CValType) IsDefer () bool { return t&CValTypeDefer != 0 } -func (t CValType) IsList () bool { return t&CValTypeList != 0 } -func (t CValType) IsMap () bool { return t&CValTypeMap != 0 } - - - -func (t CValType) Index() int { - if t == 0 { - return 0 - } - return bits.TrailingZeros32(uint32(t))+1 -} - - -func (t CValType) String () string { - if t.IsComposite() { - if t.IsDefer () { - return "defer|" + t.BaseType().String() - } - if t.IsList () { - return "list|" + t.BaseType().String() - } - if t.IsFields() { - return "fields|" + t.BaseType().String() - } - if t.IsMap () { - k, v := t.MapType() - return "map@" + k.String() + "|" + v.String() - } - } - return G.CValTypeNames[t.Index()] -} - - - -func BuildMapType(keyType, valType CValType) CValType { - if keyType == CValTypeInvalid || valType == CValTypeInvalid { - return CValTypeInvalid - } - if keyType == valType { - return CValTypeMap|keyType - } - if keyType < valType { - return CValTypeMap|keyType|valType - } - return CValTypeMap|keyType|valType|CValTypeMapKey -} - - diff --git a/src/core/cfls/cval_type_cache.go b/src/core/cfls/cval_type_cache.go deleted file mode 100644 index f639210..0000000 --- a/src/core/cfls/cval_type_cache.go +++ /dev/null @@ -1,200 +0,0 @@ -// ============================================================================= -// 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. -// / -// ============================================================================ -// ate Create 03/06/2025 -// ============================================================================ - -package cfls - -import ( - "core/blrs" - "core/excs" - "reflect" - "time" -) - -type cValTypeCacheEntry struct { - t CValType - i int - c int - } - -func makeCacheCValTypes () map[reflect.Type]cValTypeCacheEntry { - return map[reflect.Type]cValTypeCacheEntry { - // Any - reflect.TypeOf(any(nil)): {i: 1, t: CValTypeAny, c: 0}, - reflect.TypeOf((*any)(nil)): {i: 1, t: CValTypeAny, c: 1}, - reflect.TypeOf([]any(nil)): {i: 1, t: CValTypeAny|CValTypeList , c: 2}, - reflect.TypeOf((*func()any)(nil)).Elem(): {i: 1, t: CValTypeAny|CValTypeDefer, c: 3}, - - // Bool - reflect.TypeOf(true): {i: 2, t: CValTypeBool, c: 0}, - reflect.TypeOf(new(bool)): {i: 2, t: CValTypeBool, c: 1}, - reflect.TypeOf([]bool(nil)): {i: 2, t: CValTypeBool|CValTypeList , c: 2}, - reflect.TypeOf((*func() bool)(nil)).Elem(): {i: 2, t: CValTypeBool|CValTypeDefer, c: 3}, - - // Int - reflect.TypeOf(int(0)): {i: 3, t: CValTypeInt, c: 0}, - reflect.TypeOf(new(int)): {i: 3, t: CValTypeInt, c: 1}, - reflect.TypeOf([]int(nil)): {i: 3, t: CValTypeInt|CValTypeList , c: 2}, - reflect.TypeOf((*func() int)(nil)).Elem(): {i: 3, t: CValTypeInt|CValTypeDefer, c: 3}, - - // Int8 - reflect.TypeOf(int8(0)): {i: 4, t: CValTypeInt8, c: 0}, - reflect.TypeOf(new(int8)): {i: 4, t: CValTypeInt8, c: 1}, - reflect.TypeOf([]int8(nil)): {i: 4, t: CValTypeInt8|CValTypeList , c: 2}, - reflect.TypeOf((*func() int8)(nil)).Elem(): {i: 4, t: CValTypeInt8|CValTypeDefer, c: 3}, - - // Int16 - reflect.TypeOf(int16(0)): {i: 5, t: CValTypeInt16, c: 0}, - reflect.TypeOf(new(int16)): {i: 5, t: CValTypeInt16, c: 1}, - reflect.TypeOf([]int16(nil)): {i: 5, t: CValTypeInt16|CValTypeList , c: 2}, - reflect.TypeOf((*func() int16)(nil)).Elem(): {i: 5, t: CValTypeInt16|CValTypeDefer, c: 3}, - - // Int32 - reflect.TypeOf(int32(0)): {i: 6, t: CValTypeInt32, c: 0}, - reflect.TypeOf(new(int32)): {i: 6, t: CValTypeInt32, c: 1}, - reflect.TypeOf([]int32(nil)): {i: 6, t: CValTypeInt32|CValTypeList , c: 2}, - reflect.TypeOf((*func() int32)(nil)).Elem(): {i: 6, t: CValTypeInt32|CValTypeDefer, c: 3}, - - // Int64 - reflect.TypeOf(int64(0)): {i: 7, t: CValTypeInt64, c: 0}, - reflect.TypeOf(new(int64)): {i: 7, t: CValTypeInt64, c: 1}, - reflect.TypeOf([]int64(nil)): {i: 7, t: CValTypeInt64|CValTypeList , c: 2}, - reflect.TypeOf((*func() int64)(nil)).Elem(): {i: 7, t: CValTypeInt64|CValTypeDefer, c: 3}, - - // Uint - reflect.TypeOf(uint(0)): {i: 8, t: CValTypeUint, c: 0}, - reflect.TypeOf(new(uint)): {i: 8, t: CValTypeUint, c: 1}, - reflect.TypeOf([]uint(nil)): {i: 8, t: CValTypeUint|CValTypeList , c: 2}, - reflect.TypeOf((*func() uint )(nil)).Elem(): {i: 8, t: CValTypeUint|CValTypeDefer, c: 3}, - - // Uint8 - // Corregimos para que []uint8 sea bytes, un tipo basico - reflect.TypeOf(uint8(0)): {i: 9, t: CValTypeUint8, c: 0}, - reflect.TypeOf(new(uint8)): {i: 9, t: CValTypeUint8, c: 1}, - reflect.TypeOf([]uint8(nil)): {i:21, t: CValTypeUint8, c: 0}, - reflect.TypeOf((*func() uint8 )(nil)).Elem(): {i: 9, t: CValTypeUint8|CValTypeDefer, c: 3}, - - // Uint16 - reflect.TypeOf(uint16(0)): {i: 10, t: CValTypeUint16, c: 0}, - reflect.TypeOf(new(uint16)): {i: 10, t: CValTypeUint16, c: 1}, - reflect.TypeOf([]uint16(nil)): {i: 10, t: CValTypeUint16|CValTypeList , c: 2}, - reflect.TypeOf((*func() uint16 )(nil)).Elem():{i: 10, t: CValTypeUint16|CValTypeDefer, c: 3}, - - // Uint32 - reflect.TypeOf(uint32(0)): {i: 11, t: CValTypeUint32, c: 0}, - reflect.TypeOf(new(uint32)): {i: 11, t: CValTypeUint32, c: 1}, - reflect.TypeOf([]uint32(nil)): {i: 11, t: CValTypeUint32|CValTypeList , c: 2}, - reflect.TypeOf((*func() uint32 )(nil)).Elem():{i: 11, t: CValTypeUint32|CValTypeDefer, c: 3}, - - // Uint64 - reflect.TypeOf(uint64(0)): {i: 12, t: CValTypeUint64, c: 0}, - reflect.TypeOf(new(uint64)): {i: 12, t: CValTypeUint64, c: 1}, - reflect.TypeOf([]uint64(nil)): {i: 12, t: CValTypeUint64|CValTypeList , c: 2}, - reflect.TypeOf((*func() uint64 )(nil)).Elem():{i: 12, t: CValTypeUint64|CValTypeDefer, c: 3}, - - // Uintptr - reflect.TypeOf(uintptr(0)): {i: 13, t: CValTypeUintptr, c: 0}, - reflect.TypeOf(new(uintptr)): {i: 13, t: CValTypeUintptr, c: 1}, - reflect.TypeOf([]uintptr(nil)): {i: 13, t: CValTypeUintptr|CValTypeList , c: 2}, - reflect.TypeOf((*func() uintptr)(nil)).Elem():{i: 13, t: CValTypeUintptr|CValTypeDefer, c: 3}, - - // Float32 - reflect.TypeOf(float32(0)): {i: 14, t: CValTypeFloat32, c: 0}, - reflect.TypeOf(new(float32)): {i: 14, t: CValTypeFloat32, c: 1}, - reflect.TypeOf([]float32(nil)): {i: 14, t: CValTypeFloat32|CValTypeList , c: 2}, - reflect.TypeOf((*func() float32)(nil)).Elem():{i: 14, t: CValTypeFloat32|CValTypeDefer, c: 3}, - - // Float64 - reflect.TypeOf(float64(0)): {i: 15, t: CValTypeFloat64, c: 0}, - reflect.TypeOf(new(float64)): {i: 15, t: CValTypeFloat64, c: 1}, - reflect.TypeOf([]float64(nil)): {i: 15, t: CValTypeFloat64|CValTypeList , c: 2}, - reflect.TypeOf((*func() float64)(nil)).Elem():{i: 15, t: CValTypeFloat64|CValTypeDefer, c: 3}, - - // Complex64 - reflect.TypeOf(complex64(0)): {i: 16, t: CValTypeComplex64, c: 0}, - reflect.TypeOf(new(complex64)): {i: 16, t: CValTypeComplex64, c: 1}, - reflect.TypeOf([]complex64(nil)): {i: 16, t: CValTypeComplex64|CValTypeList , c: 2}, - reflect.TypeOf((*func()complex64)(nil)).Elem():{i: 16, t: CValTypeComplex64|CValTypeDefer, c: 3}, - - // Complex128 - reflect.TypeOf(complex128(0)): {i: 17, t: CValTypeComplex128, c: 0}, - reflect.TypeOf(new(complex128)): {i: 17, t: CValTypeComplex128, c: 1}, - reflect.TypeOf([]complex128(nil)): {i: 17, t: CValTypeComplex128|CValTypeList , c: 2}, - reflect.TypeOf((*func()complex128)(nil)).Elem():{i: 17, t: CValTypeComplex128|CValTypeDefer, c: 3}, - - /* time's */ - - reflect.TypeOf(time.Duration(0)): { i: 18, t:CValTypeDuration, c:0 }, - reflect.TypeOf(new(time.Duration)): { i: 18, t:CValTypeDuration, c:1 }, - reflect.TypeOf([]time.Duration(nil)): { i: 18, t:CValTypeDuration, c:2 }, - reflect.TypeOf((*func ()time.Duration)(nil)).Elem():{ i : 18, t:CValTypeDuration, c:3 }, - - reflect.TypeOf(time.Time{}): { i: 19, t:CValTypeDate, c:0 }, - reflect.TypeOf(new (time.Time)): { i: 19, t:CValTypeDate, c:1 }, - reflect.TypeOf([]time.Time(nil)): { i: 19, t:CValTypeDate, c:2 }, - reflect.TypeOf((*func ()time.Time)(nil)).Elem():{ i: 19, t:CValTypeDate, c:3 }, - - /* Strings, Bytes, Stack */ - reflect.TypeOf(""): { i: 20, t:CValTypeString, c:0 }, - reflect.TypeOf(new (string)): { i: 20, t:CValTypeString, c:1 }, - reflect.TypeOf([]string(nil)): { i: 20, t:CValTypeString, c:2 }, - reflect.TypeOf((*func ()string)(nil)).Elem(): { i: 20, t:CValTypeString, c:3 }, - - reflect.TypeOf([]uint8(nil)): { i: 21, t:CValTypeBytes, c:0 }, - reflect.TypeOf((*[]uint8)(nil)): { i: 21, t:CValTypeBytes, c:1 }, - reflect.TypeOf([][]uint8(nil)): { i: 21, t:CValTypeBytes, c:2 }, - reflect.TypeOf((*func ()[]uint8)(nil)).Elem(): { i: 21, t:CValTypeBytes, c:3 }, - - reflect.TypeOf(excs.Stack(nil)): { i: 22, t:CValTypeStack, c:0 }, - reflect.TypeOf((*excs.Stack)(nil)): { i: 22, t:CValTypeStack, c:1 }, - reflect.TypeOf([]excs.Stack(nil)): { i: 22, t:CValTypeStack, c:2 }, - reflect.TypeOf((*func ()excs.Stack)(nil)).Elem():{i: 22, t:CValTypeStack, c:3 }, - - reflect.TypeOf(blrs.Baleable(nil)): { i: 23, t:CValTypeBaleable, c:0 }, - reflect.TypeOf((*blrs.Baleable)(nil)): { i: 23, t:CValTypeBaleable, c:1 }, - reflect.TypeOf([]blrs.Baleable(nil)): { i: 23, t:CValTypeBaleable, c:2 }, - reflect.TypeOf((*func ()blrs.Baleable)(nil)).Elem(): { i : 23 , t:CValTypeBaleable, c:3 }, - - - reflect.TypeOf(error(nil)): { i: 24, t:CValTypeError, c:0 }, - reflect.TypeOf((*error)(nil)): { i: 24, t:CValTypeError, c:1 }, - reflect.TypeOf([]error(nil)): { i: 24, t:CValTypeError, c:2 }, - reflect.TypeOf((*func ()error)(nil)).Elem():{ i: 24, t:CValTypeError, c:3 }, - - reflect.TypeOf(CVal{}): { i: 26, t:CValTypeCVal, c:0 }, - reflect.TypeOf((*CVal)(nil)): { i: 26, t:CValTypeCVal, c:1 }, - reflect.TypeOf([]CVal(nil)): { i: 26, t:CValTypeCVal, c:2 }, - reflect.TypeOf((*func ()CVal)(nil)): { i: 26, t:CValTypeCVal, c:3 }, - - - reflect.TypeOf(map[string]CVal(nil)): { i: 27, t:CValTypeCVal, c:0 }, - reflect.TypeOf((*CVal)(nil)): { i: 27, t:CValTypeCVal, c:1 }, - reflect.TypeOf([]CVal(nil)): { i: 27, t:CValTypeCVal, c:2 }, - reflect.TypeOf((*func ()CVal)(nil)).Elem(): { i: 27 , t:CValTypeCVal, c:3 }, - - } -} \ No newline at end of file diff --git a/src/core/cfls/cval_type_infos.go b/src/core/cfls/cval_type_infos.go deleted file mode 100644 index 9c3c4ea..0000000 --- a/src/core/cfls/cval_type_infos.go +++ /dev/null @@ -1,311 +0,0 @@ -// ============================================================================= -// 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 04/06/2025 -// ============================================================================= - -package cfls - -import ( - "core/blrs" - "core/excs" - "math/bits" - "reflect" - "time" -) - -const( - cvalCreatorByValue = iota - cvalCreatorByPointer - cvalCreatorByList - cvalCreatorByDefer - - cValNumCreators = 4 -) - - -type ( - - cValTypeInfos struct { - names [maxCValTypes+1]string - creators [maxCValTypes+1][cValNumCreators]func(any)CVal - } -) - - -func createCValTypeInfos () cValTypeInfos { - is := cValTypeInfos{ - names: [maxCValTypes+1]string{ - /* 0: */ "invalid", - /* 1: */ "any", - /* 2: */ "bool", - /* 3: */ "int", - /* 4: */ "int8", - /* 5: */ "int16", - /* 6: */ "int32", - /* 7: */ "int64", - /* 8: */ "uint", - /* 9: */ "uint8", - /* 10: */ "uint16", - /* 11: */ "uint32", - /* 12: */ "uint64", - /* 13: */ "uintptr", - /* 14: */ "float32", - /* 15: */ "float64", - /* 16: */ "complex64", - /* 17: */ "complex128", - /* 18: */ "duration", - /* 19: */ "date", - /* 20: */ "string", - /* 21: */ "bytes", - /* 22: */ "stack", - /* 23: */ "baleable", - /* 24: */ "error", - /* 25: */ "nil", - /* 26: */ "cval", - /* 27: */ "fields", - /* 28: */ "object", - /* 29: */ "defer", - /* 30: */ "list", - /* 31: */ "map", - /* 32: */ "flag", - }, - creators: [maxCValTypes+1][cValNumCreators]func(any)CVal{ - /* 0: */ createGValCreators[any ](CValTypeInvalid, createCValInvalid), - /* 1: */ createGValCreators[any ](CValTypeAny, CreateCValAny), - /* 2: */ createGValCreators[bool ](CValTypeBool, CreateCValBool), - /* 3: */ createGValCreators[int ](CValTypeInt, CreateCValInt), - /* 4: */ createGValCreators[int8 ](CValTypeInt8, CreateCValInt8), - /* 5: */ createGValCreators[int16 ](CValTypeInt16, CreateCValInt16), - /* 6: */ createGValCreators[int32 ](CValTypeInt32, CreateCValInt32), - /* 7: */ createGValCreators[int64 ](CValTypeInt64, CreateCValInt64), - /* 8: */ createGValCreators[uint ](CValTypeUint, CreateCValUint), - /* - caso en el que []uint debe de establecerse como bytes procedemos a construirlo manualmente - */ - /* 9 :*/ { - func(v any) CVal { return CreateCValUint8 (v.(uint8)) }, - func(v any) CVal { return createGValTypePointer (CValTypeUint8, CreateCValUint8, v.(*uint8)) }, - func(v any) CVal { return createGValTypeList (CValTypeBytes, v.([]uint8)) }, - func(v any) CVal { return createGValTypeDefer (CValTypeDefer|CValTypeUint8, v.(func() uint8))}, - }, - - /* 10:*/ createGValCreators[uint16 ](CValTypeUint16, CreateCValUint16), - /* 11:*/ createGValCreators[uint32 ](CValTypeUint32, CreateCValUint32), - /* 12:*/ createGValCreators[uint64 ](CValTypeUint64, CreateCValUint64), - /* 13:*/ createGValCreators[uintptr ](CValTypeUintptr, CreateCValUintptr), - - /* 14:*/ createGValCreators[float32 ](CValTypeFloat32, CreateCValFloat32), - /* 15:*/ createGValCreators[float64 ](CValTypeFloat64, CreateCValFloat64), - /* 16:*/ createGValCreators[complex64 ](CValTypeComplex64,CreateCValComplex64), - /* 17:*/ createGValCreators[complex128 ](CValTypeComplex128,CreateCValComplex128), - - /* 18:*/ createGValCreators[time.Duration](CValTypeDuration,CreateCValDuration), - /* 19:*/ createGValCreators[time.Time ](CValTypeDate, CreateCValDate), - - /* 20:*/ createGValCreators[string ](CValTypeString, CreateCValString), - /* 21:*/ createGValCreators[[]uint8 ](CValTypeBytes, CreateCValBytes), - /* 22:*/ createGValCreators[excs.Stack ](CValTypeStack, CreateCValStack), - /* 23:*/ createGValCreators[blrs.Baleable](CValTypeBaleable,CreateCValBaleable), - /* 24:*/ createGValCreators[error ](CValTypeError, CreateCValError), - /* 25:*/ createGValCreators[any ](CValTypeNil, CreateCValNil), - /* 26:*/ createGValCreators[CVal ](CValTypeCVal, CreateCValCVal), - /* 27:*/ createGValCreators[any ](CValTypeCFields, CreateCValFields), - /* 28:*/ createGValCreators[any ](CValTypeObject, CreateCValObject), - /* 29:*/ createGValCreators[any ](CValTypeDefer, CreateCValDefer), - /* 30:*/ createGValCreators[any ](CValTypeList, CreateCValList), - /* 31:*/ createGValCreators[any ](CValTypeMap, CreateCValMap), - /* 32:*/ createGValCreators[any ](CValTypeObject, createCValInvalid), - }, - } - - - - return is -} - -func (i cValTypeInfos) getCValTypeName (cvalType CValType) string { - if cvalType.IsComposite() { - if cvalType.IsDefer () { - return "defer|" + cvalType.BaseType().String() - } - if cvalType.IsList () { - return "list|" + cvalType.BaseType().String() - } - if cvalType.IsFields() { - return "fields|"+ cvalType.BaseType().String() - } - if cvalType.IsMap () { - k, v := cvalType.MapType() - return "map@" + k.String() + "|" + v.String() - } - } - return i.names[i.getCValTypeIndex(cvalType)] -} - - -func (_ cValTypeInfos) getCValTypeIndex(cvalType CValType) int { - if cvalType == 0 { - return 0 - } - return bits.TrailingZeros32(uint32(cvalType))+1 -} - -func (i cValTypeInfos) getCreator (value any) (f func(v any) CVal) { - switch value.(type) { - /* Valores simples */ - case any : f = i.creators[ 1/* CValTypeAny.Index() */][cvalCreatorByValue] - case bool : f = i.creators[ 2/* CValTypeBool.Index() */][cvalCreatorByValue] - case int : f = i.creators[ 3/* CValTypeInt.Index() */][cvalCreatorByValue] - case int8 : f = i.creators[ 4/* CValTypeInt8.Index() */][cvalCreatorByValue] - case int16 : f = i.creators[ 5/* CValTypeInt16.Index() */][cvalCreatorByValue] - case int32 : f = i.creators[ 6/* CValTypeInt32.Index() */][cvalCreatorByValue] - case int64 : f = i.creators[ 7/* CValTypeInt64.Index() */][cvalCreatorByValue] - case uint : f = i.creators[ 8/* CValTypeUint.Index() */][cvalCreatorByValue] - case uint8 : f = i.creators[ 9/* CValTypeUint8.Index() */][cvalCreatorByValue] - case uint16 : f = i.creators[10/* CValTypeUint16.Index() */][cvalCreatorByValue] - case uint32 : f = i.creators[11/* CValTypeUint32.Index() */][cvalCreatorByValue] - case uint64 : f = i.creators[12/* CValTypeUint64.Index() */][cvalCreatorByValue] - case uintptr : f = i.creators[13/* CValTypeUintptr.Index() */][cvalCreatorByValue] - case float32 : f = i.creators[14/* CValTypeFloat32.Index() */][cvalCreatorByValue] - case float64 : f = i.creators[15/* CValTypeFloat64.Index() */][cvalCreatorByValue] - case complex64 : f = i.creators[16/* CValTypeComplex64.Index() */][cvalCreatorByValue] - case complex128 : f = i.creators[17/* CValTypeComplex128.Index()*/][cvalCreatorByValue] - case time.Duration : f = i.creators[18/* CValTypeDuration.Index() */][cvalCreatorByValue] - case time.Time : f = i.creators[19/* CValTypeDate.Index() */][cvalCreatorByValue] - case string : f = i.creators[20/* CValTypeString.Index() */][cvalCreatorByValue] - case []uint8 : f = i.creators[21/* CValTypeBytes.Index() */][cvalCreatorByValue] - case excs.Stack : f = i.creators[22/* CValTypeStack.Index() */][cvalCreatorByValue] - case blrs.Baleable : f = i.creators[23/* CValTypeBaleable.Index() */][cvalCreatorByValue] - case error : f = i.creators[24/* CValTypeError.Index() */][cvalCreatorByValue] - case CVal : f = i.creators[26/* CValTypeCVal.Index() */][cvalCreatorByValue] - case CFields : f = i.creators[27 /* CValTypeCFields.Index() */][cvalCreatorByValue] - - /* Valores Listas */ - case []any : f = i.creators[ 1/* CValTypeAny.Index() */][cvalCreatorByList] - case []bool : f = i.creators[ 2/* CValTypeBool.Index() */][cvalCreatorByList] - case []int : f = i.creators[ 3/* CValTypeInt.Index() */][cvalCreatorByList] - case []int8 : f = i.creators[ 4/* CValTypeInt8.Index() */][cvalCreatorByList] - case []int16 : f = i.creators[ 5/* CValTypeInt16.Index() */][cvalCreatorByList] - case []int32 : f = i.creators[ 6/* CValTypeInt32.Index() */][cvalCreatorByList] - case []int64 : f = i.creators[ 7/* CValTypeInt64.Index() */][cvalCreatorByList] - case []uint : f = i.creators[ 8/* CValTypeUint.Index() */][cvalCreatorByList] - // ya establecido como tipo base - //case []uint8 : f = i.creators[ 9/* CValTypeUint8.Index() */].listCreator - // - case []uint16 : f = i.creators[10/* CValTypeUint16.Index() */][cvalCreatorByList] - case []uint32 : f = i.creators[11/* CValTypeUint32.Index() */][cvalCreatorByList] - case []uint64 : f = i.creators[12/* CValTypeUint64.Index() */][cvalCreatorByList] - case []uintptr : f = i.creators[13/* CValTypeUintptr.Index() */][cvalCreatorByList] - case []float32 : f = i.creators[14/* CValTypeFloat32.Index() */][cvalCreatorByList] - case []float64 : f = i.creators[15/* CValTypeFloat64.Index() */][cvalCreatorByList] - case []complex64 : f = i.creators[16/* CValTypeComplex64.Index() */][cvalCreatorByList] - case []complex128 : f = i.creators[17/* CValTypeComplex128.Index()*/][cvalCreatorByList] - case []time.Duration: f = i.creators[18/* CValTypeDuration.Index() */][cvalCreatorByList] - case []time.Time : f = i.creators[19/* CValTypeDate.Index() */][cvalCreatorByList] - case []string : f = i.creators[20/* CValTypeString.Index() */][cvalCreatorByList] - case []excs.Stack : f = i.creators[22/* CValTypeStack.Index() */][cvalCreatorByList] - case []blrs.Baleable: f = i.creators[23/* CValTypeBaleable.Index() */][cvalCreatorByList] - case []error : f = i.creators[24/* CValTypeError.Index() */][cvalCreatorByList] - case []CVal : f = i.creators[26/* CValTypeCVal.Index() */][cvalCreatorByList] - case []CFields : f = i.creators[27 /* CValTypeCFields.Index() */][cvalCreatorByList] - - /* Valores pasados por punteros */ - case *any : f = i.creators[ 1/* CValTypeAny.Index() */][cvalCreatorByPointer] - case *bool : f = i.creators[ 2/* CValTypeBool.Index() */][cvalCreatorByPointer] - case *int : f = i.creators[ 3/* CValTypeInt.Index() */][cvalCreatorByPointer] - case *int8 : f = i.creators[ 4/* CValTypeInt8.Index() */][cvalCreatorByPointer] - case *int16 : f = i.creators[ 5/* CValTypeInt16.Index() */][cvalCreatorByPointer] - case *int32 : f = i.creators[ 6/* CValTypeInt32.Index() */][cvalCreatorByPointer] - case *int64 : f = i.creators[ 7/* CValTypeInt64.Index() */][cvalCreatorByPointer] - case *uint : f = i.creators[ 8/* CValTypeUint.Index() */][cvalCreatorByPointer] - case *uint8 : f = i.creators[ 9/* CValTypeUint8.Index() */][cvalCreatorByPointer] - case *uint16 : f = i.creators[10/* CValTypeUint16.Index() */][cvalCreatorByPointer] - case *uint32 : f = i.creators[11/* CValTypeUint32.Index() */][cvalCreatorByPointer] - case *uint64 : f = i.creators[12/* CValTypeUint64.Index() */][cvalCreatorByPointer] - case *uintptr : f = i.creators[13/* CValTypeUintptr.Index() */][cvalCreatorByPointer] - case *float32 : f = i.creators[14/* CValTypeFloat32.Index() */][cvalCreatorByPointer] - case *float64 : f = i.creators[15/* CValTypeFloat64.Index() */][cvalCreatorByPointer] - case *complex64 : f = i.creators[16/* CValTypeComplex64.Index() */][cvalCreatorByPointer] - case *complex128 : f = i.creators[17/* CValTypeComplex128.Index()*/][cvalCreatorByPointer] - case *time.Duration : f = i.creators[18/* CValTypeDuration.Index() */][cvalCreatorByPointer] - case *time.Time : f = i.creators[19/* CValTypeDate.Index() */][cvalCreatorByPointer] - case *string : f = i.creators[20/* CValTypeString.Index() */][cvalCreatorByPointer] - case *[]uint8 : f = i.creators[21/* CValTypeBytes.Index() */][cvalCreatorByPointer] - case *excs.Stack : f = i.creators[22/* CValTypeStack.Index() */][cvalCreatorByPointer] - case *blrs.Baleable : f = i.creators[23/* CValTypeBaleable.Index() */][cvalCreatorByPointer] - case *error : f = i.creators[24/* CValTypeError.Index() */][cvalCreatorByPointer] - case *CVal : f = i.creators[26/* CValTypeCVal.Index() */][cvalCreatorByPointer] - case *CFields : f = i.creators[27 /* CValTypeCFields.Index() */][cvalCreatorByPointer] - - /* Valores pasados por functions defers */ - case func()any : f = i.creators[ 1/* CValTypeAny.Index() */][cvalCreatorByDefer] - case func()bool : f = i.creators[ 2/* CValTypeBool.Index() */][cvalCreatorByDefer] - case func()int : f = i.creators[ 3/* CValTypeInt.Index() */][cvalCreatorByDefer] - case func()int8 : f = i.creators[ 4/* CValTypeInt8.Index() */][cvalCreatorByDefer] - case func()int16 : f = i.creators[ 5/* CValTypeInt16.Index() */][cvalCreatorByDefer] - case func()int32 : f = i.creators[ 6/* CValTypeInt32.Index() */][cvalCreatorByDefer] - case func()int64 : f = i.creators[ 7/* CValTypeInt64.Index() */][cvalCreatorByDefer] - case func()uint : f = i.creators[ 8/* CValTypeUint.Index() */][cvalCreatorByDefer] - case func()uint8 : f = i.creators[ 9/* CValTypeUint8.Index() */][cvalCreatorByDefer] - case func()uint16 : f = i.creators[10/* CValTypeUint16.Index() */][cvalCreatorByDefer] - case func()uint32 : f = i.creators[11/* CValTypeUint32.Index() */][cvalCreatorByDefer] - case func()uint64 : f = i.creators[12/* CValTypeUint64.Index() */][cvalCreatorByDefer] - case func()uintptr : f = i.creators[13/* CValTypeUintptr.Index() */][cvalCreatorByDefer] - case func()float32 : f = i.creators[14/* CValTypeFloat32.Index() */][cvalCreatorByDefer] - case func()float64 : f = i.creators[15/* CValTypeFloat64.Index() */][cvalCreatorByDefer] - case func()complex64 : f = i.creators[16/* CValTypeComplex64.Index() */][cvalCreatorByDefer] - case func()complex128 : f = i.creators[17/* CValTypeComplex128.Index()*/][cvalCreatorByDefer] - case func()time.Duration: f = i.creators[18/* CValTypeDuration.Index() */][cvalCreatorByDefer] - case func()time.Time : f = i.creators[19/* CValTypeDate.Index() */][cvalCreatorByDefer] - case func()string : f = i.creators[20/* CValTypeString.Index() */][cvalCreatorByDefer] - case func()[]uint8 : f = i.creators[21/* CValTypeBytes.Index() */][cvalCreatorByDefer] - case func()excs.Stack : f = i.creators[22/* CValTypeStack.Index() */][cvalCreatorByDefer] - case func()blrs.Baleable: f = i.creators[23/* CValTypeBaleable.Index() */][cvalCreatorByDefer] - case func()error : f = i.creators[24/* CValTypeError.Index() */][cvalCreatorByDefer] - case func()CVal : f = i.creators[26/* CValTypeCVal.Index() */][cvalCreatorByDefer] - case func()CFields : f = i.creators[27/* CValTypeCFields.Index() */][cvalCreatorByDefer] - - default: - - rv := reflect.ValueOf(value) - - - } - - return -} - - - - -func createGValCreators [T any] (valType CValType, createFnc func(value T) CVal) [cValNumCreators]func(any)CVal { - return [cValNumCreators]func(any)CVal { - func(v any) CVal { return createFnc(v.(T)) }, - func(v any) CVal { return createGValTypePointer(valType,createFnc,v.(*T))}, - func(v any) CVal { return createGValTypeList (CValTypeList |valType,v.([]T)) }, - func(v any) CVal { return createGValTypeDefer(CValTypeDefer|valType,v.(func() T)) }, - } -} \ No newline at end of file diff --git a/src/core/cfls/cvalue_state.go b/src/core/cfls/cvalue_state.go deleted file mode 100644 index 05bc841..0000000 --- a/src/core/cfls/cvalue_state.go +++ /dev/null @@ -1,63 +0,0 @@ -// ============================================================================= -// 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 02/06/2025 -// ============================================================================= - -package cfls - - -const ( - - cValStateInvalid CValState = 1 << iota // El valor almacenado es un valor invalido - cValStateNil // Indica que el valor es nulo - cValStateZero // Indica que el valor tiene valor 0 - cValStateReflected // Indica que el valor guardado es un value.reflect - cValStateShort // Indica que el valor es la versión corta del valor, por ejemplo: los dates - cValStateSensitive // Indica que el valor es delicado, por ejemplo no mostrar o no serializar - cValStateEncoded // Indica que el valor está codificado - cValStateError // Indica que el valor no ha podido ser establecido por un error que esta representado en el - // valor - - cValStateNone CValState = 0 - - cValStateOps CValState = cValStateEncoded|cValStateSensitive -) - - -type CValState uint8 - - -func (s CValState) HasValueInvalid () bool { return s&cValStateInvalid != 0 } -func (s CValState) HasValueNil () bool { return s&cValStateNil != 0 } -func (s CValState) HasValueZero () bool { return s&cValStateZero != 0 } -func (s CValState) HasValueReflected() bool { return s&cValStateReflected != 0 } -func (s CValState) HasValueShort () bool { return s&cValStateShort != 0 } -func (s CValState) HasValueSensitive() bool { return s&cValStateSensitive != 0 } -func (s CValState) HasValueEncoded () bool { return s&cValStateEncoded != 0 } -func (s CValState) HasValueError () bool { return s&cValStateError != 0 } - - -func (s CValState) setOption (options CValState) CValState { return s|(options&cValStateOps) } \ No newline at end of file diff --git a/src/core/cflss/a.go b/src/core/cflss/a.go deleted file mode 100644 index bac67e4..0000000 --- a/src/core/cflss/a.go +++ /dev/null @@ -1,50 +0,0 @@ -// ============================================================================= -// 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 05/06/2025 -// ============================================================================= - -package cflss - -var ( - - G = struct { - - TypeInfos *CValueTypeInfos - }{ - - - TypeInfos: newCValueTypeInfos(), - } - - - E = struct { - InvalidCValueReflected, - InvalidCValueForType string - }{ - InvalidCValueReflected : "::invalid_reflect_value", - InvalidCValueForType : "::invalid_value_for_type", - } -) \ No newline at end of file diff --git a/src/core/cflss/cvalue.go b/src/core/cflss/cvalue.go deleted file mode 100644 index 6d4cb8b..0000000 --- a/src/core/cflss/cvalue.go +++ /dev/null @@ -1,674 +0,0 @@ -// ============================================================================= -// 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 04/06/2025 -// ============================================================================= - -package cflss - -import ( - "core/blrs" - "core/excs" - "math" - "reflect" - "time" -) - -type CValue struct { - _ [0]func() - - vType CValueType - vState CValueState - intVal int64 - strVal string - anyVal any -} - - - -func CreateCValue(value any) CValue { - return G.TypeInfos.CreateCValue(value) -} - - -func createCValueAny (value any ) CValue { - if value == nil { return CValue{ vType: CValueTypeAny, vState: cValueStateNil|cValueStateZero } } - return CValue{ vType: CValueTypeAny, anyVal: value } -} - - -func CreateCValueBool (value bool ) CValue { - if !value { return CValue{ vType: CValueTypeInt, vState: cValueStateZero } } - return CValue{ vType: CValueTypeInt, vState: cValueStateZero, intVal: 1} -} - - - -// Int's - -func CreateCValueInt (value int ) CValue { - if value == 0 { return CValue{ vType: CValueTypeInt, vState: cValueStateZero } } - return CValue{ vType: CValueTypeInt, intVal: int64(value) } -} - -func CreateCValueInt8 (value int8 ) CValue { - if value == 0 { return CValue{ vType: CValueTypeInt8, vState: cValueStateZero } } - return CValue{ vType: CValueTypeInt8, intVal: int64(value) } -} - -func CreateCValueInt16 (value int16 ) CValue { - if value == 0 { return CValue{ vType: CValueTypeInt16, vState: cValueStateZero } } - return CValue{ vType: CValueTypeInt16, intVal: int64(value) } -} - -func CreateCValueInt32 (value int32 ) CValue { - if value == 0 { return CValue{ vType: CValueTypeInt32, vState: cValueStateZero } } - return CValue{ vType: CValueTypeInt32, intVal: int64(value) } -} - -func CreateCValueInt64 (value int64 ) CValue { - if value == 0 { return CValue{ vType: CValueTypeInt64, vState: cValueStateZero } } - return CValue{ vType: CValueTypeInt64, intVal: value } -} - - - -// Uint's - -func CreateCValueUint (value uint ) CValue { - if value == 0 { return CValue{ vType: CValueTypeUint, vState: cValueStateZero } } - return CValue{ vType: CValueTypeUint, intVal: int64(value) } -} - -func CreateCValueUint8 (value uint8 ) CValue { - if value == 0 { return CValue{ vType: CValueTypeUint8, vState: cValueStateZero } } - return CValue{ vType: CValueTypeUint8, intVal: int64(value) } -} - -func CreateCValueUint16 (value uint16 ) CValue { - if value == 0 { return CValue{ vType: CValueTypeUint16, vState: cValueStateZero } } - return CValue{ vType: CValueTypeUint16, intVal: int64(value) } -} - -func CreateCValueUint32 (value uint32 ) CValue { - if value == 0 { return CValue{ vType: CValueTypeUint32, vState: cValueStateZero } } - return CValue{ vType: CValueTypeUint32, intVal: int64(value) } -} - -func CreateCValueUint64 (value uint64 ) CValue { - if value == 0 { return CValue{ vType: CValueTypeUint64, vState: cValueStateZero } } - return CValue{ vType: CValueTypeUint64, intVal: int64(value) } -} - - -func CreateCValueUintptr (value uintptr ) CValue { - if value == 0 { return CValue{ vType: CValueTypeUintptr, vState: cValueStateZero } } - return CValue{ vType: CValueTypeUintptr, intVal: int64(value) } -} - - -// Floats - -func CreateCValueFloat32 (value float32 ) CValue { - if value == 0.0 { // Comprobación directa para el valor cero - return CValue{vType: CValueTypeFloat32, vState: cValueStateZero} - } - return CValue{vType: CValueTypeFloat32, intVal: int64(math.Float32bits(value))} -} - -func CreateCValueFloat64 (value float64 ) CValue { - if value == 0.0 { // Comprobación directa para el valor cero - return CValue{vType: CValueTypeFloat64, vState: cValueStateZero} - } - return CValue{vType: CValueTypeFloat64, intVal: int64(math.Float64bits(value))} -} - -func CreateCValueComplex64 (value complex64 ) CValue { - if value == 0 { // Comprobación directa para el valor cero - return CValue{vType: CValueTypeComplex64, vState: cValueStateZero } - } - return CValue{vType: CValueTypeComplex64, anyVal: value} -} - -func CreateCValueComplex128 (value complex128) CValue { - if value == 0 { // Comprobación directa para el valor cero - return CValue{vType: CValueTypeComplex128, vState: cValueStateZero } - } - return CValue{vType: CValueTypeComplex128, anyVal: value} -} - - -func CreateCValueDuration (value Duration ) CValue { - if value == 0 { - return CValue{vType: CValueTypeDuration, vState: cValueStateZero} - } - return CValue{vType: CValueTypeDuration, intVal: int64(value)} -} - -func CreateCValueDate (value Date ) CValue { - if value.IsZero() { // Comprobación directa para el valor cero - return CValue{vType: CValueTypeDate, vState: cValueStateZero} - } - if value.After(G.TypeInfos.minTime) && value.Before(G.TypeInfos.maxTime) { - return CValue{vType: CValueTypeDate, vState: cValueStateShort,intVal: value.UnixNano(), anyVal: value.Location()} - } - return CValue{vType: CValueTypeDate, anyVal: value } -} - -func CreateCValueString (value string ) CValue { - if value == "" { // Comprobación directa para el valor cero - return CValue{vType: CValueTypeString, vState: cValueStateZero} - } - return CValue{vType: CValueTypeString, strVal: value} -} - -func CreateCValueBytes (value []uint8 ) CValue { - l := len(value) - if l == 0 { - if value == nil { - return CValue{vType: CValueTypeBytes, vState: cValueStateNil} - } else { - return CValue{vType: CValueTypeBytes, vState: cValueStateZero,anyVal: value} - } - } - return CValue{vType: CValueTypeBytes, anyVal: value, intVal: int64(l)} -} - - -func CreateCValueStack (value Stack ) CValue { - l := len(value) - if l == 0 { - if value == nil { - return CValue{vType: CValueTypeStack, vState: cValueStateNil} - } else { - return CValue{vType: CValueTypeStack, vState: cValueStateZero,anyVal: value} - } - } - return CValue{vType: CValueTypeStack, anyVal: value, intVal: int64(l)} -} - - -func CreateCValueBaleable (value Baleable ) CValue { - if value == nil { - return CValue{vType: CValueTypeBaleable, vState: cValueStateNil} - } - return CValue{ vType: CValueTypeBaleable, anyVal: value } -} - -func CreateCValueError (value error ) CValue { - if value == nil { - return CValue{vType: CValueTypeError, vState: cValueStateNil} - } - return CValue{ vType: CValueTypeError, anyVal: value } -} - -func CreateCValueNil (_ any ) CValue { return CValue{ vType: CValueTypeNil, vState: cValueStateNil } } - -func createCValueCValue (value CValue ) CValue { return CValue{vType: CValueTypeCValue, anyVal: value } } - -func createCValueCField (value CField ) CValue { return CValue{vType: CValueTypeCField, anyVal: value} } - - -func createCValueObject (value any ) CValue { - return createCValueReflected(value,reflect.ValueOf(value),CValueTypeObject, true) } - - -func CreateCValueList (value any) CValue { - return createCValueReflected (value,reflect.ValueOf(value),CValueTypeList , true) -} - -func CreateCValueDefer (value any) CValue { - return createCValueReflected (value,reflect.ValueOf(value),CValueTypeDefer ,true) -} - -func CreateCValueMap (value any) CValue { - return createCValueReflected (value,reflect.ValueOf(value),CValueTypeMap , true) -} - -func createCValueInvalid (value any) CValue { - return CValue{ vType: CValueTypeInvalid, anyVal: value} -} - -func createCValueWithInvalidError (value any, vtype CValueType, vstate CValueState, er string) CValue { - return CValue{ - vType : CValueTypeInvalid, - vState: cValueStateInvalid|cValueStateError|vstate, - intVal: int64(vtype), - anyVal: value, - strVal: er, - } -} - - - - -func (v CValue) Type () CValueType { return v.vType } - -func (v CValue) State() CValueState { return v.vState } - - - - -func (v CValue) AsBool () (bool,bool){ - if v.vType != CValueTypeBool { - return false,false - } - if v.vState.HasNilOrZero() { - return false,true - } - if v.vType.IsDefer() { - return (v.anyVal.(func()bool))(),true - } - return v.intVal != 0,true -} - - - -func (v CValue) AsInt () (int,bool){ - if v.vType != CValueTypeInt { - return 0,false - } - if v.vState.HasNilOrZero() { - return 0,true - } - if v.vType.IsDefer() { - return (v.anyVal.(func()int))(),true - } - return int(v.intVal),true -} - -func (v CValue) AsInts () ([]int,bool){ - if v.vType != CValueTypeInt|CValueTypeList { - return nil,false - } - if v.vState.HasValueNil() { - return nil,true - } - return v.anyVal.([]int),true -} - - -func (v CValue) AsInt8 () (int8,bool){ - if v.vType != CValueTypeInt8 { - return 0,false - } - if v.vState.HasNilOrZero() { - return 0,true - } - if v.vType.IsDefer() { - return (v.anyVal.(func()int8))(),true - } - return int8(v.intVal),true -} - -func (v CValue) AsInt16 () (int16,bool){ - if v.vType != CValueTypeInt16 { - return 0,false - } - if v.vState.HasNilOrZero() { - return 0,true - } - if v.vType.IsDefer() { - return (v.anyVal.(func()int16))(),true - } - return int16(v.intVal),true -} - -func (v CValue) AsInt32 () (int32,bool){ - if v.vType != CValueTypeInt32 { - return 0,false - } - if v.vState.HasNilOrZero() { - return 0,true - } - if v.vType.IsDefer() { - return (v.anyVal.(func()int32))(),true - } - return int32(v.intVal),true -} - -func (v CValue) AsInt64 () (int64,bool){ - if v.vType != CValueTypeInt64 { - return 0,false - } - if v.vState.HasNilOrZero() { - return 0,true - } - if v.vType.IsDefer() { - return (v.anyVal.(func()int64))(),true - } - return v.intVal,true -} - - -func (v CValue) AsUint () (uint,bool){ - if v.vType != CValueTypeUint { - return 0,false - } - if v.vState.HasNilOrZero() { - return 0,true - } - if v.vType.IsDefer() { - return (v.anyVal.(func()uint))(),true - } - return uint(v.intVal),true -} - -func (v CValue) AsUint8 () (uint8,bool){ - if v.vType != CValueTypeUint8 { - return 0,false - } - if v.vState.HasNilOrZero() { - return 0,true - } - if v.vType.IsDefer() { - return (v.anyVal.(func()uint8))(),true - } - return uint8(v.intVal),true -} - -func (v CValue) AsUint16 () (uint16,bool){ - if v.vType != CValueTypeUint16 { - return 0,false - } - if v.vState.HasNilOrZero() { - return 0,true - } - if v.vType.IsDefer() { - return (v.anyVal.(func()uint16))(),true - } - return uint16(v.intVal),true -} - -func (v CValue) AsUint32 () (uint32,bool){ - if v.vType != CValueTypeUint32 { - return 0,false - } - if v.vState.HasNilOrZero() { - return 0,true - } - if v.vType.IsDefer() { - return (v.anyVal.(func()uint32))(),true - } - return uint32(v.intVal),true -} - -func (v CValue) AsUint64 () (uint64,bool){ - if v.vType != CValueTypeUint64 { - return 0,false - } - if v.vState.HasNilOrZero() { - return 0,true - } - if v.vType.IsDefer() { - return (v.anyVal.(func()uint64))(),true - } - return uint64(v.intVal),true -} - - -func (v CValue) AsUintptr() (uintptr,bool){ - if v.vType != CValueTypeUintptr { - return 0,false - } - if v.vState.HasNilOrZero() { - return 0,true - } - if v.vType.IsDefer() { - return (v.anyVal.(func()uintptr))(),true - } - return uintptr(v.intVal),true -} - - -func (v CValue) AsFloat32() (float32,bool){ - if v.vType != CValueTypeFloat32 { - return 0,false - } - if v.vState.HasNilOrZero() { - return 0,true - } - if v.vType.IsDefer() { - return (v.anyVal.(func()float32))(),true - } - return math.Float32frombits(uint32(v.intVal)), true -} - -func (v CValue) AsFloat64() (float64,bool){ - if v.vType != CValueTypeFloat64 { - return 0,false - } - if v.vState.HasNilOrZero() { - return 0,true - } - if v.vType.IsDefer() { - return (v.anyVal.(func()float64))(),true - } - return math.Float64frombits(uint64(v.intVal)), true -} - -func (v CValue) AsComplex64 () (complex64,bool){ - if v.vType != CValueTypeComplex64 { - return 0,false - } - if v.vState.HasNilOrZero() { - return 0,true - } - if v.vType.IsDefer() { - return (v.anyVal.(func()complex64))(),true - } - return v.anyVal.(complex64),true -} - -func (v CValue) AsComplex128() (complex128,bool){ - if v.vType != CValueTypeComplex128 { - return 0,false - } - if v.vState.HasNilOrZero() { - return 0,true - } - if v.vType.IsDefer() { - return (v.anyVal.(func()complex128))(),true - } - return v.anyVal.(complex128),true -} - - - -func (v CValue) AsDuration() (Duration,bool){ - if v.vType != CValueTypeDuration { - return 0,false - } - if v.vState.HasNilOrZero() { - return 0,true - } - if v.vType.IsDefer() { - return (v.anyVal.(func()Duration))(),true - } - return time.Duration(v.intVal),true -} - -func (v CValue) AsDate () (Date,bool){ - if v.vType != CValueTypeDate { - return time.Time{},false - } - if v.vState.HasNilOrZero() { - return time.Time{}, true - } - if v.vType.IsDefer() { - return (v.anyVal.(func()Date))(),true - } - if v.vState.HasValueShort() { - // version corta del date - return time.Unix(0, v.intVal).In(v.anyVal.(*time.Location)), true - } - return v.anyVal.(time.Time),true -} - - -func (v CValue) AsString () (string,bool){ - if v.vType != CValueTypeString { - return "", false - } - if v.vState.HasNilOrZero() { - return "", true - } - if v.vType.IsDefer() { - return v.anyVal.(string), true - } - return v.strVal,true -} - -func (v CValue) AsStrings () ([]string,bool){ - if v.vType != CValueTypeList|CValueTypeString { - return nil,false - } - if v.vState.HasValueNil() { - return nil,true - } - return v.anyVal.([]string),true -} - - -func (v CValue) AsBytes () ([]byte,bool){ - if v.vType != CValueTypeBytes { - return nil, false - } - if v.vState.HasValueNil() { - return []byte(nil),true - } - if v.vType.IsDefer() { - return v.anyVal.([]byte),true - } - return v.anyVal.([]byte),true -} - - -func (v CValue) AsStack () (Stack,bool){ - if v.vType != CValueTypeStack { - return nil, false - } - if v.vState.HasValueNil() { - return Stack(nil),true - } - if v.vType.IsDefer() { - return v.anyVal.(Stack),true - } - return v.anyVal.(excs.Stack),true -} - - -func (v CValue) AsBaleable() (blrs.Baleable,bool){ - if v.vType != CValueTypeBaleable { - return nil, false - } - if v.vState.HasValueNil() { - return blrs.Baleable(nil),true - } - if v.vType.IsDefer() { - return v.anyVal.(blrs.Baleable),true - } - return v.anyVal.(blrs.Baleable),true -} - - -func (v CValue) AsError () (error,bool){ - if v.vType != CValueTypeError { - return nil, false - } - if v.vState.HasValueNil() { - return error(nil),true - } - if v.vType.IsDefer() { - return v.anyVal.(error),true - } - return v.anyVal.(error),true -} - - -func (v CValue) AsCValue () (CValue,bool) { - if v.vType != CValueTypeCValue { - return CValue{}, false - } - if v.vType.IsDefer() { - return (v.anyVal.(func()CValue))(), true - } - return v.anyVal.(CValue), true -} - -func (v CValue) AsCField () (CField,bool) { - if v.vType != CValueTypeCField { - return CField{}, false - } - if v.vType.IsDefer() { - return (v.anyVal.(func()CField))(), true - } - return v.anyVal.(CField), true -} - -func (v CValue) AsCFields() ([]CField,bool) { - if v.vType != CValueTypeCField|CValueTypeList { - return nil, false - } - if v.vState.HasValueNil() { - return nil, false - } - if v.vType.IsDefer() { - return v.anyVal.([]CField), true - } - return v.anyVal.([]CField), true -} - - - -func (v CValue) AsObject () (any,bool) { - if v.vType != CValueTypeObject { - return nil, false - } - if v.vType.IsDefer() { - return v.anyVal.(any),true - } - return v.anyVal,true -} - -func (v CValue) AsList () (any,bool) { - if v.vType != CValueTypeList { - return nil, false - } - if v.vType.IsDefer() { - return v.anyVal.(any),true - } - return v.anyVal,true -} - -func (v CValue) AsMap () (any,bool) { - if v.vType != CValueTypeMap { - return nil, false - } - if v.vType.IsDefer() { - return v.anyVal.(any),true - } - return v.anyVal,true -} diff --git a/src/core/cflss/cvalue_state.go b/src/core/cflss/cvalue_state.go deleted file mode 100644 index 8963162..0000000 --- a/src/core/cflss/cvalue_state.go +++ /dev/null @@ -1,81 +0,0 @@ -// ============================================================================= -// 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 04/06/2025 -// ============================================================================= - -package cflss - -import "strings" - -const ( - - cValueStateInvalid CValueState = 1 << iota // El valor almacenado es un valor invalido - cValueStateNil // Indica que el valor es nulo - cValueStateZero // Indica que el valor tiene valor 0 - cValueStateReflected // Indica que el valor guardado es un value.reflect - cValueStateShort // Indica que el valor es la versión corta del valor, por ejemplo: los dates - cValueStateSensitive // Indica que el valor es delicado, por ejemplo no mostrar o no serializar - cValueStateEncoded // Indica que el valor está codificado - cValueStateError // Indica que el valor no ha podido ser establecido por un error que esta representado en el - // valor - - cValueStateNone CValueState = 0 - - cValueStateOps CValueState = cValueStateEncoded|cValueStateSensitive -) - - -type CValueState uint8 - - -func (s CValueState) HasValueInvalid () bool { return s&cValueStateInvalid != 0 } -func (s CValueState) HasValueNil () bool { return s&cValueStateNil != 0 } -func (s CValueState) HasValueZero () bool { return s&cValueStateZero != 0 } -func (s CValueState) HasValueReflected() bool { return s&cValueStateReflected != 0 } -func (s CValueState) HasValueShort () bool { return s&cValueStateShort != 0 } -func (s CValueState) HasValueSensitive() bool { return s&cValueStateSensitive != 0 } -func (s CValueState) HasValueEncoded () bool { return s&cValueStateEncoded != 0 } -func (s CValueState) HasValueError () bool { return s&cValueStateError != 0 } - -func (s CValueState) HasNilOrZero () bool { return s&(cValueStateZero|cValueStateNil) != 0 } - -func (s CValueState) setOption (options CValueState) CValueState { return s|(options&cValueStateOps) } - - -func (s CValueState) String() string { - states := [...]string{"invalid","nil","zero","reflected","short","sensitive","encoded","error"} - c := make([]string,0,4) - for i:=0; i<7; i++ { - if s& (1< 0 { - return CValue{mType: CValueTypeBytes, anyVal: value} - } - var vs CValueState - if value == nil { - vs = cValueStateNil - } else { - vs = cValueStateZero +func CreateCValueBytes (value []uint8 ) CValue { + l := len(value) + if l == 0 { + if value == nil { + return CValue{vType: CValueTypeBytes, vState: cValueStateNil} + } else { + return CValue{vType: CValueTypeBytes, vState: cValueStateZero,anyVal: value} + } } - return CValue{mType: CValueTypeBytes, mState: vs} + return CValue{vType: CValueTypeBytes, anyVal: value, intVal: int64(l)} } -func CreateCValueStack(value excs.Stack) CValue { - if len(value) > 0 { - return CValue{mType: CValueTypeStack, anyVal: value} - } - var vs CValueState - if value == nil { - vs = cValueStateNil - } else { - vs = cValueStateZero + +func CreateCValueStack (value Stack ) CValue { + l := len(value) + if l == 0 { + if value == nil { + return CValue{vType: CValueTypeStack, vState: cValueStateNil} + } else { + return CValue{vType: CValueTypeStack, vState: cValueStateZero,anyVal: value} + } } - return CValue{mType: CValueTypeStack, mState: vs} + return CValue{vType: CValueTypeStack, anyVal: value, intVal: int64(l)} } -func CreateCValueBaleable(value blrs.Baleable) CValue { + +func CreateCValueBaleable (value Baleable ) CValue { if value == nil { - return CValue{mType: CValueTypeBaleable, mState: cValueStateNil} + return CValue{vType: CValueTypeBaleable, vState: cValueStateNil} } - return CValue{mType: CValueTypeBaleable, anyVal: value} + return CValue{ vType: CValueTypeBaleable, anyVal: value } } -func CreateCValueError(value error) CValue { +func CreateCValueError (value error ) CValue { if value == nil { - return CValue{mType: CValueTypeError, mState: cValueStateNil} + return CValue{vType: CValueTypeError, vState: cValueStateNil} } - return CValue{mType: CValueTypeError , anyVal: value} + return CValue{ vType: CValueTypeError, anyVal: value } } +func CreateCValueNil (_ any ) CValue { return CValue{ vType: CValueTypeNil, vState: cValueStateNil } } -func CreateCValueNil (_ any) CValue { - return CValue{mType: CValueTypeNil, mState: cValueStateNil } -} +func createCValueCValue (value CValue ) CValue { return CValue{vType: CValueTypeCValue, anyVal: value } } +func createCValueCField (value CField ) CValue { return CValue{vType: CValueTypeCField, anyVal: value} } -func CreateCValueObject(value any) CValue { - rvalue := reflect.ValueOf(value) - if !rvalue.IsValid() { - return CValue{mType: CValueTypeInvalid, mState: cValueStateError | cValueStateNil } // O createCValueInvalid(nil) si nil no es aceptable - } - if rvalue.Kind() != reflect.Struct { - return createCValueInvalid(value) // No es el tipo de mapa esperado - } - return createCValueObjectByReflected(value,reflect.ValueOf(value)) -} - -func CreateCValueMap (value any) CValue { - rvalue := reflect.ValueOf(value) - if !rvalue.IsValid() { - return CValue{mType: CValueTypeInvalid, mState: cValueStateError | cValueStateNil } // O createCValueInvalid(nil) si nil no es aceptable - } - if rvalue.Kind() != reflect.Map { - return createCValueInvalid(value) // No es el tipo de lista esperado - } - return createCValueMapByReflected(value,rvalue) -} - -func CreateCValueList(value any) CValue { - rvalue := reflect.ValueOf(value) - if !rvalue.IsValid() { - return CValue{mType: CValueTypeInvalid, mState: cValueStateError | cValueStateNil } - } - if rvalue.Kind() != reflect.Slice && rvalue.Kind() != reflect.Array { - return createCValueInvalid(value) // No es el tipo de lista esperado - } - return createCValueListByReflected(value,rvalue) -} +func createCValueObject (value any ) CValue { + return createCValueReflected(value,reflect.ValueOf(value),CValueTypeObject, true) } -func createCValueInvalid(value any) CValue { - return CValue{ mType: CValueTypeInvalid, anyVal: value } +func CreateCValueList (value any) CValue { + return createCValueReflected (value,reflect.ValueOf(value),CValueTypeList , true) } +func CreateCValueDefer (value any) CValue { + return createCValueReflected (value,reflect.ValueOf(value),CValueTypeDefer ,true) +} +func CreateCValueMap (value any) CValue { + return createCValueReflected (value,reflect.ValueOf(value),CValueTypeMap , true) +} +func createCValueInvalid (value any) CValue { + return CValue{ vType: CValueTypeInvalid, anyVal: value} +} +func createCValueWithInvalidError (value any, vtype CValueType, vstate CValueState, er string) CValue { + return CValue{ + vType : CValueTypeInvalid, + vState: cValueStateInvalid|cValueStateError|vstate, + intVal: int64(vtype), + anyVal: value, + strVal: er, + } +} -func (v CValue) Type () CValueType { return v.mType } -func (v CValue) State() CValueState { return v.mState } +func (v CValue) Type () CValueType { return v.vType } +func (v CValue) State() CValueState { return v.vState } -func (v CValue) Value() (any,bool) { - if v.mType == CValueTypeInvalid { - return nil,false - } - switch v.mType.BaseType() { - case CValueTypeBool : return v.AsBool () - case CValueTypeInt : return v.AsInt () - case CValueTypeInt8 : return v.AsInt8 () - case CValueTypeInt16 : return v.AsInt16 () - case CValueTypeInt32 : return v.AsInt32 () - case CValueTypeInt64 : return v.AsInt64 () - case CValueTypeUint : return v.AsUint () - case CValueTypeUint8 : return v.AsUint8 () - case CValueTypeUint16 : return v.AsUint16 () - case CValueTypeUint32 : return v.AsUint32 () - case CValueTypeUint64 : return v.AsUint64 () - case CValueTypeUintptr : return v.AsUintptr () - case CValueTypeFloat32 : return v.AsFloat32 () - case CValueTypeFloat64 : return v.AsFloat64 () - case CValueTypeComplex64 : return v.AsComplex64 () - case CValueTypeComplex128: return v.AsComplex128 () - case CValueTypeDuration : return v.AsDuration () - case CValueTypeDate : return v.AsDate () - case CValueTypeString : return v.AsString () - case CValueTypeBytes : return v.AsBytes () - case CValueTypeStack : return v.AsStack () - case CValueTypeBaleable : return v.AsBaleable () - case CValueTypeError : return v.AsError () - case CValueTypeNil : return nil,true - case CValueTypeObject : return v.AsObject () - - default: - if v.mType.IsList() { - return v.AsList() - } - if v.mType.IsMap() { - return v.AsMap() - } - return v.anyVal,true - } -} func (v CValue) AsBool () (bool,bool){ - if v.mType != CValueTypeBool { + if v.vType != CValueTypeBool { return false,false } - if v.State().IsNilOrZero() { + if v.vState.HasNilOrZero() { return false,true } + if v.vType.IsDefer() { + return (v.anyVal.(func()bool))(),true + } return v.intVal != 0,true } + + func (v CValue) AsInt () (int,bool){ - if v.mType != CValueTypeInt { + if v.vType != CValueTypeInt { return 0,false } - if v.State().IsNilOrZero() { + if v.vState.HasNilOrZero() { return 0,true } + if v.vType.IsDefer() { + return (v.anyVal.(func()int))(),true + } return int(v.intVal),true } +func (v CValue) AsInts () ([]int,bool){ + if v.vType != CValueTypeInt|CValueTypeList { + return nil,false + } + if v.vState.HasValueNil() { + return nil,true + } + return v.anyVal.([]int),true +} + + func (v CValue) AsInt8 () (int8,bool){ - if v.mType != CValueTypeInt8 { + if v.vType != CValueTypeInt8 { return 0,false } - if v.State().IsNilOrZero() { + if v.vState.HasNilOrZero() { return 0,true } + if v.vType.IsDefer() { + return (v.anyVal.(func()int8))(),true + } return int8(v.intVal),true } func (v CValue) AsInt16 () (int16,bool){ - if v.mType != CValueTypeInt16 { + if v.vType != CValueTypeInt16 { return 0,false } - if v.State().IsNilOrZero() { + if v.vState.HasNilOrZero() { return 0,true } + if v.vType.IsDefer() { + return (v.anyVal.(func()int16))(),true + } return int16(v.intVal),true } func (v CValue) AsInt32 () (int32,bool){ - if v.mType != CValueTypeInt32 { + if v.vType != CValueTypeInt32 { return 0,false } - if v.State().IsNilOrZero() { + if v.vState.HasNilOrZero() { return 0,true } + if v.vType.IsDefer() { + return (v.anyVal.(func()int32))(),true + } return int32(v.intVal),true } func (v CValue) AsInt64 () (int64,bool){ - if v.mType != CValueTypeInt64 { + if v.vType != CValueTypeInt64 { return 0,false } - if v.State().IsNilOrZero() { + if v.vState.HasNilOrZero() { return 0,true } + if v.vType.IsDefer() { + return (v.anyVal.(func()int64))(),true + } return v.intVal,true } func (v CValue) AsUint () (uint,bool){ - if v.mType != CValueTypeUint { + if v.vType != CValueTypeUint { return 0,false } - if v.State().IsNilOrZero() { + if v.vState.HasNilOrZero() { return 0,true } + if v.vType.IsDefer() { + return (v.anyVal.(func()uint))(),true + } return uint(v.intVal),true } func (v CValue) AsUint8 () (uint8,bool){ - if v.mType != CValueTypeUint8 { + if v.vType != CValueTypeUint8 { return 0,false } - if v.State().IsNilOrZero() { + if v.vState.HasNilOrZero() { return 0,true } + if v.vType.IsDefer() { + return (v.anyVal.(func()uint8))(),true + } return uint8(v.intVal),true } func (v CValue) AsUint16 () (uint16,bool){ - if v.mType != CValueTypeUint16 { + if v.vType != CValueTypeUint16 { return 0,false } - if v.State().IsNilOrZero() { + if v.vState.HasNilOrZero() { return 0,true } + if v.vType.IsDefer() { + return (v.anyVal.(func()uint16))(),true + } return uint16(v.intVal),true } func (v CValue) AsUint32 () (uint32,bool){ - if v.mType != CValueTypeUint32 { + if v.vType != CValueTypeUint32 { return 0,false } - if v.State().IsNilOrZero() { + if v.vState.HasNilOrZero() { return 0,true } + if v.vType.IsDefer() { + return (v.anyVal.(func()uint32))(),true + } return uint32(v.intVal),true } func (v CValue) AsUint64 () (uint64,bool){ - if v.mType != CValueTypeUint64 { + if v.vType != CValueTypeUint64 { return 0,false } - if v.State().IsNilOrZero() { + if v.vState.HasNilOrZero() { return 0,true } + if v.vType.IsDefer() { + return (v.anyVal.(func()uint64))(),true + } return uint64(v.intVal),true } + func (v CValue) AsUintptr() (uintptr,bool){ - if v.mType != CValueTypeUintptr { + if v.vType != CValueTypeUintptr { return 0,false } - if v.State().IsNilOrZero() { + if v.vState.HasNilOrZero() { return 0,true } + if v.vType.IsDefer() { + return (v.anyVal.(func()uintptr))(),true + } return uintptr(v.intVal),true } + func (v CValue) AsFloat32() (float32,bool){ - if v.mType != CValueTypeFloat32 { + if v.vType != CValueTypeFloat32 { return 0,false } - if v.State().IsNilOrZero() { + if v.vState.HasNilOrZero() { return 0,true } + if v.vType.IsDefer() { + return (v.anyVal.(func()float32))(),true + } return math.Float32frombits(uint32(v.intVal)), true } func (v CValue) AsFloat64() (float64,bool){ - if v.mType != CValueTypeFloat64 { + if v.vType != CValueTypeFloat64 { return 0,false } - if v.State().IsNilOrZero() { + if v.vState.HasNilOrZero() { return 0,true } + if v.vType.IsDefer() { + return (v.anyVal.(func()float64))(),true + } return math.Float64frombits(uint64(v.intVal)), true } func (v CValue) AsComplex64 () (complex64,bool){ - if v.mType != CValueTypeComplex64 { + if v.vType != CValueTypeComplex64 { return 0,false } - if v.State().IsNilOrZero() { + if v.vState.HasNilOrZero() { return 0,true } + if v.vType.IsDefer() { + return (v.anyVal.(func()complex64))(),true + } return v.anyVal.(complex64),true } func (v CValue) AsComplex128() (complex128,bool){ - if v.mType != CValueTypeComplex128 { + if v.vType != CValueTypeComplex128 { return 0,false } - if v.State().IsNilOrZero() { + if v.vState.HasNilOrZero() { return 0,true } + if v.vType.IsDefer() { + return (v.anyVal.(func()complex128))(),true + } return v.anyVal.(complex128),true } -func (v CValue) AsDuration() (time.Duration,bool){ - if v.mType != CValueTypeDuration { +func (v CValue) AsDuration() (Duration,bool){ + if v.vType != CValueTypeDuration { return 0,false } - if v.State().IsNilOrZero() { + if v.vState.HasNilOrZero() { return 0,true } + if v.vType.IsDefer() { + return (v.anyVal.(func()Duration))(),true + } return time.Duration(v.intVal),true } -func (v CValue) AsDate () (time.Time,bool){ - if v.mType != CValueTypeDate { +func (v CValue) AsDate () (Date,bool){ + if v.vType != CValueTypeDate { return time.Time{},false } - if v.State().IsNilOrZero() { + if v.vState.HasNilOrZero() { return time.Time{}, true } - if v.State().isVersion() { + if v.vType.IsDefer() { + return (v.anyVal.(func()Date))(),true + } + if v.vState.HasValueShort() { // version corta del date return time.Unix(0, v.intVal).In(v.anyVal.(*time.Location)), true } return v.anyVal.(time.Time),true } + func (v CValue) AsString () (string,bool){ - if v.mType != CValueTypeString { + if v.vType != CValueTypeString { return "", false } - if v.State().IsNilOrZero() { + if v.vState.HasNilOrZero() { return "", true } + if v.vType.IsDefer() { + return v.anyVal.(string), true + } return v.strVal,true } +func (v CValue) AsStrings () ([]string,bool){ + if v.vType != CValueTypeList|CValueTypeString { + return nil,false + } + if v.vState.HasValueNil() { + return nil,true + } + return v.anyVal.([]string),true +} + + func (v CValue) AsBytes () ([]byte,bool){ - if v.mType != CValueTypeBytes { + if v.vType != CValueTypeBytes { return nil, false } - if v.State().IsNil() { + if v.vState.HasValueNil() { return []byte(nil),true } - if v.State().IsZero() { - return []byte{}, true + if v.vType.IsDefer() { + return v.anyVal.([]byte),true } return v.anyVal.([]byte),true } -func (v CValue) AsStack () (excs.Stack,bool){ - if v.mType != CValueTypeStack { +func (v CValue) AsStack () (Stack,bool){ + if v.vType != CValueTypeStack { return nil, false } - if v.State().IsNil() { - return excs.Stack(nil),true + if v.vState.HasValueNil() { + return Stack(nil),true } - if v.State().IsZero() { - return excs.Stack{}, true + if v.vType.IsDefer() { + return v.anyVal.(Stack),true } return v.anyVal.(excs.Stack),true } func (v CValue) AsBaleable() (blrs.Baleable,bool){ - if v.mType != CValueTypeBaleable { + if v.vType != CValueTypeBaleable { return nil, false } - if v.State().IsNil() { + if v.vState.HasValueNil() { return blrs.Baleable(nil),true } + if v.vType.IsDefer() { + return v.anyVal.(blrs.Baleable),true + } return v.anyVal.(blrs.Baleable),true } func (v CValue) AsError () (error,bool){ - if v.mType != CValueTypeError { + if v.vType != CValueTypeError { return nil, false } - if v.State().IsNil() { + if v.vState.HasValueNil() { return error(nil),true } + if v.vType.IsDefer() { + return v.anyVal.(error),true + } return v.anyVal.(error),true } - -func (v CValue) AsObject () (any,bool) { - if v.mType != CValueTypeObject { - return nil, false +func (v CValue) AsCValue () (CValue,bool) { + if v.vType != CValueTypeCValue { + return CValue{}, false + } + if v.vType.IsDefer() { + return (v.anyVal.(func()CValue))(), true } - return v.anyVal.(reflect.Value).Interface(),true + return v.anyVal.(CValue), true } -func (v CValue) AsList () (any,bool) { - if v.mType != CValueTypeList { - return nil, false +func (v CValue) AsCField () (CField,bool) { + if v.vType != CValueTypeCField { + return CField{}, false } - if v.State().IsNil() { - return any(nil),true + if v.vType.IsDefer() { + return (v.anyVal.(func()CField))(), true } - return v.anyVal.(reflect.Value).Interface(),true + return v.anyVal.(CField), true } -func (v CValue) AsMap () (any,bool) { - if v.mType != CValueTypeMap { +func (v CValue) AsCFields() ([]CField,bool) { + if v.vType != CValueTypeCField|CValueTypeList { return nil, false } - if v.State().IsNil() { - return nil,true + if v.vState.HasValueNil() { + return nil, false } - return v.anyVal.(reflect.Value).Interface(),true -} - - -func (v CValue) AsReflected () (reflect.Value,bool) { - if !v.State().IsNil() { - return reflect.Value{},false + if v.vType.IsDefer() { + return v.anyVal.([]CField), true } - return v.anyVal.(reflect.Value),true + return v.anyVal.([]CField), true } -func createCValueListByReflected (value any, rvalue reflect.Value) CValue { - // asumimos que rvalue es valido y que es una slice ya que la llamada - // se ha hecho o bien a traves de CreateCValue o CreateCValueList - - eleType := rvalue.Type().Elem() - zeroEle := reflect.Zero(eleType) - baseEleType := reflectToCValueType(zeroEle, eleType) - finalListCType := CValueTypeList | baseEleType - var vState CValueState - if rvalue.IsNil() { // Aunque Kind sea Slice, el slice subyacente puede ser nil - vState = cValueStateNil - return CValue{mType: finalListCType, mState: vState} +func (v CValue) AsObject () (any,bool) { + if v.vType != CValueTypeObject { + return nil, false } - vState = cValueStateReflected - if rvalue.Len() == 0 { - vState |= cValueStateZero + if v.vType.IsDefer() { + return v.anyVal.(any),true } - return CValue{mType: finalListCType, mState: vState, anyVal: rvalue} + return v.anyVal,true } -func createCValueMapByReflected (value any, rvalue reflect.Value) CValue { - // asumimos que rvalue es valido y que es un map ya que la llamada - // se ha hecho o bien a traves de CreateCValue o CreateCValueMap - - tv := rvalue.Type() - kType := tv.Key() - vType := tv.Elem() - - zeroKey := reflect.Zero(kType) - zeroValue := reflect.Zero(vType) - - mType := buildMapType(reflectToCValueType(zeroKey, kType), reflectToCValueType(zeroValue, vType)) - - var vState CValueState - if rvalue.IsNil() { - vState = cValueStateNil - return CValue{mType: mType, mState: vState} +func (v CValue) AsList () (any,bool) { + if v.vType != CValueTypeList { + return nil, false } - vState = cValueStateReflected - if rvalue.Len() == 0 { - vState |= cValueStateZero + if v.vType.IsDefer() { + return v.anyVal.(any),true } - return CValue{mType: mType, mState: vState, anyVal: rvalue} -} - -func createCValueObjectByReflected (value any, rvalue reflect.Value) CValue { - // asumimos que rvalue es valido y que es un struct ya que la llamada - // se ha hecho o bien a traves de CreateCValue o CreateCValueMap - return CValue{mType: CValueTypeObject, mState: cValueStateReflected, anyVal: rvalue} + return v.anyVal,true } - - -// reflectToCValueType determina el CValueType base para un reflect.Value y reflect.Type dados. -func reflectToCValueType(rv reflect.Value, tp reflect.Type) CValueType { - // Priorizar la identificación por el valor concreto para tipos conocidos y válidos. - if rv.IsValid() { - switch rv.Interface().(type) { - case time.Time: return CValueTypeDate - case time.Duration: return CValueTypeDuration - case excs.Stack: return CValueTypeStack - case []byte: return CValueTypeBytes - case blrs.Baleable: return CValueTypeBaleable - case error: return CValueTypeError - } +func (v CValue) AsMap () (any,bool) { + if v.vType != CValueTypeMap { + return nil, false } - - // Si tp es nil, no hay información de tipo para determinar. - if tp == nil { - return CValueTypeInvalid - } - - // Identificar tipos que implementan interfaces específicas. - if tp.Implements(reflect.TypeOf((*error)(nil)).Elem()) { - return CValueTypeError - } - if tp.Implements(reflect.TypeOf((*blrs.Baleable)(nil)).Elem()) { - return CValueTypeBaleable - } - - // Como último recurso, mapear el Kind del tipo a un CValueType. - // kindToCValueType debe ser robusto y manejar correctamente - // todos los reflect.Kind relevantes (ej., Struct -> Object, Slice/Array -> List). - return kindToCValueType(tp.Kind(), false) -} - - -func kindToCValueType(kind reflect.Kind, base bool) CValueType { - switch kind { - case reflect.Bool: return CValueTypeBool - case reflect.Int: return CValueTypeInt - case reflect.Int8: return CValueTypeInt8 - case reflect.Int16: return CValueTypeInt16 - case reflect.Int32: return CValueTypeInt32 - case reflect.Int64: return CValueTypeInt64 - case reflect.Uint: return CValueTypeUint - case reflect.Uint8: return CValueTypeUint8 - case reflect.Uint16: return CValueTypeUint16 - case reflect.Uint32: return CValueTypeUint32 - case reflect.Uint64: return CValueTypeUint64 - case reflect.Uintptr: return CValueTypeUintptr - case reflect.Float32: return CValueTypeFloat32 - case reflect.Float64: return CValueTypeFloat64 - case reflect.Complex64: return CValueTypeComplex64 - case reflect.Complex128:return CValueTypeComplex128 - case reflect.String: return CValueTypeString - - case reflect.Array, - reflect.Slice: - if base { - return CValueTypeList - } - return CValueTypeAny - case reflect.Map: - if base { - return CValueTypeMap - } - return CValueTypeAny - - case reflect.Struct: - if base { - return CValueTypeObject - } - return CValueTypeAny - - default: - return CValueTypeAny + if v.vType.IsDefer() { + return v.anyVal.(any),true } + return v.anyVal,true } - - - - - - - - - diff --git a/src/core/vals/cvalue_creator.go b/src/core/vals/cvalue_creator.go deleted file mode 100644 index 1eb731e..0000000 --- a/src/core/vals/cvalue_creator.go +++ /dev/null @@ -1,84 +0,0 @@ -// ============================================================================= -// 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 28/05/2025 -// ============================================================================= - -package vals - -type ( - cValueCreator interface { - createCValue(value any) CValue - } - creatorCValueFnc[T any] func(T) CValue - - genericProvider[T any] func() T -) - -func (f creatorCValueFnc[T]) createCValue(value any) CValue { - return f(value.(T)) -} - - - -func makeFuncCreator[T any](vtype CValueType, fnc creatorCValueFnc[T]) cValueCreator { - // The returned creatorCValueFnc expects 'value' to be of type 'func() T'. - // So, the generic parameter for creatorCValueFnc should be 'func() T'. - return creatorCValueFnc[func() T](func(callerFunc func() T) CValue { - if callerFunc == nil { - return CValue{mType: vtype, mState: cValueStateNil} - } - // Call the original function to get the actual value of type T, - // then pass it to the provided 'fnc' (which is creatorCValueFnc[T]). - return fnc(callerFunc()) - }) -} - - - -func makePointerCreator[T any](vtype CValueType, fnc creatorCValueFnc[T]) cValueCreator { - return creatorCValueFnc[*T](func(value *T) CValue { // La entrada es explícitamente *T - if value == nil { - // Si el puntero es nil, creamos un CValue que representa un valor nil del tipo T. - // Para obtener el CValueType de T, usamos una función auxiliar. - return CValue{mType: vtype, mState: cValueStateNil} - } - - // Si el puntero no es nil, lo desreferenciamos y llamamos a la función original (fnc). - return fnc(*value) - }) -} - -func makeListCreator[T any](vtype CValueType) cValueCreator { - return creatorCValueFnc[[]T](func(value []T) CValue { - if value == nil { - return CValue{mType: vtype, mState: cValueStateNil} - } - if len(value) == 0 { - return CValue{mType: vtype, mState: cValueStateZero, anyVal: value} - } - return CValue{mType: vtype, anyVal: value} // Asegúrate de usar 'anyVal' para el campo de valor - }) -} diff --git a/src/core/vals/cvalue_state.go b/src/core/vals/cvalue_state.go index 9ca2f60..8e90a4d 100644 --- a/src/core/vals/cvalue_state.go +++ b/src/core/vals/cvalue_state.go @@ -23,45 +23,59 @@ // THE SOFTWARE. // // ============================================================================= -// Date Create 28/05/2025 +// Date Create 04/06/2025 // ============================================================================= package vals +import "strings" + const ( - cValueStateInvalid CValueState = 1 << iota - cValueStateNil - cValueStateZero - cValueStateVersion - cValueStateSensitive - cValueStateReflected - cValueStateError + cValueStateInvalid CValueState = 1 << iota // El valor almacenado es un valor invalido + cValueStateNil // Indica que el valor es nulo + cValueStateZero // Indica que el valor tiene valor 0 + cValueStateReflected // Indica que el valor guardado es un value.reflect + cValueStateShort // Indica que el valor es la versión corta del valor, por ejemplo: los dates + cValueStateSensitive // Indica que el valor es delicado, por ejemplo no mostrar o no serializar + cValueStateEncoded // Indica que el valor está codificado + cValueStateError // Indica que el valor no ha podido ser establecido por un error que esta representado en el + // valor cValueStateNone CValueState = 0 - cValueStateNilOrZero = cValueStateZero | cValueStateNil - cValueStateOptions = cValueStateSensitive + cValueStateOps CValueState = cValueStateEncoded|cValueStateSensitive ) -type CValueState uint8 - -func (f CValueState) IsInvalid() bool { return f&cValueStateInvalid != 0 } -func (f CValueState) IsNil() bool { return f&cValueStateNil != 0 } +type CValueState uint8 -func (f CValueState) IsZero() bool { return f&cValueStateZero != 0 } -func (f CValueState) IsNilOrZero() bool { return f&cValueStateNilOrZero != 0 } +func (s CValueState) HasValueInvalid () bool { return s&cValueStateInvalid != 0 } +func (s CValueState) HasValueNil () bool { return s&cValueStateNil != 0 } +func (s CValueState) HasValueZero () bool { return s&cValueStateZero != 0 } +func (s CValueState) HasValueReflected() bool { return s&cValueStateReflected != 0 } +func (s CValueState) HasValueShort () bool { return s&cValueStateShort != 0 } +func (s CValueState) HasValueSensitive() bool { return s&cValueStateSensitive != 0 } +func (s CValueState) HasValueEncoded () bool { return s&cValueStateEncoded != 0 } +func (s CValueState) HasValueError () bool { return s&cValueStateError != 0 } -func (f CValueState) IsSensitive() bool { return f&cValueStateSensitive != 0 } +func (s CValueState) HasNilOrZero () bool { return s&(cValueStateZero|cValueStateNil) != 0 } -func (f CValueState) IsReflected() bool { return f&cValueStateReflected != 0 } +func (s CValueState) setOption (options CValueState) CValueState { return s|(options&cValueStateOps) } -func (f CValueState) IsError() bool { return f&cValueStateError != 0 } -func (f CValueState) isVersion() bool { return f&cValueStateVersion != 0 } +func (s CValueState) String() string { + states := [...]string{"invalid","nil","zero","reflected","short","sensitive","encoded","error"} + c := make([]string,0,4) + for i:=0; i<7; i++ { + if s& (1< 2 { // Should not happen if buildMapType is used - return CValueTypeInvalid - } - if nb == 1 { - return bs // Value type is the same as key type - } - - type1 := bs & -bs // The CValueType with the smallest bit value - type2 := bs &^ type1 // The CValueType with the largest bit value +func (t CValueType) IsComposite() bool { return t&maskCValueTypeComposite != 0 } - if (v & cValueTypeMKey) != 0 { - // MKey is active: value is type1 (smaller bit value) - return type1 +func (t CValueType) BaseType () CValueType { + if t&CValueTypeMap == 0 { + return t &maskCValueTypeBase } - // MKey is not active: value is type2 (larger bit value) - return type2 + _,vt := t.MapType() + return vt } -func (v CValueType) IsList () bool { return v&cValueTypeCompositeMask == CValueTypeList } - -func (v CValueType) IsListOf (baseType CValueType) bool { - return v&cValueTypeCompositeMask == CValueTypeList && v&cValueTypeBaseMask == baseType -} - - -func (v CValueType) IsMap () bool { return v&cValueTypeCompositeMask == CValueTypeMap } - -func (v CValueType) MapType () (CValueType, CValueType) { - if !v.IsMap() { +func (t CValueType) MapType () (CValueType,CValueType) { + if t&CValueTypeMap == 0 { return CValueTypeInvalid, CValueTypeInvalid } - bs := v & cValueTypeBaseMask - nb := bits.OnesCount32(uint32(bs)) - if nb == 0 || nb > 2 { // Should not happen - return CValueTypeInvalid, CValueTypeInvalid - } - if nb == 1 { - return bs, bs // Key and value types are the same - } - - type1 := bs & -bs // The CValueType with the smallest bit value - type2 := bs &^ type1 // The CValueType with the largest bit value - - if (v & cValueTypeMKey) != 0 { - // MKey is active: key is type2 (larger bit value), value is type1 (smaller bit value) - return type2, type1 + bs := t &maskCValueTypeBase + switch bits.OnesCount32(uint32(bs)) { + case 1: return bs,bs + case 2: + if t&CValueTypeMapKey == 0 { + return bs&-bs,bs&^(bs&-bs) + } + return bs&^(bs&-bs),bs&-bs + default: + return CValueTypeInvalid,CValueTypeInvalid } - // MKey is not active: key is type1 (smaller bit value), value is type2 (larger bit value) - return type1, type2 } -func (v CValueType) IsMapKeyOf (keyType CValueType) bool { - kt,_ := v.MapType() - return kt == keyType -} -func (v CValueType) IsMapValueOf (baseType CValueType) bool { - _,tv := v.MapType() - return tv == baseType +func (t CValueType) IsTypeInvalid () bool { return t&maskCValueTypeBase == CValueTypeInvalid } +func (t CValueType) IsTypeAny () bool { return t&maskCValueTypeBase == CValueTypeAny } +func (t CValueType) IsTypeBool () bool { return t&maskCValueTypeBase == CValueTypeBool } +func (t CValueType) IsTypeInt () bool { return t&maskCValueTypeBase == CValueTypeInt } +func (t CValueType) IsTypeInt8 () bool { return t&maskCValueTypeBase == CValueTypeInt8 } +func (t CValueType) IsTypeInt16 () bool { return t&maskCValueTypeBase == CValueTypeInt16 } +func (t CValueType) IsTypeInt32 () bool { return t&maskCValueTypeBase == CValueTypeInt32 } +func (t CValueType) IsTypeInt64 () bool { return t&maskCValueTypeBase == CValueTypeInt64 } +func (t CValueType) IsTypeUint () bool { return t&maskCValueTypeBase == CValueTypeUint } +func (t CValueType) IsTypeUint8 () bool { return t&maskCValueTypeBase == CValueTypeUint8 } +func (t CValueType) IsTypeUint16 () bool { return t&maskCValueTypeBase == CValueTypeUint16 } +func (t CValueType) IsTypeUint32 () bool { return t&maskCValueTypeBase == CValueTypeUint32 } +func (t CValueType) IsTypeUint64 () bool { return t&maskCValueTypeBase == CValueTypeUint64 } +func (t CValueType) IsTypeUintptr () bool { return t&maskCValueTypeBase == CValueTypeUintptr } +func (t CValueType) IsTypeFloat32 () bool { return t&maskCValueTypeBase == CValueTypeFloat32 } +func (t CValueType) IsTypeFloat64 () bool { return t&maskCValueTypeBase == CValueTypeFloat64 } +func (t CValueType) IsTypeComplex64 () bool { return t&maskCValueTypeBase == CValueTypeComplex64} +func (t CValueType) IsTypeComplex128 () bool { return t&maskCValueTypeBase == CValueTypeComplex128} +func (t CValueType) IsTypeDuration () bool { return t&maskCValueTypeBase == CValueTypeDuration } +func (t CValueType) IsTypeDate () bool { return t&maskCValueTypeBase == CValueTypeDate } +func (t CValueType) IsTypeString () bool { return t&maskCValueTypeBase == CValueTypeString } +func (t CValueType) IsTypeBytes () bool { return t&maskCValueTypeBase == CValueTypeBytes } +func (t CValueType) IsTypeStack () bool { return t&maskCValueTypeBase == CValueTypeStack } +func (t CValueType) IsTypeBaleable () bool { return t&maskCValueTypeBase == CValueTypeBaleable } +func (t CValueType) IsTypeError () bool { return t&maskCValueTypeBase == CValueTypeError } +func (t CValueType) IsTypeNil () bool { return t&maskCValueTypeBase == CValueTypeNil } +func (t CValueType) IsTypeCVal () bool { return t&maskCValueTypeBase == CValueTypeCValue } +func (t CValueType) IsTypeCField () bool { return t&maskCValueTypeBase == CValueTypeCField } +func (t CValueType) IsTypeObject () bool { return t&maskCValueTypeBase == CValueTypeObject } + +func (t CValueType) IsDefer () bool { return t&CValueTypeDefer != 0 } +func (t CValueType) IsList () bool { return t&CValueTypeList != 0 } +func (t CValueType) IsMap () bool { return t&CValueTypeMap != 0 } + + +func (t CValueType) String () string { + return G.TypeInfos.getName(t) } - -func (v CValueType) IsTypeInvalid () bool { return v&cValueTypeBaseMask==CValueTypeInvalid} -func (v CValueType) IsTypeAny () bool {return v&cValueTypeBaseMask==CValueTypeAny } -func (v CValueType) IsTypeBool () bool {return v&cValueTypeBaseMask==CValueTypeBool} -func (v CValueType) IsTypeInt () bool {return v&cValueTypeBaseMask==CValueTypeInt} -func (v CValueType) IsTypeInt8 () bool {return v&cValueTypeBaseMask==CValueTypeInt8} -func (v CValueType) IsTypeInt16 () bool {return v&cValueTypeBaseMask==CValueTypeInt16} -func (v CValueType) IsTypeInt32 () bool {return v&cValueTypeBaseMask==CValueTypeInt32} -func (v CValueType) IsTypeInt64 () bool {return v&cValueTypeBaseMask==CValueTypeInt64} -func (v CValueType) IsTypeUint () bool {return v&cValueTypeBaseMask==CValueTypeUint} -func (v CValueType) IsTypeUint8 () bool {return v&cValueTypeBaseMask==CValueTypeUint8} -func (v CValueType) IsTypeUint16 () bool {return v&cValueTypeBaseMask==CValueTypeUint16} -func (v CValueType) IsTypeUint32 () bool {return v&cValueTypeBaseMask==CValueTypeUint32} -func (v CValueType) IsTypeUint64 () bool {return v&cValueTypeBaseMask==CValueTypeUint64} -func (v CValueType) IsTypeUintptr () bool {return v&cValueTypeBaseMask==CValueTypeUintptr} -func (v CValueType) IsTypeFloat32 () bool {return v&cValueTypeBaseMask==CValueTypeFloat32} -func (v CValueType) IsTypeFloat64 () bool {return v&cValueTypeBaseMask==CValueTypeFloat64} -func (v CValueType) IsTypeComplex64 () bool {return v&cValueTypeBaseMask==CValueTypeComplex64} -func (v CValueType) IsTypeComplex128 () bool {return v&cValueTypeBaseMask==CValueTypeComplex128} -func (v CValueType) IsTypeDuration () bool {return v&cValueTypeBaseMask==CValueTypeDuration} -func (v CValueType) IsTypeDate () bool {return v&cValueTypeBaseMask==CValueTypeDate} -func (v CValueType) IsTypeString () bool {return v&cValueTypeBaseMask==CValueTypeString} -func (v CValueType) IsTypeBytes () bool {return v&cValueTypeBaseMask==CValueTypeBytes} -func (v CValueType) IsTypeStack () bool {return v&cValueTypeBaseMask==CValueTypeStack} -func (v CValueType) IsTypeBaleable () bool {return v&cValueTypeBaseMask==CValueTypeBaleable} -func (v CValueType) IsTypeError () bool {return v&cValueTypeBaseMask==CValueTypeError} -func (v CValueType) IsTypeNil () bool {return v&cValueTypeBaseMask==CValueTypeNil} -func (v CValueType) IsTypeObject () bool {return v&cValueTypeBaseMask==CValueTypeObject} - - -func (v CValueType) String () string { - // IsList ? - if v&cValueTypeCompositeMask == CValueTypeList { - return strings.Join(append([]string{g.cValueTypeInfos[idxCValueTypeList].name},v.BaseType().String()),cValueTypeSep) - } - if v&cValueTypeCompositeMask == CValueTypeMap { - t1,t2 := v.MapType() - return strings.Join(append([]string{g.cValueTypeInfos[idxCValueTypeMap].name}, - g.cValueTypeInfos[getCValueTypeIdx(t1)].name, - g.cValueTypeInfos[getCValueTypeIdx(t2)].name),cValueTypeSep) - } - return g.cValueTypeInfos[getCValueTypeIdx(v)].name -} - - -func buildMapType (keyType, valueType CValueType) CValueType { - if keyType == CValueTypeInvalid || valueType == CValueTypeInvalid { +func buildMapType(keyType, valType CValueType) CValueType { + if keyType == CValueTypeInvalid || valType == CValueTypeInvalid { return CValueTypeInvalid } - if keyType == valueType { - return keyType|CValueTypeMap + if keyType == valType { + return CValueTypeMap|keyType } - if keyType < valueType { - return keyType|valueType|CValueTypeMap + if keyType < valType { + return CValueTypeMap|keyType|valType } - return keyType|valueType|CValueTypeMap| cValueTypeMKey + return CValueTypeMap|valType|keyType|CValueTypeMapKey } - - diff --git a/src/core/vals/cvalue_type_info.go b/src/core/vals/cvalue_type_info.go deleted file mode 100644 index 527686c..0000000 --- a/src/core/vals/cvalue_type_info.go +++ /dev/null @@ -1,199 +0,0 @@ -// ============================================================================= -// 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 28/05/2025 -// ============================================================================= - -package vals - -import ( - "core/blrs" - "core/excs" - "time" -) - -const ( - idxCValueTypeInvalid = iota - idxCValueTypeAny - - idxCValueTypeBool - - idxCValueTypeInt - idxCValueTypeInt8 - idxCValueTypeInt16 - idxCValueTypeInt32 - idxCValueTypeInt64 - - idxCValueTypeUint - idxCValueTypeUint8 - idxCValueTypeUint16 - idxCValueTypeUint32 - idxCValueTypeUint64 - - idxCValueTypeUintptr - - idxCValueTypeFloat32 - idxCValueTypeFloat64 - idxCValueTypeComplex64 - idxCValueTypeComplex128 - - idxCValueTypeDuration - idxCValueTypeDate - - idxCValueTypeString - idxCValueTypeBytes - idxCValueTypeStack - - idxCValueTypeBaleable - - idxCValueTypeError - idxCValueTypeNil - - _ - _ - idxCValueTypeObject - - idxCValueTypeList - idxCValueTypeMap - -) - -type ( - cValueTypeInfo struct { - vType CValueType - name string - getter func() any - - vCreator, - lCreator, - pCreator, - fCreator cValueCreator - } -) - -func createCValueTypeInfo[T any](vtype CValueType, name string, creatorFnc creatorCValueFnc[T]) cValueTypeInfo { - - return cValueTypeInfo{ - vType: vtype, - name: name, - vCreator: creatorFnc, - lCreator: makeListCreator[T](vtype | CValueTypeList), - fCreator: makeFuncCreator[T](vtype, creatorFnc), - pCreator: makePointerCreator[T](vtype, creatorFnc), - } -} - -func createCValueTypeInfos() [maxCValueTypes]cValueTypeInfo { - return [maxCValueTypes]cValueTypeInfo{ - idxCValueTypeInvalid: createCValueTypeInfo[any ](CValueTypeInvalid, "invalid", createCValueInvalid), - idxCValueTypeAny : createCValueTypeInfo[any ](CValueTypeAny, "any", CreateCValueAny), - idxCValueTypeBool : createCValueTypeInfo[bool ](CValueTypeBool, "bool", CreateCValueBool), - idxCValueTypeInt : createCValueTypeInfo[int ](CValueTypeInt, "int", CreateCValueInt), - idxCValueTypeInt8 : createCValueTypeInfo[int8 ](CValueTypeInt8, "int8", CreateCValueInt8), - idxCValueTypeInt16 : createCValueTypeInfo[int16](CValueTypeInt16, "int16", CreateCValueInt16), - idxCValueTypeInt32 : createCValueTypeInfo[int32](CValueTypeInt32, "int32", CreateCValueInt32), - idxCValueTypeInt64 : createCValueTypeInfo[int64](CValueTypeInt64, "int64", CreateCValueInt64), - idxCValueTypeUint : createCValueTypeInfo[uint ](CValueTypeUint, "uint", CreateCValueUint), - // Manejo especial para uint8: su creador de listas es para bytes - idxCValueTypeUint8: { - vType: CValueTypeUint8, - name: "uint8", - vCreator: creatorCValueFnc[uint8](CreateCValueUint8), - lCreator: creatorCValueFnc[[]uint8](CreateCValueBytes), // Lista de uint8 es bytes ([]uint8) - fCreator: makeFuncCreator[uint8](CValueTypeUint8, creatorCValueFnc[uint8](CreateCValueUint8)), - pCreator: makePointerCreator[uint8](CValueTypeUint8, creatorCValueFnc[uint8](CreateCValueUint8)), - }, - idxCValueTypeUint16 : createCValueTypeInfo[uint16](CValueTypeUint16, "uint16", CreateCValueUint16), - idxCValueTypeUint32 : createCValueTypeInfo[uint32](CValueTypeUint32, "uint32", CreateCValueUint32), - idxCValueTypeUint64 : createCValueTypeInfo[uint64](CValueTypeUint64, "uint64", CreateCValueUint64), - idxCValueTypeUintptr: createCValueTypeInfo[uintptr](CValueTypeUintptr, "uintptr", CreateCValueUintptr), - idxCValueTypeFloat32: createCValueTypeInfo[float32](CValueTypeFloat32, "float32", CreateCValueFloat32), - idxCValueTypeFloat64: createCValueTypeInfo[float64](CValueTypeFloat64, "float64", CreateCValueFloat64), - idxCValueTypeComplex64 : createCValueTypeInfo[complex64](CValueTypeComplex64, "complex64", CreateCValueComplex64), - idxCValueTypeComplex128 : createCValueTypeInfo[complex128](CValueTypeComplex128, "complex128", CreateCValueComplex128), - idxCValueTypeDuration : createCValueTypeInfo[time.Duration](CValueTypeDuration, "duration", CreateCValueDuration), - idxCValueTypeDate : createCValueTypeInfo[time.Time](CValueTypeDate, "date", CreateCValueDate), - idxCValueTypeString : createCValueTypeInfo[string](CValueTypeString, "string", CreateCValueString), - idxCValueTypeBytes : createCValueTypeInfo[[]uint8](CValueTypeBytes, "bytes", CreateCValueBytes), - idxCValueTypeStack : createCValueTypeInfo[excs.Stack](CValueTypeStack, "stack", CreateCValueStack), - idxCValueTypeBaleable: createCValueTypeInfo[blrs.Baleable](CValueTypeBaleable, "packable", CreateCValueBaleable), - idxCValueTypeError : createCValueTypeInfo[error](CValueTypeError, "error", CreateCValueError), - idxCValueTypeNil : createCValueTypeInfo[any](CValueTypeNil, "nil", CreateCValueNil), - // Tipos no definidos - 26 : createCValueTypeInfo[any](CValueTypeInvalid, "invalid", createCValueInvalid), - 27 : createCValueTypeInfo[any](CValueTypeInvalid, "invalid", createCValueInvalid), - //--------------------- - idxCValueTypeObject : createCValueTypeInfo[any](CValueTypeObject, "object", CreateCValueObject), - idxCValueTypeList : createCValueTypeInfo[any](CValueTypeList, "list", CreateCValueList), - idxCValueTypeMap : createCValueTypeInfo[any](CValueTypeMap, "map", CreateCValueMap), - // Flag del mama - 31 : createCValueTypeInfo[any](CValueTypeInvalid, "invalid", createCValueInvalid), - } -} - - - - -func getCValueTypeIdx (vtype CValueType) int { - switch vtype { - case CValueTypeInvalid : return idxCValueTypeInvalid - case CValueTypeAny : return idxCValueTypeAny - case CValueTypeBool : return idxCValueTypeBool - case CValueTypeInt : return idxCValueTypeInt - case CValueTypeInt8 : return idxCValueTypeInt8 - case CValueTypeInt16 : return idxCValueTypeInt16 - case CValueTypeInt32 : return idxCValueTypeInt32 - case CValueTypeInt64 : return idxCValueTypeInt64 - case CValueTypeUint : return idxCValueTypeUint - case CValueTypeUint8 : return idxCValueTypeUint8 - case CValueTypeUint16 : return idxCValueTypeUint16 - case CValueTypeUint32 : return idxCValueTypeUint32 - case CValueTypeUint64 : return idxCValueTypeUint64 - case CValueTypeUintptr : return idxCValueTypeUintptr - case CValueTypeFloat32 : return idxCValueTypeFloat32 - case CValueTypeFloat64 : return idxCValueTypeFloat64 - case CValueTypeComplex64: return idxCValueTypeComplex64 - case CValueTypeComplex128: return idxCValueTypeComplex128 - case CValueTypeDuration: return idxCValueTypeDuration - case CValueTypeDate : return idxCValueTypeDate - case CValueTypeString : return idxCValueTypeString - case CValueTypeBytes : return idxCValueTypeBytes - case CValueTypeStack : return idxCValueTypeStack - case CValueTypeBaleable: return idxCValueTypeBaleable - case CValueTypeError : return idxCValueTypeError - case CValueTypeNil : return idxCValueTypeNil - - case CValueTypeObject : return idxCValueTypeObject - - case CValueTypeList : return idxCValueTypeList - case CValueTypeMap : return idxCValueTypeMap - - default: - // Se mapea a 0 (CValueTypeInvalid) como un valor por defecto. - // Manejar tipos que no están directamente mapeados, si es necesario. - // Podrías devolver -1 o un valor de error específico. - return 0 // Opcional: devolver 0 (Invalid) para tipos no mapeados explícitamente. - } -} \ No newline at end of file diff --git a/src/core/cflss/cvalue_type_infos.go b/src/core/vals/cvalue_type_infos.go similarity index 99% rename from src/core/cflss/cvalue_type_infos.go rename to src/core/vals/cvalue_type_infos.go index 684411b..8c51d71 100644 --- a/src/core/cflss/cvalue_type_infos.go +++ b/src/core/vals/cvalue_type_infos.go @@ -26,7 +26,7 @@ // Date Create 05/06/2025 // ============================================================================= -package cflss +package vals import ( "math" diff --git a/src/core/cflss/types.go b/src/core/vals/types.go similarity index 99% rename from src/core/cflss/types.go rename to src/core/vals/types.go index 626c54d..8515979 100644 --- a/src/core/cflss/types.go +++ b/src/core/vals/types.go @@ -26,7 +26,7 @@ // Date Create 05/06/2025 // ============================================================================= -package cflss +package vals import ( "core/blrs"