From e5f422f9ca3802a9a8006f9d70d045f0087f5a66 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 8 Aug 2021 15:29:57 +0300 Subject: [PATCH] Protect meta aquisition in Scheme --- build.gradle.kts | 2 +- .../space/kscience/dataforge/meta/Scheme.kt | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c86da3cc..b89652f3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { allprojects { group = "space.kscience" - version = "0.5.0-dev-9" + version = "0.5.0-dev-10" } subprojects { diff --git a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/Scheme.kt b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/Scheme.kt index 3cf40a76..f7abc1f5 100644 --- a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/Scheme.kt +++ b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/Scheme.kt @@ -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( private val builder: () -> T, ) : Specification, 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( override val descriptor: MetaDescriptor? get() = null override fun empty(): T = builder().also { - it.descriptor = descriptor + it.metaDescriptor = descriptor } @Suppress("OVERRIDE_BY_INLINE")