Multiplatform plugin repository.
This commit is contained in:
parent
ec833dd13c
commit
25248f6cca
@ -5,13 +5,15 @@ import kotlin.reflect.KClass
|
||||
|
||||
interface PluginFactory {
|
||||
val tag: PluginTag
|
||||
val type: KClass<Plugin>
|
||||
val type: KClass<out Plugin>
|
||||
fun build(meta: Meta): Plugin
|
||||
}
|
||||
|
||||
|
||||
expect object PluginRepository {
|
||||
|
||||
fun register(factory: PluginFactory)
|
||||
|
||||
/**
|
||||
* List plugins available in the repository
|
||||
*/
|
||||
|
@ -1,11 +1,33 @@
|
||||
package hep.dataforge.context
|
||||
|
||||
import hep.dataforge.meta.Meta
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
||||
actual object PluginRepository {
|
||||
|
||||
private val factories: MutableSet<PluginFactory> = HashSet()
|
||||
|
||||
actual fun register(factory: PluginFactory) {
|
||||
factories.add(factory)
|
||||
}
|
||||
|
||||
fun <T : Plugin> register(tag: PluginTag, type: KClass<out Plugin>, constructor: (Meta) -> T) {
|
||||
val factory = object : PluginFactory {
|
||||
override val tag: PluginTag = tag
|
||||
override val type: KClass<out Plugin> = type
|
||||
|
||||
override fun build(meta: Meta): Plugin = constructor(meta)
|
||||
|
||||
}
|
||||
register(factory)
|
||||
}
|
||||
|
||||
inline fun <reified T : Plugin> register(tag: PluginTag, noinline constructor: (Meta) -> T) =
|
||||
register(tag, T::class, constructor)
|
||||
|
||||
/**
|
||||
* List plugins available in the repository
|
||||
*/
|
||||
actual fun list(): Sequence<PluginFactory> {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
actual fun list(): Sequence<PluginFactory> = factories.asSequence()
|
||||
}
|
@ -1,9 +1,17 @@
|
||||
package hep.dataforge.context
|
||||
|
||||
actual object PluginRepository {
|
||||
|
||||
private val factories: MutableSet<PluginFactory> = HashSet()
|
||||
|
||||
actual fun register(factory: PluginFactory) {
|
||||
factories.add(factory)
|
||||
}
|
||||
|
||||
/**
|
||||
* List plugins available in the repository
|
||||
*/
|
||||
actual fun list(): Sequence<PluginFactory> = Global.services(PluginFactory::class)
|
||||
actual fun list(): Sequence<PluginFactory> =
|
||||
factories.asSequence() + Global.services(PluginFactory::class)
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user