You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
3.3 KiB
137 lines
3.3 KiB
// ------------------------------------------------------------------------
|
|
// Project active2
|
|
// Active Thing (activething.com) git.activething.com/go
|
|
//
|
|
// File name afield.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 _deprecated
|
|
|
|
import (
|
|
"time"
|
|
"vals/flds"
|
|
)
|
|
|
|
type (
|
|
|
|
AField struct {
|
|
fs *AFields
|
|
hp int
|
|
}
|
|
)
|
|
|
|
|
|
|
|
func (f AField) IsValid() bool {
|
|
return f.fs.heads[f.hp].pos != -1 }
|
|
|
|
func (f AField) Name () string {
|
|
return f.fs.heads[f.hp].name
|
|
}
|
|
|
|
func (f AField) Kind () flds.Kind {
|
|
return f.fs.heads[f.hp].kind
|
|
}
|
|
|
|
func (f AField) Value() any {
|
|
if f.fs.heads[f.hp].pos == -1 {
|
|
return nil
|
|
}
|
|
p := f.fs.heads[f.hp].pos
|
|
switch f.fs.heads[f.hp].kind {
|
|
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
|
|
}
|
|
}
|
|
|
|
func (f AField) Any () (any,bool) {
|
|
return f.Value(), f.hp != -1 }
|
|
|
|
|
|
func (f AField) Bool () (bool,bool) {
|
|
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 != 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 != 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 != flds.KindUnsigned {
|
|
return 0,false
|
|
}
|
|
return uint(f.fs.nums[f.fs.heads[f.hp].pos]),true
|
|
}
|
|
|
|
|
|
func (f AField) Date () (time.Time,bool) {
|
|
if f.hp != -1 || f.fs.heads[f.hp].kind != flds.KindDate {
|
|
var z time.Time
|
|
return z,false
|
|
}
|
|
return f.fs.dates[f.fs.heads[f.hp].pos],true
|
|
}
|
|
|
|
func (f AField) Time () (time.Time,bool) {
|
|
if f.hp != -1 || f.fs.heads[f.hp].kind != flds.KindTime {
|
|
var z time.Time
|
|
return z,false
|
|
}
|
|
return f.fs.dates[f.fs.heads[f.hp].pos],true
|
|
}
|
|
|
|
func (f AField) Error () (error,bool) {
|
|
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 != flds.KindBinary {
|
|
return nil,false
|
|
}
|
|
return f.fs.binaries[f.fs.heads[f.hp].pos],true
|
|
}
|
|
|
|
|