-
Notifications
You must be signed in to change notification settings - Fork 37
/
type.go
90 lines (81 loc) · 2.1 KB
/
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
package smi
import (
"unsafe"
"github.com/sleepinggenius2/gosmi/smi/internal"
"github.com/sleepinggenius2/gosmi/types"
)
// SmiType *smiGetType(SmiModule *smiModulePtr, char *type)
func GetType(smiModulePtr *types.SmiModule, typeName string) *types.SmiType {
if typeName == "" {
return nil
}
var modulePtr *internal.Module
if smiModulePtr != nil {
modulePtr = (*internal.Module)(unsafe.Pointer(smiModulePtr))
typePtr := modulePtr.Types.GetName(typeName)
if typePtr == nil {
return nil
}
return &typePtr.SmiType
}
for modulePtr = internal.GetFirstModule(); modulePtr != nil; modulePtr = modulePtr.Next {
typePtr := modulePtr.Types.GetName(typeName)
if typePtr != nil {
return &typePtr.SmiType
}
}
return nil
}
// SmiType *smiGetFirstType(SmiModule *smiModulePtr)
func GetFirstType(smiModulePtr *types.SmiModule) *types.SmiType {
if smiModulePtr == nil {
return nil
}
modulePtr := (*internal.Module)(unsafe.Pointer(smiModulePtr))
typePtr := modulePtr.Types.First
if typePtr == nil {
return nil
}
return &typePtr.SmiType
}
// SmiType *smiGetNextType(SmiType *smiTypePtr)
func GetNextType(smiTypePtr *types.SmiType) *types.SmiType {
if smiTypePtr == nil {
return nil
}
typePtr := (*internal.Type)(unsafe.Pointer(smiTypePtr))
if typePtr.Next == nil {
return nil
}
return &typePtr.Next.SmiType
}
// SmiType *smiGetParentType(SmiType *smiTypePtr)
func GetParentType(smiTypePtr *types.SmiType) *types.SmiType {
if smiTypePtr == nil {
return nil
}
typePtr := (*internal.Type)(unsafe.Pointer(smiTypePtr))
if typePtr.Parent == nil {
return nil
}
return &typePtr.Parent.SmiType
}
// SmiModule *smiGetTypeModule(SmiType *smiTypePtr)
func GetTypeModule(smiTypePtr *types.SmiType) *types.SmiModule {
if smiTypePtr == nil {
return nil
}
typePtr := (*internal.Type)(unsafe.Pointer(smiTypePtr))
if typePtr.Module == nil {
return nil
}
return &typePtr.Module.SmiModule
}
// int smiGetTypeLine(SmiType *smiTypePtr)
func GetTypeLine(smiTypePtr *types.SmiType) int {
if smiTypePtr == nil {
return 0
}
typePtr := (*internal.Type)(unsafe.Pointer(smiTypePtr))
return typePtr.Line
}