All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.it.unibo.tuprolog.bdd.impl.utils.CastVisitor.kt Maven / Gradle / Ivy

Go to download

Multi-platform library for representing and manipulating Binary Decision Diagrams

There is a newer version: 1.0.4
Show newest version
package it.unibo.tuprolog.bdd.impl.utils

import it.unibo.tuprolog.bdd.BinaryDecisionDiagram
import it.unibo.tuprolog.bdd.BinaryDecisionDiagramVisitor

/**
 * This visitor simulates the behavior of the `when` statement for
 * simple casting purposes. By using this we avoid type checking,
 * which is unoptimized in some target platforms (JS).
 *
 * The following code snippet shows how to properly use this visitor:
 * ```
 * val castVisitor = CastVisitor<...>()
 * castVisitor.onTerminal = { it -> /* Handle terminal case */ }
 * castVisitor.onVariable = { it -> /* Handle variable case */ }
 * bdd.accept(castVisitor)
 * ```
 *
 * @author Jason Dellaluce
 * */
internal class CastVisitor, E> :
    BinaryDecisionDiagramVisitor {
    var onTerminal: ((o: BinaryDecisionDiagram.Terminal) -> E)? = null
    var onVariable: ((o: BinaryDecisionDiagram.Variable) -> E)? = null

    override fun visit(
        node: BinaryDecisionDiagram.Terminal
    ): E = onTerminal!!(node)

    override fun visit(
        node: BinaryDecisionDiagram.Variable
    ): E = onVariable!!(node)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy