Descriptor in SchemeSpec

This commit is contained in:
Alexander Nozik 2020-11-11 10:54:52 +03:00
parent 3ab3f2766c
commit d68fbfd8a5
3 changed files with 21 additions and 11 deletions

View File

@ -2,7 +2,7 @@ plugins {
id("ru.mipt.npm.project")
}
val dataforgeVersion by extra("0.2.0-dev-6")
val dataforgeVersion by extra("0.2.0-dev-7")
val bintrayRepo by extra("dataforge")
val githubProject by extra("dataforge-core")

View File

@ -479,11 +479,11 @@ public class hep/dataforge/meta/Scheme : hep/dataforge/meta/Configurable, hep/da
public fun <init> ()V
public fun <init> (Lhep/dataforge/meta/Config;Lhep/dataforge/meta/ItemProvider;Lhep/dataforge/meta/descriptors/NodeDescriptor;)V
public synthetic fun <init> (Lhep/dataforge/meta/Config;Lhep/dataforge/meta/ItemProvider;Lhep/dataforge/meta/descriptors/NodeDescriptor;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun getConfig ()Lhep/dataforge/meta/Config;
public final fun getConfig ()Lhep/dataforge/meta/Config;
public final fun getDefaultItem (Lhep/dataforge/names/Name;)Lhep/dataforge/meta/MetaItem;
public fun getDefaultLayer ()Lhep/dataforge/meta/Meta;
public synthetic fun getDescriptor ()Lhep/dataforge/meta/descriptors/ItemDescriptor;
public fun getDescriptor ()Lhep/dataforge/meta/descriptors/NodeDescriptor;
public final fun getDescriptor ()Lhep/dataforge/meta/descriptors/NodeDescriptor;
public fun getItem (Lhep/dataforge/names/Name;)Lhep/dataforge/meta/MetaItem;
public final fun isEmpty ()Z
public fun setItem (Lhep/dataforge/names/Name;Lhep/dataforge/meta/MetaItem;)V
@ -499,9 +499,11 @@ public final class hep/dataforge/meta/SchemeKt {
public static synthetic fun toScheme$default (Lhep/dataforge/meta/Meta;Lhep/dataforge/meta/Specification;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lhep/dataforge/meta/Configurable;
}
public class hep/dataforge/meta/SchemeSpec : hep/dataforge/meta/Specification {
public class hep/dataforge/meta/SchemeSpec : hep/dataforge/meta/Specification, hep/dataforge/meta/descriptors/Described {
public fun <init> (Lkotlin/jvm/functions/Function0;)V
public fun <init> (Lkotlin/jvm/functions/Function2;)V
public fun <init> (Lkotlin/jvm/functions/Function3;)V
public synthetic fun getDescriptor ()Lhep/dataforge/meta/descriptors/ItemDescriptor;
public fun getDescriptor ()Lhep/dataforge/meta/descriptors/NodeDescriptor;
public synthetic fun wrap (Lhep/dataforge/meta/Meta;Lhep/dataforge/meta/ItemProvider;)Lhep/dataforge/meta/MutableItemProvider;
public fun wrap (Lhep/dataforge/meta/Meta;Lhep/dataforge/meta/ItemProvider;)Lhep/dataforge/meta/Scheme;
}

View File

@ -12,12 +12,16 @@ import hep.dataforge.names.asName
public open class Scheme(
config: Config = Config(),
internal var default: ItemProvider? = null,
override val descriptor: NodeDescriptor? = null,
descriptor: NodeDescriptor? = null,
) : Configurable, Described, MetaRepr {
override var config: Config = config
internal set
override var descriptor: NodeDescriptor? = descriptor
internal set
public fun getDefaultItem(name: Name): MetaItem<*>? {
return default?.getItem(name) ?: descriptor?.get(name)?.defaultItem()
}
@ -79,13 +83,14 @@ public inline operator fun <T : Scheme> T.invoke(block: T.() -> Unit): T = apply
* A specification for simplified generation of wrappers
*/
public open class SchemeSpec<T : Scheme>(
private val builder: (config: Config, defaultProvider: ItemProvider) -> T,
) : Specification<T> {
private val builder: (config: Config, defaultProvider: ItemProvider, descriptor: NodeDescriptor?) -> T,
) : Specification<T>, Described {
public constructor(emptyBuilder: () -> T) : this({ config: Config, defaultProvider: ItemProvider ->
public constructor(emptyBuilder: () -> T) : this({ config: Config, defaultProvider: ItemProvider, descriptor: NodeDescriptor? ->
emptyBuilder().apply {
this.config = config
this.default = defaultProvider
this.descriptor = descriptor
}
})
@ -93,10 +98,13 @@ public open class SchemeSpec<T : Scheme>(
* If the provided [Meta] is a [Config] use it as a scheme base, otherwise use it as default.
*/
override fun wrap(meta: Meta, defaultProvider: ItemProvider): T = if (meta is Config) {
builder(meta, defaultProvider)
builder(meta, defaultProvider, descriptor)
} else {
builder(Config(), meta.withDefault(defaultProvider))
builder(Config(), meta.withDefault(defaultProvider), descriptor)
}
//TODO Generate descriptor from Scheme class
override val descriptor: NodeDescriptor? get() = null
}
///**