diff --git a/build.gradle.kts b/build.gradle.kts index b89652f3..9707d991 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { allprojects { group = "space.kscience" - version = "0.5.0-dev-10" + version = "0.5.0-dev-11" } subprojects { diff --git a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/Meta.kt b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/Meta.kt index 2e2e4a10..c8313512 100644 --- a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/Meta.kt +++ b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/Meta.kt @@ -19,8 +19,10 @@ public interface MetaRepr { /** * A container for meta nodes */ -public fun interface MetaProvider { +public fun interface MetaProvider : ValueProvider { public fun getMeta(name: Name): Meta? + + override fun getValue(name: Name): Value? = getMeta(name)?.value } /** diff --git a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MutableMeta.kt b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MutableMeta.kt index a674aaa1..527b6cbe 100644 --- a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MutableMeta.kt +++ b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MutableMeta.kt @@ -4,6 +4,7 @@ import kotlinx.serialization.Serializable import space.kscience.dataforge.misc.DFExperimental import space.kscience.dataforge.names.* import space.kscience.dataforge.values.EnumValue +import space.kscience.dataforge.values.MutableValueProvider import space.kscience.dataforge.values.Value import space.kscience.dataforge.values.asValue import kotlin.js.JsName @@ -19,10 +20,12 @@ public annotation class MetaBuilder /** * A generic interface that gives access to getting and setting meta notes and values */ -public interface MutableMetaProvider : MetaProvider { +public interface MutableMetaProvider : MetaProvider, MutableValueProvider { override fun getMeta(name: Name): MutableMeta? public fun setMeta(name: Name, node: Meta?) - public fun setValue(name: Name, value: Value?) + override fun setValue(name: Name, value: Value?) { + getMeta(name)?.value = value + } } /** 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 0a5ce63c..d4f40eb4 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 @@ -12,8 +12,14 @@ import kotlin.jvm.Synchronized */ public open class Scheme : Described, MetaRepr, MutableMetaProvider, Configurable { + /** + * Meta to be mutated by this schme + */ private var targetMeta: MutableMeta = MutableMeta() + /** + * Default values provided by this scheme + */ private var defaultMeta: Meta? = null final override val meta: ObservableMutableMeta = SchemeMeta(Name.EMPTY) @@ -25,7 +31,7 @@ public open class Scheme : Described, MetaRepr, MutableMetaProvider, Configurabl newMeta: MutableMeta, preserveDefault: Boolean = false ) { - if(preserveDefault){ + if (preserveDefault) { defaultMeta = targetMeta.seal() } targetMeta = newMeta @@ -62,12 +68,14 @@ public open class Scheme : Described, MetaRepr, MutableMetaProvider, Configurabl private inner class SchemeMeta(val pathName: Name) : ObservableMutableMeta { override var value: Value? - get() = targetMeta[pathName]?.value ?: defaultMeta?.get(pathName)?.value + get() = targetMeta[pathName]?.value + ?: defaultMeta?.get(pathName)?.value + ?: descriptor?.get(pathName)?.defaultValue set(value) { val oldValue = targetMeta[pathName]?.value targetMeta[pathName] = value if (oldValue != value) { - invalidate(pathName) + invalidate(Name.EMPTY) } } @@ -84,9 +92,9 @@ public open class Scheme : Described, MetaRepr, MutableMetaProvider, Configurabl @Synchronized override fun onChange(owner: Any?, callback: Meta.(name: Name) -> Unit) { - listeners.add(MetaListener(owner) { changedeName -> - if (changedeName.startsWith(pathName)) { - this@Scheme.meta.callback(changedeName.removeHeadOrNull(pathName)!!) + listeners.add(MetaListener(owner) { changedName -> + if (changedName.startsWith(pathName)) { + this@Scheme.meta.callback(changedName.removeHeadOrNull(pathName)!!) } }) } diff --git a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/values/ValueProvider.kt b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/values/ValueProvider.kt new file mode 100644 index 00000000..f7600145 --- /dev/null +++ b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/values/ValueProvider.kt @@ -0,0 +1,17 @@ +package space.kscience.dataforge.values + +import space.kscience.dataforge.names.Name + +/** + * An object that could provide values + */ +public fun interface ValueProvider { + public fun getValue(name: Name): Value? +} + +/** + * An object that could consume values + */ +public interface MutableValueProvider: ValueProvider{ + public fun setValue(name: Name, value: Value?) +} \ No newline at end of file