blob: 43c27d7d14b9cfbcd8fcb7790ee65d8d30b288bd [file] [log] [blame] [edit]
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package path
import (
"fmt"
"android.googlesource.com/platform/tools/gpu/framework/binary"
"android.googlesource.com/platform/tools/gpu/framework/id"
)
// ContextID is the unique identifier of a single context in a capture.
type ContextID id.ID
// Context is a path that refers to a single context in a capture.
type Context struct {
binary.Generate
Contexts *Contexts // The path to the full list of the capture's contexts.
ID ContextID // The capture's unique identifier.
}
// String returns the string representation of the path.
func (n *Context) String() string { return n.Path() }
// Path implements the Path interface.
func (n *Context) Path() string {
return fmt.Sprintf("%v<%v>", n.Contexts, id.ID(n.ID))
}
// Base implements the Path interface, returning the path to the hierarchy.
func (n *Context) Base() Path {
return n.Contexts
}
// Clone implements the Path interface, returning a deep-copy of this path.
func (n *Context) Clone() Path {
return &Context{Contexts: n.Contexts.Clone().(*Contexts), ID: n.ID}
}
// Validate implements the Path interface.
func (n *Context) Validate() error {
switch {
case n == nil:
return fmt.Errorf("Context is nil")
case n.Contexts == nil:
return fmt.Errorf("Context.Contexts is nil")
case !id.ID(n.ID).IsValid():
return fmt.Errorf("Context.ID is invalid")
}
return n.Contexts.Validate()
}