commonMain.it.unibo.tuprolog.bdd.impl.utils.CastVisitor.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bdd-jvm Show documentation
Show all versions of bdd-jvm Show documentation
Multi-platform library for representing and manipulating Binary Decision Diagrams
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