diff options
author | Ben Clayton <bclayton@google.com> | 2015-07-08 10:22:08 +0100 |
---|---|---|
committer | Ben Clayton <bclayton@google.com> | 2015-07-08 10:25:45 +0100 |
commit | 609683449ae6e842186e7924bde1cdf3635f01d5 (patch) | |
tree | f7a4dcd526ab9ffb40fce4649c4c1f9903b1d256 /service/path | |
parent | 9cc536dd5d3307a45d89cb8a52e8548b2cf53d33 (diff) | |
download | gpu-609683449ae6e842186e7924bde1cdf3635f01d5.tar.gz |
Path: Use concrete types instead of path.Value where possible.
Change-Id: I8f41a57b00e9875ba518f9ca214456cad00e5457
Diffstat (limited to 'service/path')
-rw-r--r-- | service/path/array_index.go | 25 | ||||
-rw-r--r-- | service/path/atom.go | 15 | ||||
-rw-r--r-- | service/path/capture.go | 2 | ||||
-rw-r--r-- | service/path/field.go | 25 | ||||
-rw-r--r-- | service/path/map_index.go | 25 | ||||
-rw-r--r-- | service/path/path.go | 8 | ||||
-rw-r--r-- | service/path/path_binary.go | 18 | ||||
-rw-r--r-- | service/path/report.go | 2 | ||||
-rw-r--r-- | service/path/state.go | 21 |
9 files changed, 84 insertions, 57 deletions
diff --git a/service/path/array_index.go b/service/path/array_index.go index d2542ed1c..479309f1e 100644 --- a/service/path/array_index.go +++ b/service/path/array_index.go @@ -23,7 +23,7 @@ import ( // ArrayIndex is a path that refers to a single element of an array. type ArrayIndex struct { binary.Generate - Array Value // The path to the array. + Array Path // The path to the array. Index uint64 // The index of the element in the array. } @@ -42,20 +42,29 @@ func (n *ArrayIndex) Base() Path { // Clone implements the Path interface, returning a deep-copy of this path. func (n *ArrayIndex) Clone() Path { - return &ArrayIndex{Array: n.Array.Clone().(Value), Index: n.Index} + return &ArrayIndex{Array: n.Array.Clone(), Index: n.Index} } -// Field implements the Value interface. -func (n *ArrayIndex) Field(name string) Value { +// Field returns the path to the field value with the specified name on the +// struct object represented by this path. +// The represented value type must be of type struct, otherwise the returned +// path is invalid. +func (n *ArrayIndex) Field(name string) *Field { return &Field{Struct: n, Name: name} } -// ArrayIndex implements the Value interface. -func (n *ArrayIndex) ArrayIndex(index uint64) Value { +// ArrayIndex returns the path to the i'th element on the array or slice +// represented by this path. +// The represented value type must be of type array or slice, otherwise the +// returned path is invalid. +func (n *ArrayIndex) ArrayIndex(index uint64) *ArrayIndex { return &ArrayIndex{Array: n, Index: index} } -// MapIndex implements the Value interface. -func (n *ArrayIndex) MapIndex(key interface{}) Value { +// MapIndex returns the path to the map element with key k on the map object +// represented by this path. +// The represented value type must be of type map, otherwise the returned path +// is invalid. +func (n *ArrayIndex) MapIndex(key interface{}) *MapIndex { return &MapIndex{Map: n, Key: key} } diff --git a/service/path/atom.go b/service/path/atom.go index d31f8020d..b81cbf521 100644 --- a/service/path/atom.go +++ b/service/path/atom.go @@ -45,21 +45,12 @@ func (n *Atom) Clone() Path { return &Atom{Atoms: n.Atoms.Clone().(*Atoms), Index: n.Index} } -// Field implements the Value interface. -func (n *Atom) Field(name string) Value { +// Field returns the path to the field value with the specified name on the +// atom represented by this path. +func (n *Atom) Field(name string) *Field { return &Field{Struct: n, Name: name} } -// ArrayIndex implements the Value interface. -func (n *Atom) ArrayIndex(index uint64) Value { - return &ArrayIndex{Array: n, Index: index} -} - -// MapIndex implements the Value interface. -func (n *Atom) MapIndex(key interface{}) Value { - return &MapIndex{Map: n, Key: key} -} - // StateAfter returns the path to the state immediately following this atom. func (n *Atom) StateAfter() *State { return &State{After: n} diff --git a/service/path/capture.go b/service/path/capture.go index b2799cfc8..69d44aec0 100644 --- a/service/path/capture.go +++ b/service/path/capture.go @@ -50,6 +50,6 @@ func (c *Capture) Atoms() *Atoms { } // Report returns the path to the capture's report. -func (c *Capture) Report() Path { +func (c *Capture) Report() *Report { return &Report{Capture: c} } diff --git a/service/path/field.go b/service/path/field.go index 689fceb27..ad3723f40 100644 --- a/service/path/field.go +++ b/service/path/field.go @@ -23,7 +23,7 @@ import ( // Field is a path that refers to a single field of a struct object. type Field struct { binary.Generate - Struct Value // The path to the structure holding the field. + Struct Path // The path to the structure holding the field. Name string // The name of the field. } @@ -42,20 +42,29 @@ func (n *Field) Base() Path { // Clone implements the Path interface, returning a deep-copy of this path. func (n *Field) Clone() Path { - return &Field{Struct: n.Struct.Clone().(Value), Name: n.Name} + return &Field{Struct: n.Struct.Clone(), Name: n.Name} } -// Field implements the Value interface. -func (n *Field) Field(name string) Value { +// Field returns the path to the field value with the specified name on the +// struct object represented by this path. +// The represented value type must be of type struct, otherwise the returned +// path is invalid. +func (n *Field) Field(name string) *Field { return &Field{Struct: n, Name: name} } -// ArrayIndex implements the Value interface. -func (n *Field) ArrayIndex(index uint64) Value { +// ArrayIndex returns the path to the i'th element on the array or slice +// represented by this path. +// The represented value type must be of type array or slice, otherwise the +// returned path is invalid. +func (n *Field) ArrayIndex(index uint64) *ArrayIndex { return &ArrayIndex{Array: n, Index: index} } -// MapIndex implements the Value interface. -func (n *Field) MapIndex(key interface{}) Value { +// MapIndex returns the path to the map element with key k on the map object +// represented by this path. +// The represented value type must be of type map, otherwise the returned path +// is invalid. +func (n *Field) MapIndex(key interface{}) *MapIndex { return &MapIndex{Map: n, Key: key} } diff --git a/service/path/map_index.go b/service/path/map_index.go index b2a5d7848..ac4a7eec6 100644 --- a/service/path/map_index.go +++ b/service/path/map_index.go @@ -23,7 +23,7 @@ import ( // MapIndex is a path that refers to a single value in a map. type MapIndex struct { binary.Generate - Map Value // The path to the map containing the value. + Map Path // The path to the map containing the value. Key interface{} // The key to the value in the map. } @@ -42,20 +42,29 @@ func (n *MapIndex) Base() Path { // Clone implements the Path interface, returning a deep-copy of this path. func (n *MapIndex) Clone() Path { - return &MapIndex{Map: n.Map.Clone().(Value), Key: n.Key} + return &MapIndex{Map: n.Map.Clone(), Key: n.Key} } -// Field implements the Value interface. -func (n *MapIndex) Field(name string) Value { +// Field returns the path to the field value with the specified name on the +// struct object represented by this path. +// The represented value type must be of type struct, otherwise the returned +// path is invalid. +func (n *MapIndex) Field(name string) *Field { return &Field{Struct: n, Name: name} } -// ArrayIndex implements the Value interface. -func (n *MapIndex) ArrayIndex(index uint64) Value { +// ArrayIndex returns the path to the i'th element on the array or slice +// represented by this path. +// The represented value type must be of type array or slice, otherwise the +// returned path is invalid. +func (n *MapIndex) ArrayIndex(index uint64) *ArrayIndex { return &ArrayIndex{Array: n, Index: index} } -// MapIndex implements the Value interface. -func (n *MapIndex) MapIndex(key interface{}) Value { +// MapIndex returns the path to the map element with key k on the map object +// represented by this path. +// The represented value type must be of type map, otherwise the returned path +// is invalid. +func (n *MapIndex) MapIndex(key interface{}) *MapIndex { return &MapIndex{Map: n, Key: key} } diff --git a/service/path/path.go b/service/path/path.go index 30ce83dff..fd305e5b4 100644 --- a/service/path/path.go +++ b/service/path/path.go @@ -53,17 +53,17 @@ type Value interface { // struct object represented by this path. // The represented value type must be of type struct, otherwise the returned // path is invalid. - Field(name string) Value + Field(name string) *Field - // ArrayIndex returns the path to the i'th array element on the array object + // ArrayIndex returns the path to the i'th element on the array or slice // represented by this path. // The represented value type must be of type array or slice, otherwise the // returned path is invalid. - ArrayIndex(i uint64) Value + ArrayIndex(i uint64) *ArrayIndex // MapIndex returns the path to the map element with key k on the map object // represented by this path. // The represented value type must be of type map, otherwise the returned path // is invalid. - MapIndex(k interface{}) Value + MapIndex(k interface{}) *MapIndex } diff --git a/service/path/path_binary.go b/service/path/path_binary.go index 3ea96436d..c30617ba8 100644 --- a/service/path/path_binary.go +++ b/service/path/path_binary.go @@ -27,12 +27,12 @@ func init() { } var ( - binaryIDArrayIndex = binary.ID{0x48, 0x23, 0xb9, 0xfb, 0x5c, 0x3c, 0xd8, 0x21, 0x0a, 0xe7, 0xca, 0x09, 0xc7, 0xb9, 0x4b, 0xc9, 0x7d, 0xd2, 0x48, 0x69} + binaryIDArrayIndex = binary.ID{0x70, 0x45, 0xaf, 0xd6, 0x00, 0x20, 0x4c, 0x2c, 0x72, 0x36, 0x74, 0xc3, 0x2e, 0x1e, 0xb9, 0xf5, 0x4b, 0xe6, 0x68, 0xfb} binaryIDCapture = binary.ID{0x0e, 0x9b, 0xe3, 0x62, 0x7b, 0x67, 0x5b, 0xe0, 0x44, 0x7b, 0x7b, 0x21, 0xa1, 0x50, 0x6d, 0x1b, 0xfb, 0xc7, 0x47, 0xe6} binaryIDAtoms = binary.ID{0x17, 0x6b, 0x7c, 0x08, 0xc2, 0x36, 0x2c, 0xe3, 0x1b, 0x17, 0xd5, 0x3a, 0x0a, 0x98, 0x5b, 0x76, 0xc5, 0x1d, 0x01, 0xa7} binaryIDAtom = binary.ID{0x58, 0x11, 0xbe, 0x6d, 0xfc, 0xe2, 0xe0, 0x12, 0x6c, 0x42, 0x55, 0x2d, 0xf3, 0x5e, 0x11, 0x1a, 0xc1, 0x6b, 0xfe, 0x3b} - binaryIDField = binary.ID{0xd0, 0x6a, 0xce, 0x53, 0xcf, 0xc3, 0x4c, 0x2a, 0x51, 0xa7, 0xaf, 0xf1, 0xb5, 0x91, 0x67, 0xdd, 0xe0, 0x21, 0x7b, 0x02} - binaryIDMapIndex = binary.ID{0xf1, 0xfd, 0x8e, 0x5c, 0x70, 0x49, 0x7f, 0xbd, 0x40, 0xbc, 0x54, 0x04, 0xff, 0x46, 0x76, 0xec, 0x4c, 0x4c, 0xc0, 0x01} + binaryIDField = binary.ID{0xd2, 0x4f, 0x7f, 0x64, 0xec, 0x81, 0x92, 0x06, 0x6c, 0x25, 0x60, 0xfa, 0x5a, 0x0b, 0x9c, 0x6e, 0x73, 0xf7, 0x4b, 0x4c} + binaryIDMapIndex = binary.ID{0x0d, 0x46, 0x56, 0xf3, 0x1d, 0xba, 0xf9, 0xd8, 0x5e, 0xcf, 0xcc, 0x0e, 0x84, 0x93, 0x38, 0x5b, 0xbb, 0xd2, 0xec, 0xde} binaryIDReport = binary.ID{0xc3, 0x15, 0x30, 0x12, 0xb4, 0xa6, 0x7e, 0x71, 0x3a, 0xa3, 0xec, 0xb5, 0x93, 0x21, 0xf6, 0x2f, 0xd2, 0xf1, 0x4f, 0xa9} binaryIDState = binary.ID{0xf1, 0xa4, 0x19, 0x51, 0x01, 0xc4, 0xe2, 0x90, 0xc2, 0xca, 0x28, 0x00, 0x17, 0x08, 0x72, 0xb9, 0x46, 0x3a, 0xd1, 0x7b} ) @@ -59,7 +59,7 @@ func doDecodeArrayIndex(d binary.Decoder, o *ArrayIndex) error { if obj, err := d.Object(); err != nil { return err } else if obj != nil { - o.Array = obj.(Value) + o.Array = obj.(Path) } else { o.Array = nil } @@ -99,7 +99,7 @@ var schemaArrayIndex = &schema.Class{ Package: "path", Name: "ArrayIndex", Fields: []schema.Field{ - {Declared: "Array", Type: &schema.Interface{Name: "Value"}}, + {Declared: "Array", Type: &schema.Interface{Name: "Path"}}, {Declared: "Index", Type: &schema.Primitive{Name: "uint64", Method: schema.Uint64}}, }, } @@ -297,7 +297,7 @@ func doDecodeField(d binary.Decoder, o *Field) error { if obj, err := d.Object(); err != nil { return err } else if obj != nil { - o.Struct = obj.(Value) + o.Struct = obj.(Path) } else { o.Struct = nil } @@ -337,7 +337,7 @@ var schemaField = &schema.Class{ Package: "path", Name: "Field", Fields: []schema.Field{ - {Declared: "Struct", Type: &schema.Interface{Name: "Value"}}, + {Declared: "Struct", Type: &schema.Interface{Name: "Path"}}, {Declared: "Name", Type: &schema.Primitive{Name: "string", Method: schema.String}}, }, } @@ -373,7 +373,7 @@ func doDecodeMapIndex(d binary.Decoder, o *MapIndex) error { if obj, err := d.Object(); err != nil { return err } else if obj != nil { - o.Map = obj.(Value) + o.Map = obj.(Path) } else { o.Map = nil } @@ -417,7 +417,7 @@ var schemaMapIndex = &schema.Class{ Package: "path", Name: "MapIndex", Fields: []schema.Field{ - {Declared: "Map", Type: &schema.Interface{Name: "Value"}}, + {Declared: "Map", Type: &schema.Interface{Name: "Path"}}, {Declared: "Key", Type: &any.Any{}}, }, } diff --git a/service/path/report.go b/service/path/report.go index 16eba87aa..4a1b38297 100644 --- a/service/path/report.go +++ b/service/path/report.go @@ -23,7 +23,7 @@ import ( // Report is a path that refers to a capture's report. type Report struct { binary.Generate - Capture *Capture // The path to the capture containing the atoms. + Capture *Capture // The path to the capture containing the report. } // String returns the string representation of the path. diff --git a/service/path/state.go b/service/path/state.go index 04f9f3567..530d3051c 100644 --- a/service/path/state.go +++ b/service/path/state.go @@ -45,17 +45,26 @@ func (n *State) Clone() Path { return &State{After: n.After.Clone().(*Atom)} } -// Field implements the Value interface. -func (n *State) Field(name string) Value { +// Field returns the path to the field value with the specified name on the +// struct object represented by this path. +// The represented value type must be of type struct, otherwise the returned +// path is invalid. +func (n *State) Field(name string) *Field { return &Field{Struct: n, Name: name} } -// ArrayIndex implements the Value interface. -func (n *State) ArrayIndex(index uint64) Value { +// ArrayIndex returns the path to the i'th element on the array or slice +// represented by this path. +// The represented value type must be of type array or slice, otherwise the +// returned path is invalid. +func (n *State) ArrayIndex(index uint64) *ArrayIndex { return &ArrayIndex{Array: n, Index: index} } -// MapIndex implements the Value interface. -func (n *State) MapIndex(key interface{}) Value { +// MapIndex returns the path to the map element with key k on the map object +// represented by this path. +// The represented value type must be of type map, otherwise the returned path +// is invalid. +func (n *State) MapIndex(key interface{}) *MapIndex { return &MapIndex{Map: n, Key: key} } |