forked from mei-rune/gowbem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cim_type.go
120 lines (107 loc) · 2.36 KB
/
cim_type.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package gowbem
type CIMTypeCode int
const (
INVALID CIMTypeCode = iota
BOOLEAN
STRING
CHAR16
UINT8
SINT8
UINT16
SINT16
UINT32
SINT32
UINT64
SINT64
DATETIME
REAL32
REAL64
NUMERIC
REFERENCE
)
const (
NON_ARRAY = 0
UNBOUNDED_ARRAY = -1
)
var (
INVALID_TYPE = CIMType{typeCode: INVALID}
types = map[string]CIMType{
"": CIMType{typeCode: INVALID},
"boolean": CIMType{typeCode: BOOLEAN},
"string": CIMType{typeCode: STRING},
"char16": CIMType{typeCode: CHAR16},
"uint8": CIMType{typeCode: UINT8},
"sint8": CIMType{typeCode: SINT8},
"uint16": CIMType{typeCode: UINT16},
"sint16": CIMType{typeCode: SINT16},
"uint32": CIMType{typeCode: UINT32},
"sint32": CIMType{typeCode: SINT32},
"uint64": CIMType{typeCode: UINT64},
"sint64": CIMType{typeCode: SINT64},
"datetime": CIMType{typeCode: DATETIME},
"real32": CIMType{typeCode: REAL32},
"real64": CIMType{typeCode: REAL64},
"numeric": CIMType{typeCode: NUMERIC},
"reference": CIMType{typeCode: REFERENCE},
}
)
type CIMType struct {
typeCode CIMTypeCode
/**
* non array if =0 <br>
* unbounded if <0 <br>
* bounded if >0
*/
arraySize int
refClassName string
}
/**
* Returns the class name of the CIM REFERENCE data type.
*
* @return The CIM REFERENCE class name.
*/
func (self *CIMType) GetClassName() string {
return self.refClassName
}
/**
* Returns the size of the maximum number of elements an array data type may
* hold.
*
* @return The maximum size of the array data type.
*/
func (self *CIMType) GetSize() int {
return self.arraySize
}
/**
* Returns the data type.
*
* @return The data type.
*/
func (self *CIMType) GetType() CIMTypeCode {
return self.typeCode
}
/**
* Checks if the data type is an array type.
*
* @return <code>true</code> if the data type is an array type,
* <code>false</code> otherwise.
*/
func (self *CIMType) IsArray() bool {
return self.arraySize == 0
}
func CreateCIMType(t string) CIMType {
if ct, ok := types[t]; ok {
return ct
}
return CIMType{typeCode: INVALID}
}
func CreateCIMArrayType(t string, arraySize int) CIMType {
if ct, ok := types[t]; ok {
ct.arraySize = arraySize
return ct
}
return CIMType{typeCode: INVALID, arraySize: arraySize}
}
func CreateCIMReferenceType(class string) CIMType {
return CIMType{typeCode: REFERENCE, refClassName: class}
}