Sustituido los nuevos sfields, que sustituyen a los afields

master
DEV 2 years ago
parent 4d42ed5798
commit 225ad90bdb

@ -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<len(fs); i++ {
fmt.Printf("%s\n",fs[i].Name())
}
/*
cx,cl := context.WithCancel(context.Background())
//cl()
l,er := alogs.NewActiveLogger(alogs.LevelAll,
alogs.ActiveLoggerWithContext(cx,true),
@ -100,5 +116,5 @@ func main() {
//time.Sleep(1000 * time.Millisecond)
cl()
*/
}

@ -21,9 +21,12 @@
// limitations under the License.
// ------------------------------------------------------------------------
package flds
package _deprecated
import "time"
import (
"time"
"vals/flds"
)
type (
@ -42,7 +45,7 @@ func (f AField) Name () string {
return f.fs.heads[f.hp].name
}
func (f AField) Kind () Kind {
func (f AField) Kind () flds.Kind {
return f.fs.heads[f.hp].kind
}
@ -52,15 +55,15 @@ func (f AField) Value() any {
}
p := f.fs.heads[f.hp].pos
switch f.fs.heads[f.hp].kind {
case KindAny : return f.fs.anys[p]
case KindError : return f.fs.anys[p].(error)
case KindBool : return f.fs.nums[p] != 0
case KindSigned : return f.fs.nums[p]
case KindUnsigned : return uint(f.fs.nums[p])
case KindFloat : return f.fs.floats [p]
case KindString : return f.fs.strings [p]
case KindDate : return f.fs.dates [p]
case KindBinary : return f.fs.binaries[p]
case flds.KindAny: return f.fs.anys[p]
case flds.KindError: return f.fs.anys[p].(error)
case flds.KindBool: return f.fs.nums[p] != 0
case flds.KindSigned: return f.fs.nums[p]
case flds.KindUnsigned: return uint(f.fs.nums[p])
case flds.KindFloat: return f.fs.floats [p]
case flds.KindString: return f.fs.strings [p]
case flds.KindDate: return f.fs.dates [p]
case flds.KindBinary: return f.fs.binaries[p]
default:
// Handle unknown field type
return nil
@ -72,28 +75,28 @@ func (f AField) Any () (any,bool) {
func (f AField) Bool () (bool,bool) {
if f.hp != -1 || f.fs.heads[f.hp].kind != KindBool {
if f.hp != -1 || f.fs.heads[f.hp].kind != flds.KindBool {
return false,false
}
return f.fs.nums[f.fs.heads[f.hp].pos] > 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

@ -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)
}

@ -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
}
)

@ -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
}
*/

@ -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) }

@ -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
}

@ -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 }

@ -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)
}
)

@ -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
}

@ -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 }

@ -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 }

@ -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 }

@ -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 }

@ -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 }

@ -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 }

@ -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 }

@ -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() }
Loading…
Cancel
Save

Powered by TurnKey Linux.