Minor updates for mutable meta and builder

This commit is contained in:
Alexander Nozik 2019-07-31 16:22:14 +03:00
parent 9f6d53f214
commit c82eda28d8
4 changed files with 27 additions and 8 deletions

View File

@ -1,6 +1,6 @@
plugins {
id("scientifik.mpp") version "0.1.4-dev" apply false
id("scientifik.publish") version "0.1.4-dev" apply false
id("scientifik.mpp") version "0.1.4" apply false
id("scientifik.publish") version "0.1.4" apply false
}
val dataforgeVersion by extra("0.1.3-dev-10")

View File

@ -7,6 +7,11 @@ import hep.dataforge.names.plus
//TODO add validator to configuration
data class MetaListener(
val owner: Any? = null,
val action: (name: Name, oldItem: MetaItem<*>?, newItem: MetaItem<*>?) -> Unit
)
/**
* Mutable meta representing object state
*/

View File

@ -1,5 +1,6 @@
package hep.dataforge.meta
import hep.dataforge.names.Name
import hep.dataforge.names.asName
import hep.dataforge.values.Value
@ -28,6 +29,25 @@ class MetaBuilder : AbstractMutableMeta<MetaBuilder>() {
infix fun String.to(metaBuilder: MetaBuilder.() -> Unit) {
this@MetaBuilder[this] = MetaBuilder().apply(metaBuilder)
}
infix fun Name.to(value: Any) {
if (value is Meta) {
this@MetaBuilder[this] = value
}
this@MetaBuilder[this] = Value.of(value)
}
infix fun Name.to(meta: Meta) {
this@MetaBuilder[this] = meta
}
infix fun Name.to(value: Iterable<Meta>) {
this@MetaBuilder[this] = value.toList()
}
infix fun Name.to(metaBuilder: MetaBuilder.() -> Unit) {
this@MetaBuilder[this] = MetaBuilder().apply(metaBuilder)
}
}
/**

View File

@ -3,12 +3,6 @@ package hep.dataforge.meta
import hep.dataforge.names.*
import hep.dataforge.values.Value
internal data class MetaListener(
val owner: Any? = null,
val action: (name: Name, oldItem: MetaItem<*>?, newItem: MetaItem<*>?) -> Unit
)
interface MutableMeta<M : MutableMeta<M>> : MetaNode<M> {
override val items: Map<NameToken, MetaItem<M>>
operator fun set(name: Name, item: MetaItem<*>?)