From 42262babfabed037f5fcc840ecf37dc905ac3364 Mon Sep 17 00:00:00 2001 From: dankito Date: Tue, 14 Jul 2020 17:07:53 +0200 Subject: [PATCH] Added Freezer to be able to freeze objects from common code (non-Native implementations just do nothing) --- .../dankito/utils/multiplatform/Freezer.kt | 14 +++++++++++++ .../dankito/utils/multiplatform/Freezer.kt | 21 +++++++++++++++++++ .../dankito/utils/multiplatform/Freezer.kt | 18 ++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 common/src/commonMain/kotlin/net/dankito/utils/multiplatform/Freezer.kt create mode 100644 common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Freezer.kt create mode 100644 common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/Freezer.kt diff --git a/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/Freezer.kt b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/Freezer.kt new file mode 100644 index 00000000..7d9a7afd --- /dev/null +++ b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/Freezer.kt @@ -0,0 +1,14 @@ +package net.dankito.utils.multiplatform + + +expect class Freezer() { + + companion object { + + fun freeze(obj: T): T + + fun isFrozen(obj: Any): Boolean + + } + +} \ No newline at end of file diff --git a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Freezer.kt b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Freezer.kt new file mode 100644 index 00000000..c7edba73 --- /dev/null +++ b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Freezer.kt @@ -0,0 +1,21 @@ +package net.dankito.utils.multiplatform + +import kotlin.native.concurrent.freeze +import kotlin.native.concurrent.isFrozen + + +actual class Freezer { + + actual companion object { + + actual fun freeze(obj: T): T { + return obj.freeze() + } + + actual fun isFrozen(obj: Any): Boolean { + return obj.isFrozen + } + + } + +} \ No newline at end of file diff --git a/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/Freezer.kt b/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/Freezer.kt new file mode 100644 index 00000000..72c52a04 --- /dev/null +++ b/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/Freezer.kt @@ -0,0 +1,18 @@ +package net.dankito.utils.multiplatform + + +actual class Freezer { + + actual companion object { + + actual fun freeze(obj: T): T { + return obj // no op + } + + actual fun isFrozen(obj: Any): Boolean { + return false // freezing is only possible on Kotlin/Native + } + + } + +} \ No newline at end of file