com.github.stormbit.vksdk.vkapi.Bitmask.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vk-bot-sdk-kotlin Show documentation
Show all versions of vk-bot-sdk-kotlin Show documentation
The Kotlin library for working with VK api
The newest version!
package com.github.stormbit.vksdk.vkapi
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
open class Bitmask(open var mask: Int = 0) {
fun getValue(bit: Int): Boolean = mask and bit != 0
fun setValue(bit: Int) { mask = mask or bit }
fun clearValue(bit: Int) { mask = mask xor bit }
fun bitmask(bit: Int): BitmaskDelegate = BitmaskDelegate(bit)
class BitmaskDelegate(private val bit: Int) : ReadWriteProperty {
override fun getValue(thisRef: Bitmask, property: KProperty<*>) = thisRef.getValue(bit)
override fun setValue(thisRef: Bitmask, property: KProperty<*>, value: Boolean) =
if (value) thisRef.setValue(bit) else thisRef.clearValue(bit)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy