-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontext.go
More file actions
141 lines (104 loc) · 2.42 KB
/
Copy pathcontext.go
File metadata and controls
141 lines (104 loc) · 2.42 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package rigo
import (
"sync"
. "github.com/mae-global/rigo/ri"
. "github.com/mae-global/rigo/ris"
)
type Configuration struct {
Entity bool
PrettyPrint bool
PrettyPrintSpacing string
}
type Context struct {
mux sync.RWMutex
pipe *Pipe
HandleManagerer
files map[RtToken]bool
cache map[RtShaderHandle]Shader
Info
}
/* Write */
func (ctx *Context) Write(name RtName,args,params []Rter,values []Rter) error {
ctx.mux.Lock()
defer ctx.mux.Unlock()
return ctx.pipe.Run(name,args,Mix(params,values),ctx.Info)
}
/* OpenRaw */
func (ctx *Context) OpenRaw(id RtToken) (ArchiveWriter,error) {
ctx.mux.Lock()
defer ctx.mux.Unlock()
if ctx.files == nil {
ctx.files = make(map[RtToken]bool,0)
}
if _,exists := ctx.files[id]; exists {
return nil,ErrNotSupported
}
for _,r := range ctx.files {
if r {
return nil,ErrNotSupported
}
}
ctx.files[id] = true
return ctx.pipe.ToRaw(),nil
}
/* CloseRaw */
func (ctx *Context) CloseRaw(id RtToken) error {
ctx.mux.Lock()
defer ctx.mux.Unlock()
if ctx.files == nil {
return ErrNotSupported
}
if _,exists := ctx.files[id]; !exists {
return ErrNotSupported
}
delete(ctx.files,id)
return nil
}
/* SetShader */
func (ctx *Context) SetShader(sh RtShaderHandle,s Shader) {
ctx.mux.Lock()
defer ctx.mux.Unlock()
ctx.cache[sh] = s
}
/* GetShader */
func (ctx *Context) GetShader(sh RtShaderHandle) Shader {
ctx.mux.Lock()
defer ctx.mux.Unlock()
if s,ok := ctx.cache[sh]; ok {
return s
}
return nil
}
/* Shader */
func (ctx *Context) Shader(sh RtShaderHandle) ShaderWriter {
return ctx.GetShader(sh)
}
func NewContext(pipe *Pipe,mgr HandleManagerer,config *Configuration) *Context {
if pipe == nil {
pipe = DefaultFilePipe()
}
if config == nil {
config = &Configuration{Entity:false,PrettyPrint:false,PrettyPrintSpacing:"\t"}
} else {
if config.PrettyPrint && len(config.PrettyPrintSpacing) == 0 {
config.PrettyPrintSpacing = "\t"
}
}
if mgr == nil {
mgr = NewHandleManager(nil,nil,nil)
}
info := Info{Name:"",Entity:config.Entity,PrettyPrint:config.PrettyPrint,
PrettyPrintSpacing:config.PrettyPrintSpacing}
ctx := &Context{pipe:pipe,Info:info}
ctx.HandleManagerer = mgr
ctx.cache = make(map[RtShaderHandle]Shader,0)
return ctx
}
/* Wrap the RIS interface */
func RIS(ctx RisContexter) *Ris {
return &Ris{ctx} /* TODO: add errorhandler to RIS as well */
}
/* Wrap the RI interface */
func RI(ctx RiContexter) *Ri {
return NewRi(ctx)
}