diff --git a/app/main.go b/app/main.go index d640d1e..59feed2 100644 --- a/app/main.go +++ b/app/main.go @@ -2,12 +2,11 @@ package main import ( "alogs" - "context" "errs" "fmt" "mems" "os" - "time" + "vals/flds" ) @@ -57,9 +56,26 @@ func Append2 (_ *alogs.Entry) error { func main() { + + var fs flds.SFields + + fs = fs.AddField(flds.NewSFieldSigned("Z",1)) + fs = fs.AddField(flds.NewSFieldSigned("a",1)) + fs = fs.AddField(flds.NewSFieldSigned("m",1)) + fs = fs.AddField(flds.NewSFieldSigned("b",1)) + + fs.Sort() + + for i:= 0; i 0,true } func (f AField) String () (string,bool) { - if f.hp != -1 || f.fs.heads[f.hp].kind != KindString { + if f.hp != -1 || f.fs.heads[f.hp].kind != flds.KindString { return "",false } return f.fs.strings[f.fs.heads[f.hp].pos],true } func (f AField) Signed () (int,bool) { - if f.hp != -1 || f.fs.heads[f.hp].kind != KindSigned { + if f.hp != -1 || f.fs.heads[f.hp].kind != flds.KindSigned { return 0,false } return f.fs.nums[f.fs.heads[f.hp].pos],true } func (f AField) Unsigned () (uint,bool) { - if f.hp != -1 || f.fs.heads[f.hp].kind != KindUnsigned { + if f.hp != -1 || f.fs.heads[f.hp].kind != flds.KindUnsigned { return 0,false } return uint(f.fs.nums[f.fs.heads[f.hp].pos]),true @@ -101,7 +104,7 @@ func (f AField) Unsigned () (uint,bool) { func (f AField) Date () (time.Time,bool) { - if f.hp != -1 || f.fs.heads[f.hp].kind != KindDate { + if f.hp != -1 || f.fs.heads[f.hp].kind != flds.KindDate { var z time.Time return z,false } @@ -109,7 +112,7 @@ func (f AField) Date () (time.Time,bool) { } func (f AField) Time () (time.Time,bool) { - if f.hp != -1 || f.fs.heads[f.hp].kind != KindTime { + if f.hp != -1 || f.fs.heads[f.hp].kind != flds.KindTime { var z time.Time return z,false } @@ -117,14 +120,14 @@ func (f AField) Time () (time.Time,bool) { } func (f AField) Error () (error,bool) { - if f.hp != -1 || f.fs.heads[f.hp].kind != KindError { + if f.hp != -1 || f.fs.heads[f.hp].kind != flds.KindError { return nil,false } return f.fs.anys[f.fs.heads[f.hp].pos].(error),true } func (f AField) Binary () ([]byte,bool) { - if f.hp != -1 || f.fs.heads[f.hp].kind != KindBinary { + if f.hp != -1 || f.fs.heads[f.hp].kind != flds.KindBinary { return nil,false } return f.fs.binaries[f.fs.heads[f.hp].pos],true diff --git a/core/vals/flds/afields.go b/core/vals/flds/_deprecated/afields.go similarity index 79% rename from core/vals/flds/afields.go rename to core/vals/flds/_deprecated/afields.go index 89808e1..197095c 100644 --- a/core/vals/flds/afields.go +++ b/core/vals/flds/_deprecated/afields.go @@ -21,19 +21,20 @@ // limitations under the License. // ------------------------------------------------------------------------ -package flds +package _deprecated import ( "fmt" "sort" "time" + "vals/flds" ) type ( AFields struct { heads []head - kinds Kind + kinds flds.Kind anys []any nums []int @@ -50,14 +51,14 @@ type ( func AcquireAFields (options ...AFieldsFnc) *AFields { - return g.pool.Get().init(options) } + return flds.g.pool.Get().init(options) } func ReleaseAFields (fields *AFields) { if fields == nil { return } - g.pool.Put(fields.Reset()) + flds.g.pool.Put(fields.Reset()) } @@ -99,12 +100,12 @@ func (f *AFields) Reset() *AFields { } -func (f *AFields) Kinds() Kind { +func (f *AFields) Kinds() flds.Kind { return f.kinds } func (f *AFields) GetField (name string) AField { - return AField { + return AField{ fs: f, hp: f.has(name), } @@ -150,46 +151,46 @@ func (f *AFields) AddAny (name string, value any) { case []byte : f.AddBinary(name,t) case time.Time: f.AddDate(name,t) default: - f.addField(name,KindAny,len(f.anys)).anys = append(f.anys, value) + f.addField(name, flds.KindAny,len(f.anys)).anys = append(f.anys, value) } } func (f *AFields) AddError(name string, value error) { - f.addField(name,KindError,len(f.anys)).anys = append(f.anys,value) } + f.addField(name, flds.KindError,len(f.anys)).anys = append(f.anys,value) } func (f *AFields) AddBool (name string, value bool) { v := 0 if value { v=1 } - f.addField(name,KindBool,len(f.nums)).nums = append(f.nums,v) + f.addField(name, flds.KindBool,len(f.nums)).nums = append(f.nums,v) } func (f *AFields) AddSigned (name string, value int) { - f.addField(name,KindSigned,len(f.nums)).nums = append(f.nums,value) } + f.addField(name, flds.KindSigned,len(f.nums)).nums = append(f.nums,value) } func (f *AFields) AddUnsigned(name string, value uint) { - f.addField(name,KindUnsigned,len(f.nums)).nums = append(f.nums,int(value)) } + f.addField(name, flds.KindUnsigned,len(f.nums)).nums = append(f.nums,int(value)) } func (f *AFields) AddFloat(name string, value float64) { - f.addField(name,KindFloat,len(f.floats)).floats = append(f.floats,value) } + f.addField(name, flds.KindFloat,len(f.floats)).floats = append(f.floats,value) } func (f *AFields) AddDate (name string, value time.Time) { - f.addField(name,KindDate,len(f.dates)).dates = append(f.dates,value) } + f.addField(name, flds.KindDate,len(f.dates)).dates = append(f.dates,value) } func (f *AFields) AddTime (name string, value time.Time) { - f.addField(name,KindTime,len(f.dates)).dates = append(f.dates,value) } + f.addField(name, flds.KindTime,len(f.dates)).dates = append(f.dates,value) } func (f *AFields) AddString(name string, value string) { - f.addField(name,KindString,len(f.strings)).strings = append(f.strings,value) } + f.addField(name, flds.KindString,len(f.strings)).strings = append(f.strings,value) } func (f *AFields) AddBinary(name string, value []byte) { - f.addField(name,KindBinary,len(f.binaries)).binaries = append(f.binaries,value) } + f.addField(name, flds.KindBinary,len(f.binaries)).binaries = append(f.binaries,value) } -func (f *AFields) addField (name string, kind Kind, pos int) *AFields { +func (f *AFields) addField (name string, kind flds.Kind, pos int) *AFields { for i:=1; f.has(name) == -1; i++ { name = fmt.Sprintf("fmtNameDuplicated",name,i) } diff --git a/core/vals/flds/heads.go b/core/vals/flds/_deprecated/heads.go similarity index 94% rename from core/vals/flds/heads.go rename to core/vals/flds/_deprecated/heads.go index 042655e..323ae4e 100644 --- a/core/vals/flds/heads.go +++ b/core/vals/flds/_deprecated/heads.go @@ -21,14 +21,15 @@ // limitations under the License. // ------------------------------------------------------------------------ -package flds +package _deprecated +import "vals/flds" type ( head struct { name string - kind Kind + kind flds.Kind pos int } ) diff --git a/core/vals/flds/active.go b/core/vals/flds/active.go index 4cbe0cc..152046b 100644 --- a/core/vals/flds/active.go +++ b/core/vals/flds/active.go @@ -23,24 +23,54 @@ package flds -import "syncs/pools" +const( + + kindBits = 16 +) var ( G = struct { - - + ErrInvalidName ErrField + ErrDuplicateField ErrField } { + ErrInvalidName : ErrField("invalid-field-name"), + ErrDuplicateField : ErrField("duplicated-field-name"), } g = struct { - - pool pools.GPool[AFields] + kindNames []string + //pool pools.GPool[_deprecated.AFields] } { - pool : *pools.NewGPool[AFields](pools.WithNew(newAFields)), + //pool : *pools.NewGPool[_deprecated.AFields](pools.WithNew(_deprecated.newAFields)), + kindNames : []string{ + "any", + "bool", + "signed", + "unsigned", + "float", + "string", + "date", + "time", + "binary", + "error", + "reflect", + "defer", + }, + } + +) + + +/* deprecated +func checkFieldName (name string) bool { + if name == "" { + panic(G.ErrInvalidName) } + return true +} -) \ No newline at end of file + */ \ No newline at end of file diff --git a/core/vals/flds/err_field.go b/core/vals/flds/err_field.go new file mode 100644 index 0000000..00c643d --- /dev/null +++ b/core/vals/flds/err_field.go @@ -0,0 +1,44 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name err_field.go +// Created by DEV +// Modified 30/04/2024 +// +// 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 flds + +type ( + + // ErrField no puede heredar directamente de Errs.Code + // ya que es utilizada por dependencias usadas por Errs + // + ErrField string +) + + +func (e ErrField) Error() string { + return string(e) } + + +func (e ErrField) Code () string { + return string(e) } + + + + diff --git a/core/vals/flds/kind.go b/core/vals/flds/kind.go index e0c5fce..1a05976 100644 --- a/core/vals/flds/kind.go +++ b/core/vals/flds/kind.go @@ -23,6 +23,10 @@ package flds +import ( + "math/bits" +) + const( KindAny Kind = 1 << iota @@ -35,12 +39,16 @@ const( KindTime KindBinary KindError + KindReflect + KindDefer + + ) type ( - Kind uint8 + Kind uint16 ) @@ -74,15 +82,47 @@ func (k Kind) IsBinary() bool { func (k Kind) IsError() bool { return k&KindError != 0 } - - - - - - - - - +func (k Kind) IsReflect() bool { + return k&KindReflect != 0 } + + +func (k Kind) IsDefer() bool { + return k&KindDefer != 0 } + + + +func (k Kind) Count () int { + return bits.OnesCount16(uint16(k)) } + +func (k Kind) Kinds () []Kind { + if k == 0 { + return nil + } + var ls []Kind + c := Kind(1) + for i:=0; i< kindBits; i++ { + c = 1 << i + if c&k != 0 { + ls = append(ls,c) + } + } + return ls +} + +func (k Kind) KindNames () []string { + if k==0 { + return []string{""} + } + var ls []string + c := Kind(1) + for i:=0; i< kindBits; i++ { + c = 1 << i + if c&k != 0 { + ls = append(ls,g.kindNames[i]) + } + } + return ls +} diff --git a/core/vals/flds/part_sfield.go b/core/vals/flds/part_sfield.go new file mode 100644 index 0000000..3bce6a9 --- /dev/null +++ b/core/vals/flds/part_sfield.go @@ -0,0 +1,74 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name sfield.go +// Created by DEV +// Modified 30/04/2024 +// +// 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 flds + +import ( + "reflect" + "time" +) + +type ( + + partSField struct { + name string + } +) + + +func makePartSField(name string) partSField { + //checkFieldName(name) + return partSField{ name: name } +} + +func (f partSField) Name () string { + return f.name } + + + +func (f partSField) Bool () (bool,bool) { + return false,false } + +func (f partSField) String () (string,bool) { + return "",false } + +func (f partSField) Signed () (int,bool) { + return 0,false } + +func (f partSField) Unsigned () (uint,bool) { + return 0,false } + +func (f partSField) Date () (time.Time,bool) { + return *new(time.Time),false } + +func (f partSField) Time () (time.Time,bool) { + return *new(time.Time),false } + +func (f partSField) Error () (error,bool) { + return nil,false } + +func (f partSField) Binary () ([]byte,bool) { + return nil,false } + +func (f partSField) Reflect() (reflect.Value,bool) { + return *new(reflect.Value),false } diff --git a/core/vals/flds/sfield.go b/core/vals/flds/sfield.go new file mode 100644 index 0000000..bc8cb3c --- /dev/null +++ b/core/vals/flds/sfield.go @@ -0,0 +1,56 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name sfield.go +// Created by DEV +// Modified 30/04/2024 +// +// 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 flds + +import ( + "reflect" + "time" +) + +type ( + + SField interface { + Name () string + Kind () Kind + + Value() any + + Any () (any,bool) + Bool () (bool,bool) + String () (string,bool) + Signed () (int,bool) + Unsigned () (uint,bool) + Date () (time.Time,bool) + Time () (time.Time,bool) + Error () (error,bool) + Binary () ([]byte,bool) + Reflect () (reflect.Value,bool) + } +) + + + + + + diff --git a/core/vals/flds/sfield_any.go b/core/vals/flds/sfield_any.go new file mode 100644 index 0000000..2cef81f --- /dev/null +++ b/core/vals/flds/sfield_any.go @@ -0,0 +1,139 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name sfield_any.go +// Created by DEV +// Modified 30/04/2024 +// +// 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 flds + +import ( + "reflect" + "time" +) + +type ( + + SFieldAny struct { + partSField + value any + } +) + +func NewSFieldAny (name string, value any) *SFieldAny { + return &SFieldAny{ + partSField: makePartSField(name), + value : value } } + + + +func (_ SFieldAny) Kind () Kind { + return KindAny } + +func (f SFieldAny) Value() any { + return f.value } + +func (f SFieldAny) Any () (any,bool) { + return f.value,true } + + +func (f SFieldAny) Bool () (bool,bool) { + v,ok := f.value.(bool) + return v,ok +} + + +func (f SFieldAny) String () (string,bool) { + v,ok := f.value.(string) + return v,ok +} + +func (f SFieldAny) Signed () (int,bool) { + switch t := f.value.(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 SFieldAny) Unsigned () (uint,bool) { + switch t := f.value.(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 SFieldAny) Float () (float64,bool) { + v, ok := f.value.(float64) + if !ok { + var f32 float32 + if f32,ok = f.value.(float32); ok { + v = float64(f32) + } + } + return v, ok +} + + +func (f SFieldAny) Date () (time.Time,bool) { + v, ok := f.value.(time.Time) + return v, ok +} + +func (f SFieldAny) Time () (time.Time,bool) { + v, ok := f.value.(time.Time) + return v, ok +} + +func (f SFieldAny) Error () (error,bool) { + v, ok := f.value.(error) + return v, ok +} + +func (f SFieldAny) Binary () ([]byte,bool) { + v, ok := f.value.([]byte) + return v, ok +} + + +func (f SFieldAny) Reflect () (reflect.Value,bool) { + v, ok := f.value.(reflect.Value) + return v, ok +} + + + + + + + + + + + + + + diff --git a/core/vals/flds/sfield_bool.go b/core/vals/flds/sfield_bool.go new file mode 100644 index 0000000..9a1fc81 --- /dev/null +++ b/core/vals/flds/sfield_bool.go @@ -0,0 +1,56 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name sfield_bool.go +// Created by DEV +// Modified 30/04/2024 +// +// 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 flds + + + +type ( + + SFieldBool struct { + partSField + value bool + } +) + +func NewSFieldBool (name string, value bool) *SFieldBool { + return &SFieldBool{ + partSField: makePartSField(name), + value: value } } + + + +func (_ SFieldBool) Kind () Kind { + return KindSigned } + +func (f SFieldBool) Value() any { + return f.value } + + +func (f SFieldBool) Any () (any,bool) { + return f.value,true } + +func (f SFieldBool) Bool() (bool,bool) { + return f.value,true } + + diff --git a/core/vals/flds/sfield_error.go b/core/vals/flds/sfield_error.go new file mode 100644 index 0000000..fa7c8a2 --- /dev/null +++ b/core/vals/flds/sfield_error.go @@ -0,0 +1,61 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name sfield_error.go +// Created by DEV +// Modified 30/04/2024 +// +// 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 flds + + + + + +type ( + + SFieldError struct { + partSField + value error + } +) + +func NewSFieldError(name string, value error) *SFieldError { + return &SFieldError{ + partSField: makePartSField(name), + value: value } } + + + +func (_ SFieldError) Kind () Kind { + return KindError } + +func (f SFieldError) Value() any { + return f.value } + + +func (f SFieldError) Any () (any,bool) { + return f.value,true } + +func (f SFieldError) Error() (error,bool) { + return f.value,true } + + + + + diff --git a/core/vals/flds/sfield_float.go b/core/vals/flds/sfield_float.go new file mode 100644 index 0000000..3a7ec5f --- /dev/null +++ b/core/vals/flds/sfield_float.go @@ -0,0 +1,56 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name sfield_float.go +// Created by DEV +// Modified 30/04/2024 +// +// 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 flds + + + +type ( + + SFieldFloat struct { + partSField + value float64 + } +) + +func NewSFieldFloat(name string, value float64) *SFieldFloat { + return &SFieldFloat{ + partSField: makePartSField(name), + value: value } } + + + +func (_ SFieldFloat) Kind () Kind { + return KindFloat } + +func (f SFieldFloat) Value() any { + return f.value } + + +func (f SFieldFloat) Any () (any,bool) { + return f.value,true } + +func (f SFieldFloat) Float() (float64,bool) { + return f.value,true } + + diff --git a/core/vals/flds/sfield_reflect.go b/core/vals/flds/sfield_reflect.go new file mode 100644 index 0000000..3680d1f --- /dev/null +++ b/core/vals/flds/sfield_reflect.go @@ -0,0 +1,56 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name sfield_reflect.go +// Created by DEV +// Modified 30/04/2024 +// +// 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 flds + +import "reflect" + +type ( + + SFieldReflect struct { + partSField + value reflect.Value + } +) + +func NewSFieldReflect(name string, value reflect.Value) *SFieldReflect { + return &SFieldReflect{ + partSField: makePartSField(name), + value: value } } + + + +func (_ SFieldReflect) Kind () Kind { + return KindReflect } + +func (f SFieldReflect) Value() any { + return f.value } + + +func (f SFieldReflect) Any () (any,bool) { + return f.value,true } + +func (f SFieldReflect) Reflect() (reflect.Value,bool) { + return f.value,true } + + diff --git a/core/vals/flds/sfield_signed.go b/core/vals/flds/sfield_signed.go new file mode 100644 index 0000000..2a66e65 --- /dev/null +++ b/core/vals/flds/sfield_signed.go @@ -0,0 +1,54 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name sfield_signed.go +// Created by DEV +// Modified 30/04/2024 +// +// 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 flds + + + +type ( + + SFieldSigned struct { + partSField + value int + } +) + +func NewSFieldSigned (name string, value int) *SFieldSigned { + return &SFieldSigned{ + partSField: makePartSField(name), + value: value } } + + + +func (_ SFieldSigned) Kind () Kind { + return KindSigned } + +func (f SFieldSigned) Value() any { + return f.value } + + +func (f SFieldSigned) Any () (any,bool) { + return f.value,true } + +func (f SFieldSigned) Signed() (int,bool) { + return f.value,true } \ No newline at end of file diff --git a/core/vals/flds/sfield_str.go b/core/vals/flds/sfield_str.go new file mode 100644 index 0000000..6570f53 --- /dev/null +++ b/core/vals/flds/sfield_str.go @@ -0,0 +1,54 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name sfield_string.go +// Created by DEV +// Modified 30/04/2024 +// +// 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 flds + + + +type ( + + SFieldString struct { + partSField + value string + } +) + +func NewSFieldString (name string, value string) *SFieldString { + return &SFieldString{ + partSField: makePartSField(name), + value : value } } + + + +func (_ SFieldString) Kind () Kind { + return KindString } + +func (f SFieldString) Value() any { + return f.value } + + +func (f SFieldString) Any () (any,bool) { + return f.value,true } + +func (f SFieldString) String() (string,bool) { + return f.value,true } \ No newline at end of file diff --git a/core/vals/flds/sfield_unsigned.go b/core/vals/flds/sfield_unsigned.go new file mode 100644 index 0000000..3f06f82 --- /dev/null +++ b/core/vals/flds/sfield_unsigned.go @@ -0,0 +1,54 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name sfield_unsigned.go +// Created by DEV +// Modified 30/04/2024 +// +// 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 flds + + +type ( + + SFieldUnsigned struct { + partSField + value uint + } +) + +func NewSFieldUnsigned(name string, value uint) *SFieldUnsigned { + return &SFieldUnsigned{ + partSField: makePartSField(name), + value : value } } + + +func (_ SFieldUnsigned) Kind () Kind { + return KindUnsigned } + +func (f SFieldUnsigned) Value() any { + return f.value } + + +func (f SFieldUnsigned) Any () (any,bool) { + return f.value,true } + +func (f SFieldUnsigned) Unsigned() (uint,bool) { + return f.value,true } + + diff --git a/core/vals/flds/sfields.go b/core/vals/flds/sfields.go new file mode 100644 index 0000000..c7aef1c --- /dev/null +++ b/core/vals/flds/sfields.go @@ -0,0 +1,89 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name sfields.go +// Created by DEV +// Modified 30/04/2024 +// +// 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 flds + +import "sort" + +type ( + + SFields []SField + +) + + +func (f SFields) Len () int { + return len(f) } + +func (f SFields) Has (name string) bool { + return f.has(name) != -1 } + +func (f SFields) has (name string) int { + for i,f := range f { + if f.Name() == name { + return i + } + } + return -1 +} + +func (f SFields) Kinds() Kind { + var k Kind + for _,f := range f { + k|=f.Kind() + } + return k +} + +func (f SFields) GeField (name string) SField { + if p := f.has(name); p != -1 { + return f[p] + } + return nil +} + +func (f SFields) AddField (field SField) SFields { + if field != nil { + return append(f,field) + } + return f +} + +func (f SFields) DelField (name string) SFields { + if p := f.has(name); p != -1 { + return append(f[:p],f[p+1:]...) + } + return f +} + + + +func (f SFields) Sort() { + sort.Sort(f) } + +func (f SFields) Swap(i, j int) { + f[i], f[j] = f[j], f[i] } + +func (f SFields) Less(i, j int) bool { + return f[i].Name() < f[j].Name() } +