From 5eb2bcfce6273f886cada41db84e010cde6f043f Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 8 Mar 2019 11:34:51 +0300 Subject: [PATCH] Fixed config delegates --- .../hep/dataforge/meta/ConfigDelegates.kt | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/ConfigDelegates.kt diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/ConfigDelegates.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/ConfigDelegates.kt new file mode 100644 index 00000000..581fa7ed --- /dev/null +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/ConfigDelegates.kt @@ -0,0 +1,42 @@ +package hep.dataforge.meta + +import hep.dataforge.values.Null +import hep.dataforge.values.Value +import kotlin.jvm.JvmName + + +//Configurable delegates + +/** + * A property delegate that uses custom key + */ +fun Configurable.value(default: Value = Null, key: String? = null) = + ValueConfigDelegate(config, key, default) + +fun Configurable.string(default: String? = null, key: String? = null) = + StringConfigDelegate(config, key, default) + +fun Configurable.boolean(default: Boolean? = null, key: String? = null) = + BooleanConfigDelegate(config, key, default) + +fun Configurable.number(default: Number? = null, key: String? = null) = + NumberConfigDelegate(config, key, default) + +fun Configurable.child(key: String? = null) = MetaNodeDelegate(config, key) + +//fun Configurable.spec(spec: Specification, key: String? = null) = ChildConfigDelegate(key) { spec.wrap(this) } + +@JvmName("safeString") +fun Configurable.string(default: String, key: String? = null) = + SafeStringConfigDelegate(config, key, default) + +@JvmName("safeBoolean") +fun Configurable.boolean(default: Boolean, key: String? = null) = + SafeBooleanConfigDelegate(config, key, default) + +@JvmName("safeNumber") +fun Configurable.number(default: Number, key: String? = null) = + SafeNumberConfigDelegate(config, key, default) + +inline fun > Configurable.enum(default: E, key: String? = null) = + SafeEnumvConfigDelegate(config, key, default) { enumValueOf(it) } \ No newline at end of file