commonMain.it.unibo.tuprolog.solve.FlagStore.kt Maven / Gradle / Ivy
package it.unibo.tuprolog.solve
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.flags.DoubleQuotes
import it.unibo.tuprolog.solve.flags.MaxArity
import it.unibo.tuprolog.solve.flags.NotableFlag
import it.unibo.tuprolog.solve.flags.Unknown
/** A storage for flags and their values */
class FlagStore private constructor(private val flags: Map) : Map by flags {
private constructor(vararg flagValues: Pair) : this(mapOf(*flagValues))
private constructor(vararg notableFlagValues: NotableFlag) : this(notableFlagValues.map { it.toPair() }.toMap())
operator fun get(notableFlag: NotableFlag): Term? =
this[notableFlag.name]
operator fun plus(flagValue: Pair): FlagStore =
FlagStore(mapOf(flagValue) + this)
operator fun plus(notableFlagValue: NotableFlag): FlagStore =
FlagStore(mapOf(notableFlagValue.toPair()) + this)
operator fun plus(flags: Map): FlagStore =
FlagStore(this.flags + flags)
operator fun minus(flagName: String): FlagStore =
FlagStore(this.flags - flagName)
operator fun minus(flagNames: Iterable): FlagStore =
FlagStore(this.flags - flagNames)
companion object {
val EMPTY = FlagStore(emptyMap())
val DEFAULT = FlagStore(
Unknown,
MaxArity,
DoubleQuotes
)
fun of(flags: Map) = FlagStore(flags)
fun of(vararg flagValues: Pair) = FlagStore(*flagValues)
fun of(vararg notableFlagValues: NotableFlag) = FlagStore(*notableFlagValues)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy