| // Copyright (C) 2015 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/binary" |
| "android.googlesource.com/platform/tools/gpu/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(c interface{}, d Database, l log.Logger) (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 binary.ID) binary.ID { |
| b := bytes.Buffer{} |
| b.WriteString("lazy:") |
| b.WriteString(in.String()) |
| return binary.NewID(b.Bytes()) |
| } |