-
Notifications
You must be signed in to change notification settings - Fork 0
/
attr_value.go
executable file
·90 lines (70 loc) · 1.4 KB
/
attr_value.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package radgo
import (
. "asdf"
)
type EAttrValueType int
func (me EAttrValueType) Tag() string {
return "Attribute-Value-Type"
}
func (me EAttrValueType) Begin() int {
return int(avtBegin)
}
func (me EAttrValueType) End() int {
return int(avtEnd)
}
func (me EAttrValueType) Int() int {
return int(me)
}
func (me EAttrValueType) IsGood() bool {
return IsGoodEnum(me) &&
len(avtBind) == me.End() &&
len(avtBind[me]) > 0
}
func (me EAttrValueType) IsNumber() bool {
switch me {
case AvtAddress:
fallthrough
case AvtInteger:
fallthrough
case AvtTime:
return true
default:
return false
}
}
func (me EAttrValueType) IsString() bool {
return !me.IsNumber()
}
func (me EAttrValueType) ToString() string {
var b EnumBinding = avtBind[:]
return b.EntryShow(me)
}
func (me *EAttrValueType) FromString(Name string) error {
if e, ok := avtMap[Name]; ok {
*me = e
return nil
}
return ErrNoFound
}
const (
avtBegin EAttrValueType = 1
AvtText EAttrValueType = 1
AvtString EAttrValueType = 2
AvtAddress EAttrValueType = 3
AvtInteger EAttrValueType = 4
AvtTime EAttrValueType = 5
avtEnd EAttrValueType = 6
)
var avtBind = [avtEnd]string{
AvtText: "Text",
AvtString: "String",
AvtAddress: "Address",
AvtInteger: "Integer",
AvtTime: "Time",
}
var avtMap = map[string]EAttrValueType{}
func initAvt() {
for i := avtBegin; i < avtEnd; i++ {
avtMap[avtBind[i]] = i
}
}