diff --git a/dataforge-meta/api/dataforge-meta.api b/dataforge-meta/api/dataforge-meta.api index 2b0ea50f..06b46d01 100644 --- a/dataforge-meta/api/dataforge-meta.api +++ b/dataforge-meta/api/dataforge-meta.api @@ -455,10 +455,11 @@ public class hep/dataforge/meta/Scheme : hep/dataforge/meta/MetaRepr, hep/datafo } public final class hep/dataforge/meta/SchemeKt { - public static final fun inflate (Lhep/dataforge/meta/Specification;Lhep/dataforge/meta/MutableItemProvider;Lhep/dataforge/meta/ItemProvider;Lhep/dataforge/meta/descriptors/NodeDescriptor;)Lhep/dataforge/meta/Scheme; - public static synthetic fun inflate$default (Lhep/dataforge/meta/Specification;Lhep/dataforge/meta/MutableItemProvider;Lhep/dataforge/meta/ItemProvider;Lhep/dataforge/meta/descriptors/NodeDescriptor;ILjava/lang/Object;)Lhep/dataforge/meta/Scheme; public static final fun invoke (Lhep/dataforge/meta/Scheme;Lkotlin/jvm/functions/Function1;)Lhep/dataforge/meta/Scheme; public static final fun isEmpty (Lhep/dataforge/meta/Scheme;)Z + public static final fun retarget (Lhep/dataforge/meta/Scheme;Lhep/dataforge/meta/MutableItemProvider;)Lhep/dataforge/meta/Scheme; + public static final fun wrap (Lhep/dataforge/meta/Specification;Lhep/dataforge/meta/MutableItemProvider;Lhep/dataforge/meta/ItemProvider;Lhep/dataforge/meta/descriptors/NodeDescriptor;)Lhep/dataforge/meta/Scheme; + public static synthetic fun wrap$default (Lhep/dataforge/meta/Specification;Lhep/dataforge/meta/MutableItemProvider;Lhep/dataforge/meta/ItemProvider;Lhep/dataforge/meta/descriptors/NodeDescriptor;ILjava/lang/Object;)Lhep/dataforge/meta/Scheme; } public class hep/dataforge/meta/SchemeSpec : hep/dataforge/meta/Specification, hep/dataforge/meta/descriptors/Described { diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Scheme.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Scheme.kt index 8875e762..b2a82ca7 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Scheme.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Scheme.kt @@ -17,7 +17,7 @@ public open class Scheme() : MutableItemProvider, Described, MetaRepr { final override var descriptor: NodeDescriptor? = null - internal fun inflate( + internal fun wrap( items: MutableItemProvider, default: ItemProvider? = null, descriptor: NodeDescriptor? = null, @@ -84,14 +84,23 @@ public open class Scheme() : MutableItemProvider, Described, MetaRepr { */ public fun Scheme.isEmpty(): Boolean = rootItem == null -public fun > S.inflate( +/** + * Create a new empty [Scheme] object (including defaults) and inflate it around existing [MutableItemProvider]. + * Items already present in the scheme are used as defaults. + */ +public fun > S.wrap( items: MutableItemProvider, default: ItemProvider? = null, descriptor: NodeDescriptor? = null, ): T = empty().apply { - inflate(items, default, descriptor) + wrap(items, default, descriptor) } +/** + * Relocate scheme target onto given [MutableItemProvider]. Old provider does not get updates anymore. + * Current state of the scheme used as a default. + */ +public fun T.retarget(provider: MutableItemProvider) :T = apply { wrap(provider) } /** * A shortcut to edit a [Scheme] object in-place @@ -107,10 +116,10 @@ public open class SchemeSpec( override fun empty(): T = builder() - override fun read(items: ItemProvider): T = inflate(Config(), items, descriptor) + override fun read(items: ItemProvider): T = wrap(Config(), items, descriptor) override fun write(target: MutableItemProvider, defaultProvider: ItemProvider): T = - inflate(target, defaultProvider, descriptor) + wrap(target, defaultProvider, descriptor) //TODO Generate descriptor from Scheme class override val descriptor: NodeDescriptor? get() = null diff --git a/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/SpecificationTest.kt b/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/SpecificationTest.kt index 0f826c2c..ddf06c1b 100644 --- a/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/SpecificationTest.kt +++ b/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/SpecificationTest.kt @@ -14,10 +14,10 @@ class SpecificationTest { override fun empty(): TestScheme = TestScheme() override fun read(items: ItemProvider): TestScheme = - inflate(Config(), items) + wrap(Config(), items) override fun write(target: MutableItemProvider, defaultProvider: ItemProvider): TestScheme = - inflate(target, defaultProvider) + wrap(target, defaultProvider) } }