diff --git a/.idea/active3.iml b/.idea/active3.iml index 5e764c4..32c7253 100644 --- a/.idea/active3.iml +++ b/.idea/active3.iml @@ -2,7 +2,9 @@ - + + + diff --git a/AATest/field_benchmarks_test.go b/AATest/field_benchmarks_test.go index 18c9395..5dd777a 100644 --- a/AATest/field_benchmarks_test.go +++ b/AATest/field_benchmarks_test.go @@ -19,18 +19,21 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -// ------------------------------------------------------------------------ +// ------------------------------------------------------------A------------ package AATest import ( + "acache" "aflds" + "fields" "testing" ) -func BenchmarkA (b *testing.B) { +func BenchmarkAflds (b *testing.B) { for i := 0; i < b.N; i++ { + aflds.NewFieldString("f1", "value") aflds.NewFieldUint("f2", 11) aflds.NewFieldInt("f3", -11) @@ -39,12 +42,123 @@ func BenchmarkA (b *testing.B) { aflds.NewDFieldInt("d1",func()int{ return -3 }) aflds.NewDFieldUint("d2",func()uint{ return uint(3) }) aflds.NewDFieldFloat("f2",func()float64{ return 3.2}) + + } +} + + +func BenchmarkAcache (b *testing.B) { + for i := 0; i < b.N; i++ { + + acache.NewFieldString("f1", "value") + acache.NewFieldUint("f2", 11) + acache.NewFieldInt("f3", -11) + acache.NewFieldFloat("f4", 2.3) + acache.NewFieldBinary("f5", []byte{1,2,2,4,3,3,3,3}) + acache.NewDFieldInt("d1",func()int{ return -3 }) + acache.NewDFieldUint("d2",func()uint{ return uint(3) }) + acache.NewDFieldFloat("f2",func()float64{ return 3.2}) + + } +} + + +func BenchmarkAFields (b *testing.B) { + for i := 0; i < b.N; i++ { + + fields.NewFieldString("f1", "value") + fields.NewFieldUint("f2", 11) + fields.NewFieldInt("f3", -11) + fields.NewFieldFloat("f4", 2.3) + fields.NewFieldBinary("f5", []byte{1,2,2,4,3,3,3,3}) + fields.NewDFieldInt("d1",func()int{ return -3 }) + fields.NewDFieldUint("d2",func()uint{ return uint(3) }) + fields.NewDFieldFloat("f2",func()float64{ return 3.2}) + + } +} + + + +/* +func BenchmarkA1 (b *testing.B) { + for i := 0; i < b.N; i++ { + aflds.NewDFieldString("f1", func() string { return "value" }) + aflds.NewDFieldUint("f2", func () uint { return uint(11) }) + aflds.NewDFieldInt("f3", func () int { return -11 }) + aflds.NewDFieldFloat("f4",func() float64 { return 2.3 }) + aflds.NewDFieldBinary("f5",func() []byte { return []byte{1,2,2,4,3,3,3,3} }) + aflds.NewDFieldInt("d1",func()int{ return -3 }) + aflds.NewDFieldUint("d2",func()uint{ return uint(3) }) + aflds.NewDFieldFloat("f2",func()float64{ return 3.2}) + } +} + +*/ + + +func BenchmarkAfldsAcc (b *testing.B) { + var d[8]any + flds := []aflds.Field { + aflds.NewFieldString("f1", "value"), + aflds.NewFieldUint("f2", 11), + aflds.NewFieldInt("f3", -11), + aflds.NewFieldFloat("f4", 2.3), + aflds.NewFieldBinary("f5", []byte{1,2,2,4,3,3,3,3}), + aflds.NewDFieldInt("d1",func()int{ return -3 }), + aflds.NewDFieldUint("d2",func()uint{ return uint(3) }), + aflds.NewDFieldFloat("f2",func()float64{ return 3.2}), + } + for i := 0; i < b.N; i++ { + for i:=0; i<8; i++ { + d[i]=flds[i].Value() + } + } +} + +func BenchmarkAcacheAcc (b *testing.B) { + var d[8]any + flds := []acache.Field { + acache.NewDFieldString("f1", func() string { return "value" }), + acache.NewDFieldUint("f2", func () uint { return uint(11) }), + acache.NewDFieldInt("f3", func () int { return -11 }), + acache.NewDFieldFloat("f4",func() float64 { return 2.3 }), + acache.NewDFieldBinary("f5",func() []byte { return []byte{1,2,2,4,3,3,3,3} }), + acache.NewDFieldInt("d1",func()int{ return -3 }), + acache.NewDFieldUint("d2",func()uint{ return uint(3) }), + acache.NewDFieldFloat("f2",func()float64{ return 3.2}), + } + for i := 0; i < b.N; i++ { + for i:=0; i<8; i++ { + d[i]=flds[i].Value() + } + } +} + + +func BenchmarkAFieldsAcc (b *testing.B) { + var d[8]any + flds := []fields.Field { + fields.NewDFieldString("f1", func() string { return "value" }), + fields.NewDFieldUint("f2", func () uint { return uint(11) }), + fields.NewDFieldInt("f3", func () int { return -11 }), + fields.NewDFieldFloat("f4",func() float64 { return 2.3 }), + fields.NewDFieldBinary("f5",func() []byte { return []byte{1,2,2,4,3,3,3,3} }), + fields.NewDFieldInt("d1",func()int{ return -3 }), + fields.NewDFieldUint("d2",func()uint{ return uint(3) }), + fields.NewDFieldFloat("f2",func()float64{ return 3.2}), + } + for i := 0; i < b.N; i++ { + for i:=0; i<8; i++ { + d[i]=flds[i].Value() + } } } +/* -func BenchmarkB (b *testing.B) { +func BenchmarkA2 (b *testing.B) { for i := 0; i < b.N; i++ { aflds.Create("f1", "value",aflds.KindString) aflds.Create("f2", uint(11),aflds.KindUint) @@ -57,7 +171,7 @@ func BenchmarkB (b *testing.B) { } } -func BenchmarkC (b *testing.B) { +func BenchmarkA3 (b *testing.B) { for i := 0; i < b.N; i++ { aflds.CreateFromValue("f1", "value") aflds.CreateFromValue("f2", 11) @@ -70,3 +184,4 @@ func BenchmarkC (b *testing.B) { } } +*/ \ No newline at end of file diff --git a/AATest/go.mod b/AATest/go.mod new file mode 100644 index 0000000..7ec0b44 --- /dev/null +++ b/AATest/go.mod @@ -0,0 +1,3 @@ +module AATest + +go 1.22 diff --git a/core/ablds/go.mod b/core/ablds/go.mod new file mode 100644 index 0000000..febbd3d --- /dev/null +++ b/core/ablds/go.mod @@ -0,0 +1,3 @@ +module ablds + +go 1.22 diff --git a/core/ablds/list_builder.go b/core/ablds/list_builder.go index fc65df4..4eb54b7 100644 --- a/core/ablds/list_builder.go +++ b/core/ablds/list_builder.go @@ -28,8 +28,8 @@ package ablds type ( ListBuilder interface { - Ender - Item () ValueBuilder + + Item () Builder } diff --git a/core/ablds/map_builder.go b/core/ablds/map_builder.go index 21a495a..64a2948 100644 --- a/core/ablds/map_builder.go +++ b/core/ablds/map_builder.go @@ -27,8 +27,6 @@ package ablds type ( MapBuilder interface { - Ender Element (key any) Builder - } ) \ No newline at end of file diff --git a/core/ablds/object_builder.go b/core/ablds/object_builder.go index 43fb8b6..225fe00 100644 --- a/core/ablds/object_builder.go +++ b/core/ablds/object_builder.go @@ -28,9 +28,7 @@ package ablds type ( ObjectBuilder interface { - Ender Field (name string) Builder - } ) diff --git a/core/acache/active.go b/core/acache/active.go new file mode 100644 index 0000000..b069bbd --- /dev/null +++ b/core/acache/active.go @@ -0,0 +1,152 @@ +// ------------------------------------------------------------------------ +// ℹ️ Project active3 +// 🔗 Active Thing (activething.com) git.activething.com/go +// +// File name active.go +// ✍️ Created by DEV +// 📅 Modified 01/05/2024 +// +// 🔒 COPYRIGHT Copyright 2024 activething.com +// +// 📜 LICENSE +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package acache + +import ( + "reflect" + "time" +) + +const( + + kindBits = 16 +) + + +var ( + G = struct { + + ErrInvalidKind ErrCode + ErrInvalidName ErrCode + ErrInvalidDeferFunc ErrCode + ErrDeferNotAllowed ErrCode + ErrFieldsReadOnly ErrCode + ErrDuplicatedField ErrCode + ErrDistinctType ErrCode + }{ + ErrInvalidKind : ErrCode("invalid-valuerKind"), + ErrInvalidName : ErrCode("invalid-field-name"), + ErrInvalidDeferFunc : ErrCode("invalid-defer-func"), + ErrDeferNotAllowed : ErrCode("defer-field-not-allow"), + ErrFieldsReadOnly : ErrCode("fields-read-only"), + ErrDuplicatedField : ErrCode("duplicate-field-name"), + ErrDistinctType : ErrCode("distinct-field-types"), + + } + + g = struct { + timeZero time.Time + reflectZero reflect.Value + + kindNames []string + + /* 🚫 DEPRECATED + constructors map[reflect.Type]func(name string, valueFn any) Field + */ + + }{ + kindNames : []string{ + "any", + "bool", + "binary", + "string", + "int", + "uint", + "float", + "time", + "duration", + "error", + "reflect", + "", + "", + "", + "defer", + }, + + /* 🚫 DEPRECATED : Tiene mejor rendimiento con el type switch, se descarta + + constructors: map[reflect.Type] func(name string, valueFn any) Field { + reflect.TypeOf(false) : func(n string, v any) Field { return NewFieldBool (n,v.(bool)) }, + reflect.TypeOf([]byte{}) : func(n string, v any) Field { return NewFieldBinary(n,v.([]byte))} , + reflect.TypeOf("") : func(n string, v any) Field { return NewFieldString(n,v.(string))}, + + reflect.TypeOf(int(0)) : func(n string, v any) Field { return NewFieldInt (n,v.(int))}, + reflect.TypeOf(int8 (0)) : func(n string, v any) Field { return NewFieldInt (n,int(v.(int8)))}, + reflect.TypeOf(int16(0)) : func(n string, v any) Field { return NewFieldInt (n,int(v.(int32)))}, + reflect.TypeOf(int32(0)) : func(n string, v any) Field { return NewFieldInt (n,int(v.(int32)))}, + reflect.TypeOf(int64(0)) : func(n string, v any) Field { return NewFieldInt (n,int(v.(int64)))}, + + reflect.TypeOf(uint (0)) : func(n string, v any) Field { return NewFieldUint (n,v.(uint))}, + reflect.TypeOf(uint8 (0)) : func(n string, v any) Field { return NewFieldUint (n,uint(v.(uint8)))}, + reflect.TypeOf(uint16(0)) : func(n string, v any) Field { return NewFieldUint (n,uint(v.(uint32)))}, + reflect.TypeOf(uint32(0)) : func(n string, v any) Field { return NewFieldUint (n,uint(v.(uint32)))}, + reflect.TypeOf(uint64(0)) : func(n string, v any) Field { return NewFieldUint (n,uint(v.(uint64)))}, + + reflect.TypeOf(float64(0)): func(n string, v any) Field { return NewFieldFloat(n,v.(float64))}, + reflect.TypeOf(float32(0)): func(n string, v any) Field { return NewFieldFloat(n,float64(v.(float32)))}, + + reflect.TypeOf(time.Time{}) : func(n string, v any) Field { return NewFieldTime(n,v.(time.Time))}, + reflect.TypeOf(time.Duration(0)): func(n string, v any) Field { return NewFieldDuration(n,v.(time.Duration))}, + + reflect.TypeOf(reflect.Value{}) : func(n string, v any) Field { return NewFieldReflect(n,v.(reflect.Value))}, + + reflect.TypeOf(func() any (nil)): func(n string, v any) Field { return NewDFieldAny (n,v.(func()any)) }, + reflect.TypeOf(func() bool (nil)): func(n string, v any) Field { return NewDFieldBool (n,v.(func()bool))}, + reflect.TypeOf(func() []byte(nil)): func(n string, v any) Field { return NewDFieldBinary(n,v.(func()[]byte))}, + reflect.TypeOf(func() string(nil)): func(n string, v any) Field { return NewDFieldString(n,v.(func()string))}, + + reflect.TypeOf(func() int (nil)): func(n string, v any) Field { return NewDFieldInt(n,v.(func()int)) } , + reflect.TypeOf(func() int8 (nil)): func(n string, v any) Field { return NewDFieldInt(n,func() int { return int(v.(func()int8)()) }) }, + reflect.TypeOf(func() int16 (nil)): func(n string, v any) Field { return NewDFieldInt(n,func() int { return int(v.(func()int16)()) }) }, + reflect.TypeOf(func() int32 (nil)): func(n string, v any) Field { return NewDFieldInt(n,func() int { return int(v.(func()int32)()) }) }, + reflect.TypeOf(func() int64 (nil)): func(n string, v any) Field { return NewDFieldInt(n,func() int { return int(v.(func()int64)()) }) }, + + reflect.TypeOf(func() uint (nil)): func(n string, v any) Field { return NewDFieldUint(n,v.(func()uint)) }, + reflect.TypeOf(func() uint8 (nil)): func(n string, v any) Field { return NewDFieldUint(n,func() uint { return uint(v.(func()uint8)()) }) }, + reflect.TypeOf(func() uint16 (nil)): func(n string, v any) Field { return NewDFieldUint(n,func() uint { return uint(v.(func()uint16)()) }) }, + reflect.TypeOf(func() uint32 (nil)): func(n string, v any) Field { return NewDFieldUint(n,func() uint { return uint(v.(func()uint32)()) }) }, + reflect.TypeOf(func() uint64 (nil)): func(n string, v any) Field { return NewDFieldUint(n,func() uint { return uint(v.(func()uint64)()) }) }, + reflect.TypeOf(func() uintptr(nil)): func(n string, v any) Field { return NewDFieldUint(n,func() uint { return uint(v.(func()uintptr)()) }) }, + + reflect.TypeOf(func() float64(nil)): func(n string, v any) Field { return NewDFieldFloat(n,v.(func()float64)) }, + reflect.TypeOf(func() float32(nil)): func(n string, v any) Field { return NewDFieldFloat(n,func()float64{ return float64(v.(func()float32)()) }) }, + reflect.TypeOf(func() error (nil)): func(n string, v any) Field { return NewDFieldError(n,v.(func()error)) }, + + reflect.TypeOf(func() time.Time (nil)): func(n string, v any) Field { return NewDFieldTime(n,v.(func()time.Time)) }, + reflect.TypeOf(func() time.Duration(nil)): func(n string, v any) Field { return NewDFieldDuration(n,v.(func()time.Duration)) }, + + reflect.TypeOf(func() reflect.Value(nil)): func(n string, v any) Field { return NewDFieldReflect(n,v.(func()reflect.Value))}, + + }, + + */ + + + } +) + + + diff --git a/core/acache/err_code.go b/core/acache/err_code.go new file mode 100644 index 0000000..5a54189 --- /dev/null +++ b/core/acache/err_code.go @@ -0,0 +1,46 @@ +// ------------------------------------------------------------------------ +// ℹ️ Project active3 +// Active Thing (activething.com) git.activething.com/go +// +// File name err_code.go +// ✍️ Created by DEV +// 📅 Modified 01/05/2024 +// +// 🔒 COPYRIGHT Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package acache + + +type ( + + ErrCode string +) + + + +func (e ErrCode) Error () string { + return string(e) } + +func (e ErrCode) Code () string { + return string(e) } + + +func (_ ErrCode) Unwrap() error { + return nil } + +func (_ ErrCode) UnwrapAll() []error { + return nil } + diff --git a/core/acache/factory.go b/core/acache/factory.go new file mode 100644 index 0000000..a1921e1 --- /dev/null +++ b/core/acache/factory.go @@ -0,0 +1,246 @@ +// ------------------------------------------------------------------------ +// ℹ️ Project active3 +// 🔗 Active Thing (activething.com) git.activething.com/go +// +// File name factory.go +// ✍️ Created by DEV +// 📅 Modified 01/05/2024 +// +// 🔒 COPYRIGHT Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package acache + +import ( + "reflect" + "time" +) + +// Create es un método que crea y devuelve un nuevo campo con el nombre, valor y tipo especificados. +// Este método es utilizado para crear campos de diferentes tipos según el valor del tipo Kind proporcionado. +// Si el tipo Kind es KindAny, el campo se crea utilizando el valor y su tipo se infiere automáticamente. +// +// Parámetros: +// - name: El nombre del campo que se va a crear. +// - valueFn: El valor del campo que se va a asignar. +// - valuerKind: El tipo de campo que se va a crear, representado por un valor de la enumeración Kind. +// Devuelve: +// - Field: El campo creado con el nombre, valor y tipo especificados. +// Pánico: +// - Si se proporciona un tipo de Kind inválido, el método entra en un estado de pánico y devuelve un error ErrInvalidKind. +func Create (name string, value any, kind Kind) Field { + if kind == 0 { + return CreateFromValue(name,value) + } + switch kind { + case KindAny : return NewFieldAny (name,value) + case KindBool : return NewFieldBool (name,value.(bool)) + case KindBinary : return NewFieldBinary(name,value.([]byte)) + case KindString : return NewFieldString(name,value.(string)) + case KindInt : return NewFieldInt (name,value.(int)) + case KindUint : return NewFieldUint (name,value.(uint)) + case KindFloat : return NewFieldFloat (name,value.(float64)) + case KindTime : return NewFieldTime (name,value.(time.Time)) + case KindDuration:return NewFieldDuration(name,value.(time.Duration)) + case KindError : return NewFieldError (name,value.(error)) + case KindReflect : return NewFieldReflect(name,value.(reflect.Value)) + + //valuerKind Fields + case KindDefer, + KindDeferAny : return NewDFieldAny (name,value.(func()any)) + case KindDeferBool : return NewDFieldBool (name,value.(func()bool)) + case KindDeferString : return NewDFieldString(name,value.(func()string)) + case KindDeferBinary : return NewDFieldBinary(name,value.(func()[]byte)) + case KindDeferInt : return NewDFieldInt (name,value.(func()int)) + case KindDeferUint : return NewDFieldUint (name,value.(func()uint)) + case KindDeferFloat : return NewDFieldFloat (name,value.(func()float64)) + case KindDeferTime : return NewDFieldTime (name,value.(func()time.Time)) + case KindDeferDuration:return NewDFieldDuration (name,value.(func()time.Duration)) + case KindDeferError : return NewDFieldError (name,value.(func()error)) + case KindDeferReflect :return NewDFieldReflect(name,value.(func()reflect.Value)) + + default: + panic(G.ErrInvalidKind) + } +} + + + + +// CreateFromValue es un método que crea y devuelve un nuevo campo basado en el valor proporcionado. +// Examina el tipo del valor y crea un campo correspondiente, asignando el nombre especificado. +// Si el tipo del valor no coincide con ninguno de los tipos predefinidos, se crea un campo genérico utilizando el tipo KindAny. +// +// Parámetros: +// - name: El nombre del campo que se va a crear. +// - valueFn: El valor del campo que se va a asignar. +// Devuelve: +// - Field: El campo creado con el nombre y valor especificados. +func CreateFromValue(name string, value any) Field { + switch t := value.(type) { + + case bool : return NewFieldBool (name,t) + case []byte : return NewFieldBinary (name,t) + case string : return NewFieldString (name,t) + + case int : return NewFieldInt (name,t) + case int8 : return NewFieldInt (name,int(t)) + case int16 : return NewFieldInt (name,int(t)) + case int32 : return NewFieldInt (name,int(t)) + case int64 : return NewFieldInt (name,int(t)) + + case uint : return NewFieldUint (name,t) + case uint8 : return NewFieldUint (name,uint(t)) + case uint16 : return NewFieldUint (name,uint(t)) + case uint32 : return NewFieldUint (name,uint(t)) + case uint64 : return NewFieldUint (name,uint(t)) + case uintptr: return NewFieldUint (name,uint(t)) + + case float64: return NewFieldFloat(name,t) + case float32: return NewFieldFloat(name,float64(t)) + + case error : return NewFieldError(name,t) + case time.Time: + return NewFieldTime (name,t) + case time.Duration: + return NewFieldDuration (name,t) + case reflect.Value : + return NewFieldReflect(name,t) + + case func() any : return NewDFieldAny (name,t) + case func() bool : return NewDFieldBool(name,t) + + case func() []byte : return NewDFieldBinary(name,t) + case func() string : return NewDFieldString(name,t) + + case func() int : return NewDFieldInt (name,t) + case func() int8 : return NewDFieldInt (name,func() int { return int(t()) }) + case func() int16 : return NewDFieldInt (name,func() int { return int(t()) }) + case func() int32 : return NewDFieldInt (name,func() int { return int(t()) }) + case func() int64 : return NewDFieldInt (name,func() int { return int(t()) }) + + case func() uint : return NewDFieldUint(name,t) + case func() uint8 : return NewDFieldUint(name,func() uint { return uint(t()) }) + case func() uint16 : return NewDFieldUint(name,func() uint { return uint(t()) }) + case func() uint32 : return NewDFieldUint(name,func() uint { return uint(t()) }) + case func() uint64 : return NewDFieldUint(name,func() uint { return uint(t()) }) + case func() uintptr: return NewDFieldUint(name,func() uint { return uint(t()) }) + + case func() float64: return NewDFieldFloat(name,t) + case func() float32: return NewDFieldFloat(name,func() float64 { return float64(t()) }) + + case func() error : return NewDFieldError(name,t) + + case func() time.Time : + return NewDFieldTime(name,t) + case func() time.Duration : + return NewDFieldDuration(name,t) + case func() reflect.Value : + return NewDFieldReflect(name,t) + + default: + if value != nil { + rv := reflect.ValueOf(value) + if rv.Kind() == reflect.Func { + tp := rv.Type() + if tp.NumIn() == 0 && tp.NumOut() == 1 { + return NewDFieldAny(name, func() any { + return rv.Call(nil)[0].Interface() + }) + } + } + } + return NewFieldAny(name,value) + } +} + + +// TypeToKind es una función que determina el tipo de Kind correspondiente al valor proporcionado. +// Examina el tipo del valor y devuelve un tipo Kind adecuado que representa el tipo del valor. +// Si el valor es una función, el tipo Kind resultante tendrá la bandera KindDefer para indicar que es una función deferida. +// +// Parámetros: +// - valueFn: El valor del cual se determinará el tipo Kind. +// Devuelve: +// - Kind: El tipo Kind correspondiente al valor proporcionado. +func TypeToKind(value any) Kind { + switch value.(type) { + case bool: + return KindAny + case []byte : + return KindBinary + case string : + return KindString + case int, + int8, + int16, + int32, + int64 : + return KindInt + case uint, + uint8, + uint16, + uint32, + uint64, + uintptr : return KindUint + case float64, + float32: + return KindFloat + case error : + return KindError + case time.Time: + return KindTime + case reflect.Value: + return KindReflect + + case func() any : + return KindAny|KindDefer + case func() bool : + return KindBool|KindDefer + case func() []byte : + return KindBinary|KindDefer + case func() string : + return KindString|KindDefer + case func() int, + func() int8, + func() int16, + func() int32, + func() int64 : + return KindInt|KindDefer + case func() uint, + func() uint8, + func() uint16, + func() uint32, + func() uint64, + func() uintptr : + return KindInt|KindDefer + case func() float64, + func() float32 : + return KindFloat|KindDefer + case func() error : + return KindError|KindDefer + case func() time.Time: + return KindTime|KindDefer + case func() reflect.Value: + return KindReflect|KindDefer + + default: + rt := reflect.TypeOf(value) + if rt.Kind() == reflect.Func && rt.NumIn() == 0 && rt.NumOut() == 1 { + return KindAny|KindDefer + } + return KindAny + } +} diff --git a/core/acache/field.go b/core/acache/field.go new file mode 100644 index 0000000..2094210 --- /dev/null +++ b/core/acache/field.go @@ -0,0 +1,70 @@ +// ------------------------------------------------------------------------ +// ℹ️ Project active3 +// Active Thing (activething.com) git.activething.com/go +// +// File name field.go +// ✍️ Created by DEV +// 📅 Modified 01/05/2024 +// +// 🔒 COPYRIGHT Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package acache + +import "ablds" + +type ( + + Field interface { + NativeResolver + + Kind () Kind + Name () string + Value() any + } + +) + + +func FieldAsBuildable (field Field) ablds.BuildFnc { + return func (b ablds.Builder) { + buildFieldAsObject(field,b) + } +} + +func buildFieldAsObject (field Field, builder ablds.Builder) { + builder.Object(func(ob ablds.ObjectBuilder){ + buildFieldAsField(field,ob) + }) +} + +func buildFieldAsField (field Field, obuilder ablds.ObjectBuilder) { + vb := obuilder.Field(field.Name()) + switch field.Kind() { + case KindAny : vb.Any (field.Value()) + case KindBool : v,_ := field.Bool(); vb.Bool(v) + case KindBinary : v,_ := field.Binary(); vb.Binary(v) + case KindString : v,_ := field.String(); vb.String(v) + case KindInt : v,_ := field.Int(); vb.Int(v) + case KindUint : v,_ := field.Uint(); vb.Uint(v) + case KindFloat : v,_ := field.Float(); vb.Float64(v) + case KindTime : v,_ := field.Time(); vb.Time(v) + case KindDuration: v,_ := field.Duration(); vb.Duration(v) + case KindError : v,_ := field.Error(); vb.Error(v) + case KindReflect : v,_ := field.Reflect(); vb.Reflect(v) + default: + vb.Any(field.Value()) + } +} \ No newline at end of file diff --git a/core/acache/field_any.go b/core/acache/field_any.go new file mode 100644 index 0000000..4e1f499 --- /dev/null +++ b/core/acache/field_any.go @@ -0,0 +1,148 @@ +// ------------------------------------------------------------------------ +// ℹ️ Project active3 +// Active Thing (activething.com) git.activething.com/go +// +// File name field_any.go +// ✍️ Created by DEV +// 📅 Modified 01/05/2024 +// +// 🔒 COPYRIGHT Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package acache + +import ( + "ablds" + "reflect" + "time" +) + +type ( + + FieldAny struct { + partialField + valuerMode + valueFn func() any + } +) + + +func NewFieldAny (name string, value any) *FieldAny { + return &FieldAny{ + partialField : makePartialField(name), + valuerMode: localValuer{}, + valueFn : func() any { return value }, + } +} + + +func NewDFieldAny (name string, valueFn func() any) *FieldAny { + if valueFn == nil { + panic(G.ErrInvalidDeferFunc) + } + return &FieldAny{ + partialField: makePartialField(name), + valuerMode: deferValuer{}, + valueFn : valueFn, + } +} + + +func (f FieldAny) Kind() Kind { + return KindAny | f.valuerKind() } + + +func (f FieldAny) Value() any { + return f.valueFn() } + + + + +func (f FieldAny) Bool () (bool,bool) { + v,ok := f.valueFn().(bool) + return v,ok +} + +func (f FieldAny) Binary () ([]byte,bool) { + v, ok := f.valueFn().([]byte) + return v, ok +} + +func (f FieldAny) String () (string,bool) { + v,ok := f.valueFn().(string) + return v,ok +} + +func (f FieldAny) Int () (int,bool) { + switch t := f.valueFn().(type) { + case int : return t,true + case int8 : return int(t),true + case int16: return int(t),true + case int32: return int(t),true + case int64: return int(t),true + default : return 0,false + } +} + +func (f FieldAny) Uint () (uint,bool) { + switch t := f.valueFn().(type) { + case uint : return t,true + case uint8 : return uint(t),true + case uint16: return uint(t),true + case uint32: return uint(t),true + case uint64: return uint(t),true + default : return 0,false + } +} + +func (f FieldAny) Float () (float64,bool) { + v, ok := f.valueFn().(float64) + if !ok { + var f32 float32 + if f32,ok = f.valueFn().(float32); ok { + v = float64(f32) + } + } + return v, ok +} + + +func (f FieldAny) Date () (time.Time,bool) { + v, ok := f.valueFn().(time.Time) + return v, ok +} + +func (f FieldAny) Time () (time.Time,bool) { + v, ok := f.valueFn().(time.Time) + return v, ok +} + + +func (f FieldAny) Error () (error,bool) { + v, ok := f.valueFn().(error) + return v, ok +} + + +func (f FieldAny) Reflect () (reflect.Value,bool) { + v, ok := f.valueFn().(reflect.Value) + return v, ok +} + + + +func (f FieldAny) Build (builder ablds.Builder) { + builder.Object(func(b ablds.ObjectBuilder){ + b.Field(f.name).Any(f.valueFn()) }) } \ No newline at end of file diff --git a/core/acache/field_binary.go b/core/acache/field_binary.go new file mode 100644 index 0000000..92b8b10 --- /dev/null +++ b/core/acache/field_binary.go @@ -0,0 +1,73 @@ +// ------------------------------------------------------------------------ +// ℹ️ Project active3 +// Active Thing (activething.com) git.activething.com/go +// +// File name field_binary.go +// ✍️ Created by DEV +// 📅 Modified 01/05/2024 +// +// 🔒 COPYRIGHT Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package acache + +import "ablds" + +type ( + + FieldBinary struct { + partialField + valuerMode + valueFn func()[]byte + } +) + +func NewFieldBinary (name string, value []byte) *FieldBinary { + return &FieldBinary{ + partialField: makePartialField(name), + valuerMode: localValuer{}, + valueFn: func()[]byte { return value }, + } +} + + +func NewDFieldBinary (name string, valueFn func() []byte) *FieldBinary { + if valueFn == nil { + panic(G.ErrInvalidDeferFunc) + } + return &FieldBinary { + partialField: makePartialField(name), + valuerMode: deferValuer{}, + valueFn : valueFn, + } +} + + + +func (f FieldBinary) Kind () Kind { + return KindBinary | f.valuerKind() } + +func (f FieldBinary) Value() any { + return f.valueFn +} + + +func (f FieldBinary) Binary() ([]byte,bool) { + return f.valueFn(),true } + + +func (f FieldBinary) Build (builder ablds.Builder) { + builder.Object(func(b ablds.ObjectBuilder){ + b.Field(f.name).Binary(f.valueFn()) }) } \ No newline at end of file diff --git a/core/acache/field_bool.go b/core/acache/field_bool.go new file mode 100644 index 0000000..58c888f --- /dev/null +++ b/core/acache/field_bool.go @@ -0,0 +1,73 @@ +// ------------------------------------------------------------------------ +// ℹ️ Project active3 +// Active Thing (activething.com) git.activething.com/go +// +// File name field_bool.go +// ✍️ Created by DEV +// 📅 Modified 01/05/2024 +// +// 🔒 COPYRIGHT Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package acache + +import "ablds" + +type ( + + FieldBool struct { + partialField + valuerMode + valueFn func() bool + } +) + +func NewFieldBool (name string, value bool) *FieldBool { + return &FieldBool{ + partialField: makePartialField(name), + valuerMode: localValuer{}, + valueFn : func() bool { return value }, + } +} + + +func NewDFieldBool (name string, valueFn func() bool) *FieldBool { + if valueFn == nil { + panic(G.ErrInvalidDeferFunc) + } + return &FieldBool{ + partialField: makePartialField(name), + valuerMode: deferValuer{}, + valueFn : valueFn, + } +} + + + +func (f FieldBool) Kind () Kind { + return KindBool | f.valuerKind() } + +func (f FieldBool) Value() any { + return f.valueFn +} + + +func (f FieldBool) Bool() (bool,bool) { + return f.valueFn(),true } + + +func (f FieldBool) Build (builder ablds.Builder) { + builder.Object(func(b ablds.ObjectBuilder){ + b.Field(f.name).Bool(f.valueFn()) }) } \ No newline at end of file diff --git a/core/acache/field_duration.go b/core/acache/field_duration.go new file mode 100644 index 0000000..ed63285 --- /dev/null +++ b/core/acache/field_duration.go @@ -0,0 +1,76 @@ +// ------------------------------------------------------------------------ +// ℹ️ Project active3 +// Active Thing (activething.com) git.activething.com/go +// +// File name field_time.go +// ✍️ Created by DEV +// 📅 Modified 01/05/2024 +// +// 🔒 COPYRIGHT Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package acache + +import ( + "ablds" + "time" +) + +type ( + + FieldDuration struct { + partialField + valuerMode + valueFn func () time.Duration + } +) + +func NewFieldDuration (name string, value time.Duration) *FieldDuration { + return &FieldDuration{ + partialField: makePartialField(name), + valuerMode: localValuer{}, + valueFn: func() time.Duration { return value }, + } +} + + +func NewDFieldDuration (name string, valueFn func() time.Duration) *FieldDuration { + if valueFn == nil { + panic(G.ErrInvalidDeferFunc) + } + return &FieldDuration{ + partialField: makePartialField(name), + valuerMode: deferValuer{}, + valueFn : valueFn, + } +} + + + +func (f FieldDuration) Kind () Kind { + return KindDuration | f.valuerKind() } + +func (f FieldDuration) Value() any { + return f.valueFn +} + + +func (f FieldDuration) Duration() (time.Duration,bool) { + return f.valueFn(),true } + + +func (f FieldDuration) Build (builder ablds.Builder) { + builder.Object(func(b ablds.ObjectBuilder){ + b.Field(f.name).Duration(f.valueFn()) }) } \ No newline at end of file diff --git a/core/acache/field_error.go b/core/acache/field_error.go new file mode 100644 index 0000000..c8b83d2 --- /dev/null +++ b/core/acache/field_error.go @@ -0,0 +1,73 @@ +// ------------------------------------------------------------------------ +// ℹ️ Project active3 +// Active Thing (activething.com) git.activething.com/go +// +// File name field_error.go +// ✍️ Created by DEV +// 📅 Modified 01/05/2024 +// +// 🔒 COPYRIGHT Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package acache + +import "ablds" + +type ( + + FieldError struct { + partialField + valuerMode + valueFn func() error + } +) + + +func NewFieldError (name string, value error) *FieldError { + return &FieldError{ + partialField: makePartialField(name), + valuerMode: localValuer{}, + valueFn: func() error { return value }, + } +} + + +func NewDFieldError (name string, valueFn func() error) *FieldError { + if valueFn == nil { + panic(G.ErrInvalidDeferFunc) + } + return &FieldError{ + partialField: makePartialField(name), + valuerMode : deferValuer{}, + valueFn : valueFn, + } +} + + +func (f FieldError) Kind () Kind { + return KindError | f.valuerKind() } + +func (f FieldError) Value() any { + return f.valueFn +} + + +func (f FieldError) Error() (error,bool) { + return f.valueFn(),true } + + +func (f FieldError) Build (builder ablds.Builder) { + builder.Object(func(b ablds.ObjectBuilder){ + b.Field(f.name).Error(f.valueFn()) }) } \ No newline at end of file diff --git a/core/acache/field_float.go b/core/acache/field_float.go new file mode 100644 index 0000000..8824da4 --- /dev/null +++ b/core/acache/field_float.go @@ -0,0 +1,70 @@ +// ------------------------------------------------------------------------ +// ℹ️ Project active3 +// Active Thing (activething.com) git.activething.com/go +// +// File name field_float.go +// ✍️ Created by DEV +// 📅 Modified 01/05/2024 +// +// 🔒 COPYRIGHT Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package acache + +import "ablds" + +type ( + + FieldFloat struct { + partialField + valuerMode + valueFn func() float64 + } +) + +func NewFieldFloat (name string, value float64) *FieldFloat { + return &FieldFloat{ + partialField: makePartialField(name), + valuerMode : localValuer{}, + valueFn : func() float64 { return value }, + } +} + +func NewDFieldFloat (name string, valueFn func()float64) *FieldFloat { + if valueFn == nil { + panic(G.ErrInvalidDeferFunc) + } + return &FieldFloat{ + partialField: makePartialField(name), + valuerMode : deferValuer{}, + valueFn : valueFn } } + + +func (f FieldFloat) Kind () Kind { + return KindFloat | f.valuerKind() } + +func (f FieldFloat) Value() any { + return f.valueFn() +} + +func (f FieldFloat) Float() (float64,bool) { + return f.valueFn(),true } + + +func (f FieldFloat) Build (builder ablds.Builder) { + builder.Object(func(b ablds.ObjectBuilder){ + b.Field(f.name).Float64(f.valueFn()) + }) +} \ No newline at end of file diff --git a/core/acache/field_int.go b/core/acache/field_int.go new file mode 100644 index 0000000..ed6e18a --- /dev/null +++ b/core/acache/field_int.go @@ -0,0 +1,74 @@ +// ------------------------------------------------------------------------ +// ℹ️ Project active3 +// Active Thing (activething.com) git.activething.com/go +// +// File name field_int.go +// ✍️ Created by DEV +// 📅 Modified 01/05/2024 +// +// 🔒 COPYRIGHT Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package acache + +import "ablds" + +type ( + + FieldInt struct { + partialField + valuerMode + valueFn func()int + } +) + +func NewFieldInt (name string, value int) *FieldInt { + return &FieldInt{ + partialField: makePartialField(name), + valuerMode : deferValuer{}, + valueFn : func() int { return value }, + } +} + + +func NewDFieldInt (name string, valueFn func()int) *FieldInt { + if valueFn == nil { + panic(G.ErrInvalidDeferFunc) + } + return &FieldInt{ + partialField: makePartialField(name), + valuerMode : deferValuer{}, + valueFn : valueFn, + } +} + + + +func (f FieldInt) Kind () Kind { + return KindInt | f.valuerKind() } + +func (f FieldInt) Value() any { + return f.valueFn() } + + +func (f FieldInt) Int() (int,bool) { + return f.valueFn(),true } + + + +func (f FieldInt) Build (builder ablds.Builder) { + builder.Object(func(b ablds.ObjectBuilder){ + b.Field(f.name).Int(f.valueFn()) }) } + diff --git a/core/acache/field_reflect.go b/core/acache/field_reflect.go new file mode 100644 index 0000000..dd59796 --- /dev/null +++ b/core/acache/field_reflect.go @@ -0,0 +1,76 @@ +// ------------------------------------------------------------------------ +// ℹ️ Project active3 +// Active Thing (activething.com) git.activething.com/go +// +// File name field_reflect.go +// ✍️ Created by DEV +// 📅 Modified 01/05/2024 +// +// 🔒 COPYRIGHT Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package acache + +import ( + "ablds" + "reflect" +) + +type ( + + FieldReflect struct { + partialField + valuerMode + valueFn func() reflect.Value + } +) + +func NewFieldReflect (name string, value reflect.Value) *FieldReflect { + return &FieldReflect{ + partialField: makePartialField(name), + valuerMode : localValuer{}, + valueFn : func() reflect.Value { return value }, + } +} + + +func NewDFieldReflect (name string, valueFn func()reflect.Value) *FieldReflect { + if valueFn == nil { + panic(G.ErrInvalidDeferFunc) + } + return &FieldReflect{ + partialField: makePartialField(name), + valuerMode : deferValuer{}, + valueFn : valueFn , + } +} + + + +func (f FieldReflect) Kind () Kind { + return KindReflect | f.valuerKind() } + +func (f FieldReflect) Value() any { + return f.valueFn() } + + +func (f FieldReflect) Reflect() (reflect.Value,bool) { + return f.valueFn(),true } + + + +func (f FieldReflect) Build (builder ablds.Builder) { + builder.Object(func(b ablds.ObjectBuilder){ + b.Field(f.name).Reflect(f.valueFn()) }) } \ No newline at end of file diff --git a/core/acache/field_strings.go b/core/acache/field_strings.go new file mode 100644 index 0000000..a03b61e --- /dev/null +++ b/core/acache/field_strings.go @@ -0,0 +1,74 @@ +// ------------------------------------------------------------------------ +// ℹ️ Project active3 +// Active Thing (activething.com) git.activething.com/go +// +// File name field_string.go +// ✍️ Created by DEV +// 📅 Modified 01/05/2024 +// +// 🔒 COPYRIGHT Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package acache + +import "ablds" + +type ( + + FieldString struct { + partialField + valuerMode + valueFn func() string + } +) + +func NewFieldString (name string, value string) *FieldString { + return &FieldString{ + partialField: makePartialField(name), + valuerMode: localValuer{}, + valueFn: func() string { return value }, + } +} + +func NewDFieldString (name string, valueFn func()string) *FieldString { + if valueFn == nil { + panic(G.ErrInvalidDeferFunc) + } + return &FieldString{ + partialField: makePartialField(name), + valuerMode : deferValuer{}, + valueFn : valueFn , + } +} + + + +func (f FieldString) Kind () Kind { + return KindString | f.valuerKind() } + +func (f FieldString) Value() any { + return f.valueFn() } + + +func (f FieldString) String() (string,bool) { + return f.valueFn(),true } + + +func (f FieldString) Build (builder ablds.Builder) { + builder.Object(func(b ablds.ObjectBuilder){ + b.Field(f.name).String(f.valueFn()) + }) +} + diff --git a/core/acache/field_time.go b/core/acache/field_time.go new file mode 100644 index 0000000..d1a7764 --- /dev/null +++ b/core/acache/field_time.go @@ -0,0 +1,76 @@ +// ------------------------------------------------------------------------ +// ℹ️ Project active3 +// Active Thing (activething.com) git.activething.com/go +// +// File name field_time.go +// ✍️ Created by DEV +// 📅 Modified 01/05/2024 +// +// 🔒 COPYRIGHT Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package acache + +import ( + "ablds" + "time" +) + +type ( + + FieldTime struct { + partialField + valuerMode + valueFn func() time.Time + } +) + +func NewFieldTime (name string, value time.Time) *FieldTime { + return &FieldTime{ + partialField: makePartialField(name), + valuerMode: localValuer{}, + valueFn: func() time.Time { return value }, + } +} + + +func NewDFieldTime(name string, valueFn func()time.Time) *FieldTime { + if valueFn == nil { + panic(G.ErrInvalidDeferFunc) + } + return &FieldTime{ + partialField: makePartialField(name), + valuerMode : deferValuer{}, + valueFn : valueFn , + } +} + + + +func (f FieldTime) Kind () Kind { + return KindTime | f.valuerKind() } + +func (f FieldTime) Value() any { + return f.valueFn() } + + +func (f FieldTime) Time() (time.Time,bool) { + return f.valueFn(),true } + + + +func (f FieldTime) Build (builder ablds.Builder) { + builder.Object(func(b ablds.ObjectBuilder){ + b.Field(f.name).Time(f.valueFn()) }) } \ No newline at end of file diff --git a/core/acache/field_uint.go b/core/acache/field_uint.go new file mode 100644 index 0000000..919d08c --- /dev/null +++ b/core/acache/field_uint.go @@ -0,0 +1,73 @@ +// ------------------------------------------------------------------------ +// ℹ️ Project active3 +// Active Thing (activething.com) git.activething.com/go +// +// File name field_unuint.go +// ✍️ Created by DEV +// 📅 Modified 01/05/2024 +// +// 🔒 COPYRIGHT Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package acache + +import "ablds" + +type ( + + FieldUint struct { + partialField + valuerMode + valueFn func() uint + } +) + +func NewFieldUint (name string, value uint) *FieldUint { + return &FieldUint{ + partialField: makePartialField(name), + valuerMode: localValuer{}, + valueFn: func() uint { return value }, + } +} + + +func NewDFieldUint (name string, valueFn func()uint) *FieldUint { + if valueFn == nil { + panic(G.ErrInvalidDeferFunc) + } + return &FieldUint{ + partialField: makePartialField(name), + valuerMode : deferValuer{}, + valueFn : valueFn , + } +} + + + +func (f FieldUint) Kind () Kind { + return KindInt | f.valuerKind() } + +func (f FieldUint) Value() any { + return f.valueFn() } + + +func (f FieldUint) Uint() (uint,bool) { + return f.valueFn(),true } + + +func (f FieldUint) Build (builder ablds.Builder) { + builder.Object(func(b ablds.ObjectBuilder){ + b.Field(f.name).Uint(f.valueFn()) }) } + diff --git a/core/acache/fields.go b/core/acache/fields.go new file mode 100644 index 0000000..6276d26 --- /dev/null +++ b/core/acache/fields.go @@ -0,0 +1,143 @@ +// ------------------------------------------------------------------------ +// ℹ️ Project active3 +// Active Thing (activething.com) git.activething.com/go +// +// File name fields.go +// ✍️ Created by DEV +// 📅 Modified 01/05/2024 +// +// 🔒 COPYRIGHT Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package acache + +import ( + "ablds" + "sort" +) + +type ( + + // Fields es un tipo que representa una lista de campos y proporciona métodos + // para gestionar y manipular dicha lista. + Fields []Field + +) + + + +func (f Fields) Len () int { + return len(f) } + +func (f Fields) Has (name string) bool { + return f.indexOf(name) != -1 } + + +func (f Fields) Kinds() Kind { + var k Kind + for _,f := range f { + k|=f.Kind() + } + return k +} + +func (f Fields) Get(name string) Field { + if p := f.indexOf(name); p != -1 { + return f[p] + } + return nil +} + + +func (f Fields) GetAll (name string) []Field { + var ls []Field + for _,fl := range f { + if fl.Name() == name { + ls = append(ls,fl) + } + } + return ls +} + + + + +func (f Fields) Add(field Field) Fields { + if field != nil { + return append(f,field) + } + return f +} + +func (f Fields) Set(field Field) Fields { + if field == nil { + return f + } + if p := f.indexOf(field.Name()); p != -1 { + return append(append(f[:p],field), f[p+1:]...) + } + return append(f,field) +} + +func (f Fields) Del(name string) Fields { + if p := f.indexOf(name); p != -1 { + return append(f[:p],f[p+1:]...) + } + return f +} + +func (f Fields) DelAll (name string) Fields { + l := make(Fields,0,len(f)) + c := 0 + for i := 0; i