blob: 7bd85da6e51d9b6f2210bd8563825d052c031b90 [file] [log] [blame]
// 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 database
import (
"bytes"
"android.googlesource.com/platform/tools/gpu/framework/binary"
"android.googlesource.com/platform/tools/gpu/framework/id"
"android.googlesource.com/platform/tools/gpu/framework/log"
)
// Lazy is the interface for types that redirects database resolves to an
// object lazily built using BuildLazy(). The BuildLazy() method will be called
// the first time the object is resolved, and all subsequent resolves will
// return the same pre-built object.
// Lazy is commonly implemented by objects that generate data that is expensive
// to calculate but can be deterministically produced using the information
// stored in the Lazy.
type Lazy interface {
binary.Object
// BuildLazy constructs and returns the lazily-built object.
// c is the build context that was passed to the database constructor.
BuildLazy(ctx log.Context, c interface{}, d Database) (interface{}, error)
}
// LazyOutputID returns the identifier of a LazyOutput object given the
// identifier of the Lazy. The database will not contain the LazyObject with the
// returned identifier until it is built.
func LazyOutputID(in id.ID) id.ID {
b := bytes.Buffer{}
b.WriteString("lazy:")
b.WriteString(in.String())
return id.OfBytes(b.Bytes())
}