-
Notifications
You must be signed in to change notification settings - Fork 1
/
context.go
97 lines (83 loc) · 2.3 KB
/
context.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
package proj
/*
#cgo CFLAGS: -I. -I${SRCDIR}/usr/local/include
#cgo LDFLAGS: -L${SRCDIR}/usr/local/lib -lproj
#include "wrapper.h"
*/
import "C"
import "unsafe"
// Context handles an internal threads context of the PROJ library
//
type Context struct {
pj *C.PJ_CONTEXT
}
var (
authorities map[string]bool
)
// NewContext creates a new threading-context into the PROJ library.
//
func NewContext () (*Context) {
return &Context{pj:C.proj_context_create()}
}
// DestroyContext deallocates the internal threading-context into the PROJ library.
//
func (ctx *Context) DestroyContext () {
if (*ctx).pj != nil {
C.proj_context_destroy((*ctx).pj)
(*ctx).pj = nil
}
}
// Handle returns the PROJ internal object to be passed to the PROJ library
//
func (ctx *Context) Handle () (interface{}) {
return (*ctx).pj
}
// HandleIsNil returns true when the PROJ internal object is NULL.
//
func (ctx *Context) HandleIsNil () bool {
return (*ctx).pj == (*C.PJ_CONTEXT)(nil)
}
// DatabasePath returns the path to the database, empty string if none.
//
func (ctx *Context) DatabasePath () string {
p := C.proj_context_get_database_path((*ctx).pj)
if p == nil { return "" }
return C.GoString(p)
}
// SetDatabasePath assigns the path to the 'proj.db' file.
//
func (ctx *Context) SetDatabasePath ( p string ) {
dbp := C.CString(p)
defer C.free(unsafe.Pointer(dbp))
_ = C.proj_context_set_database_path((*ctx).pj,dbp,nil,nil)
}
// IsAnAuthority checks whether the proposed name is an authority or not
//
func (ctx *Context) IsAnAuthority ( name string ) bool {
return authorities[name]
}
// LogLevel returns the current log level of PROJ.
//
func (ctx *Context) LogLevel ( ) LoggingLevel {
return LogLevel(ctx)
}
// SetLogLevel assigns the log level of PROJ.
//
func (ctx *Context) SetLogLevel ( lvl LoggingLevel ) {
SetLogLevel(ctx,lvl)
}
// init package initialisation
//
func init () {
if auths := C.proj_get_authorities_from_database(nil) ; auths != nil {
authorities = make(map[string]bool)
for i := 0 ; i >= 0 ; i++ {
cauth := C.getAuthorityFromPROJ(auths, C.int(i))
if cauth == nil {
break
}
authorities[C.GoString(cauth)] = true
}
C.proj_string_list_destroy(auths)
}
}