More access to HandleWrapper members because it anyway must be wrapped
This commit is contained in:
parent
bdb1fe56fa
commit
4b799c0ecf
@ -15,7 +15,7 @@ buildscript {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "ru.landgrafhomyak.utility"
|
group = "ru.landgrafhomyak.utility"
|
||||||
version = "1.1"
|
version = "1.2"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|||||||
@ -4,24 +4,22 @@ import kotlin.contracts.InvocationKind
|
|||||||
import kotlin.contracts.contract
|
import kotlin.contracts.contract
|
||||||
|
|
||||||
public class HandleWrapper<H>(
|
public class HandleWrapper<H>(
|
||||||
handle: H,
|
public val handle: H,
|
||||||
state: CloseableState,
|
public val state: CloseableState,
|
||||||
) {
|
) {
|
||||||
private val _unprotected = handle
|
|
||||||
private val _state: CloseableState = state
|
|
||||||
|
|
||||||
public fun <R> useHandle(method: (H) -> R): R {
|
public fun <R> useHandle(method: (H) -> R): R {
|
||||||
contract {
|
contract {
|
||||||
callsInPlace(method, InvocationKind.EXACTLY_ONCE)
|
callsInPlace(method, InvocationKind.EXACTLY_ONCE)
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._state.withUse { method(this._unprotected) }
|
return this.state.withUse { method(this.handle) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ManualStateManipulation
|
@ManualStateManipulation
|
||||||
private fun close() {
|
public fun close() {
|
||||||
this._state.close()
|
this.state.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String = "<wrapper of handle=${this._unprotected} protected with state=${this._state}>"
|
override fun toString(): String = "<wrapper of handle=${this.handle} protected with state=${this.state}>"
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user