Protect meta aquisition in Scheme

This commit is contained in:
Alexander Nozik 2021-08-08 15:29:57 +03:00
parent c01bc36d41
commit e5f422f9ca
2 changed files with 10 additions and 8 deletions

View File

@ -4,7 +4,7 @@ plugins {
allprojects {
group = "space.kscience"
version = "0.5.0-dev-9"
version = "0.5.0-dev-10"
}
subprojects {

View File

@ -10,17 +10,19 @@ import space.kscience.dataforge.values.Value
*/
public open class Scheme : Described, MetaRepr, MutableMetaProvider, Configurable {
final override var meta: ObservableMutableMeta = MutableMeta()
private set
private var _meta = MutableMeta()
final override var descriptor: MetaDescriptor? = null
internal set
final override val meta: ObservableMutableMeta get() = _meta
internal var metaDescriptor: MetaDescriptor? = null
final override val descriptor: MetaDescriptor? get() = metaDescriptor
internal fun wrap(
items: MutableMeta,
preserveDefault: Boolean = false
) {
meta = (if (preserveDefault) items.withDefault(meta.seal()) else items).asObservable()
_meta = (if (preserveDefault) items.withDefault(meta.seal()) else items).asObservable()
}
/**
@ -69,7 +71,7 @@ public open class SchemeSpec<out T : Scheme>(
private val builder: () -> T,
) : Specification<T>, Described {
override fun read(source: Meta): T = empty().also {
override fun read(source: Meta): T = builder().also {
it.wrap(MutableMeta().withDefault(source))
}
@ -81,7 +83,7 @@ public open class SchemeSpec<out T : Scheme>(
override val descriptor: MetaDescriptor? get() = null
override fun empty(): T = builder().also {
it.descriptor = descriptor
it.metaDescriptor = descriptor
}
@Suppress("OVERRIDE_BY_INLINE")