-
Notifications
You must be signed in to change notification settings - Fork 0
/
Context.go
47 lines (40 loc) · 1.34 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
// =================================================================
//
// Copyright (C) 2019 Spatial Current, Inc. - All Rights Reserved
// Released as open source under the MIT License. See LICENSE file.
//
// =================================================================
package dfl
// Context is a simple alias for a map[string]interface{} that is used for containing the context for evaluating a DFL Node.
// The values in a context are essentially the input parameters for a DFL expression and match up with the Attribute.
// The Context is built from the trailing command line arguments. For example the arguments from the following command line
//
// ./dfl -filter "(@amenity like bar) and (open > 0)" amenity=bar popularity=10 open=1
//
// Would be interpreted as the following Context
//
// ctx := Context{"amenity": "bar", "popularity": 10, "open": 1}
//
type Context struct {
Data map[string]interface{}
}
func (c *Context) Len() int {
return len(c.Data)
}
func (c *Context) Has(key string) bool {
_, ok := c.Data[key]
return ok
}
func (c *Context) Get(key string) interface{} {
return c.Data[key]
}
func (c *Context) Set(key string, value interface{}) {
c.Data[key] = value
}
func (c *Context) Values() []interface{} {
values := make([]interface{}, 0, len(c.Data))
for _, v := range c.Data {
values = append(values, v)
}
return values
}