-
Notifications
You must be signed in to change notification settings - Fork 0
/
branch.go
62 lines (52 loc) · 1.15 KB
/
branch.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
package croot
// #include "croot/croot.h"
//
// #include <stdlib.h>
// #include <string.h>
//
import "C"
import (
"unsafe"
)
// Branch
type Branch interface {
Object
GetAddress() uintptr
GetClassName() string
GetListOfLeaves() []Leaf
GetLeaf(n string) Leaf
}
type branchImpl struct {
c C.CRoot_Branch
}
func (b *branchImpl) GetAddress() uintptr {
return uintptr(unsafe.Pointer(C.CRoot_Branch_GetAddress(b.c)))
}
// func (b *branch_impl) GetObject() uintptr {
// return uintptr(unsafe.Pointer(C.CRoot_Branch_GetObject(b.c)))
// }
func (b *branchImpl) GetClassName() string {
cstr := C.CRoot_Branch_GetClassName(b.c)
return C.GoString(cstr)
}
func (b *branchImpl) GetListOfLeaves() []Leaf {
c := C.CRoot_Branch_GetListOfLeaves(b.c)
objs := objArrayImpl{c: c}
leaves := make([]Leaf, objs.GetEntries())
for i := 0; i < len(leaves); i++ {
obj := objs.At(int64(i))
leaf := b.GetLeaf(obj.GetName())
leaves[i] = leaf
}
return leaves
}
func (b *branchImpl) GetLeaf(name string) Leaf {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
c := C.CRoot_Branch_GetLeaf(b.c, cname)
if c == nil {
return nil
}
return &leafImpl{c: c}
}
// EOF