sbt/cache/HListCache.scala

47 lines
1.3 KiB
Scala
Raw Normal View History

/* sbt -- Simple Build Tool
* Copyright 2009 Mark Harrah
*/
package sbt
2009-08-16 20:29:08 +02:00
import java.io.{InputStream,OutputStream}
import Types._
2009-08-16 20:29:08 +02:00
class HNilInputCache extends NoInputCache[HNil]
class HConsInputCache[H,T <: HList](val headCache: InputCache[H], val tailCache: InputCache[T]) extends InputCache[H :+: T]
2009-08-16 20:29:08 +02:00
{
def uptodate(in: H :+: T)(cacheStream: InputStream) =
2009-08-16 20:29:08 +02:00
{
2009-12-12 00:56:09 +01:00
val headResult = headCache.uptodate(in.head)(cacheStream)
val tailResult = tailCache.uptodate(in.tail)(cacheStream)
2009-08-16 20:29:08 +02:00
new CacheResult
{
2009-12-12 00:56:09 +01:00
val uptodate = headResult.uptodate && tailResult.uptodate
2009-08-16 20:29:08 +02:00
def update(outputStream: OutputStream) =
{
headResult.update(outputStream)
tailResult.update(outputStream)
}
}
}
def force(in: H :+: T)(cacheStream: OutputStream) =
2009-08-16 20:29:08 +02:00
{
headCache.force(in.head)(cacheStream)
tailCache.force(in.tail)(cacheStream)
}
}
class HNilOutputCache extends NoOutputCache[HNil](HNil)
class HConsOutputCache[H,T <: HList](val headCache: OutputCache[H], val tailCache: OutputCache[T]) extends OutputCache[H :+: T]
2009-08-16 20:29:08 +02:00
{
def loadCached(cacheStream: InputStream) =
{
val head = headCache.loadCached(cacheStream)
val tail = tailCache.loadCached(cacheStream)
HCons(head, tail)
}
def update(out: H :+: T)(cacheStream: OutputStream)
2009-08-16 20:29:08 +02:00
{
headCache.update(out.head)(cacheStream)
tailCache.update(out.tail)(cacheStream)
}
}