blob: 4e3a768cb9aa852b72ab3c81ff5e3600b7f96322 [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"
)
// AtomRange is a path that refers to an interval of atoms in an atom list.
type AtomRange struct {
binary.Generate
Atoms *Atoms // The path to the list of atoms.
First uint64 // The index of the first atom in the range
Count uint64 // The number of atoms in the range
}
// String returns the string representation of the path.
func (n *AtomRange) String() string { return n.Path() }
// Path implements the Path interface.
func (n *AtomRange) Path() string {
return fmt.Sprintf("%v[%d-%d]", n.Atoms, n.First, n.First+n.Count)
}
// Base implements the Path interface, returning the path to the atom list.
func (n *AtomRange) Base() Path {
return n.Atoms
}
// Clone implements the Path interface, returning a deep-copy of this path.
func (n *AtomRange) Clone() Path {
return &AtomRange{Atoms: n.Atoms.Clone().(*Atoms), First: n.First, Count: n.Count}
}
// Validate implements the Path interface.
func (n *AtomRange) Validate() error {
switch {
case n == nil:
return fmt.Errorf("AtomRange is nil")
case n.Atoms == nil:
return fmt.Errorf("AtomRange.Atoms is nil")
}
return n.Atoms.Validate()
}
// FindAtomRange returns the first AtomRange found traversing the path p.
// If no Atom was found, then nil is returned.
func FindAtomRange(p Path) *AtomRange {
for p != nil {
if p, ok := p.(*AtomRange); ok {
return p
}
p = p.Base()
}
return nil
}