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.
active/core/vals/flds/sfield_any.go

140 lines
2.7 KiB

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

Powered by TurnKey Linux.