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"
|
||||
version = "1.1"
|
||||
version = "1.2"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
@ -4,24 +4,22 @@ import kotlin.contracts.InvocationKind
|
||||
import kotlin.contracts.contract
|
||||
|
||||
public class HandleWrapper<H>(
|
||||
handle: H,
|
||||
state: CloseableState,
|
||||
public val handle: H,
|
||||
public val state: CloseableState,
|
||||
) {
|
||||
private val _unprotected = handle
|
||||
private val _state: CloseableState = state
|
||||
|
||||
public fun <R> useHandle(method: (H) -> R): R {
|
||||
contract {
|
||||
callsInPlace(method, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
|
||||
return this._state.withUse { method(this._unprotected) }
|
||||
return this.state.withUse { method(this.handle) }
|
||||
}
|
||||
|
||||
@ManualStateManipulation
|
||||
private fun close() {
|
||||
this._state.close()
|
||||
public fun 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