diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/ChildCloseableState.kt b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/ChildCloseableState.kt index 7a32ffc..9954050 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/ChildCloseableState.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/ChildCloseableState.kt @@ -29,6 +29,7 @@ public sealed class ChildCloseableState : CloseableState { override fun finishUsage(): Unit = this._state.finishUsage() + @Destructor @ManualStateManipulation override fun close() { this._state.finishUsage() diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/CloseableState.kt b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/CloseableState.kt index 3146172..cc4be3a 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/CloseableState.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/CloseableState.kt @@ -11,6 +11,7 @@ public interface CloseableState { @ManualStateManipulation public fun finishUsage() + @Destructor @ManualStateManipulation public fun close() diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/CloseableStateCloseableWrapper.kt b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/CloseableStateCloseableWrapper.kt index 26c27d5..73e6f14 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/CloseableStateCloseableWrapper.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/CloseableStateCloseableWrapper.kt @@ -19,6 +19,7 @@ public expect class CloseableStateCloseableWrapper : CloseableState.ExternallySy @ManualStateManipulation override fun finishUsage(close: Boolean) + @Destructor @ManualStateManipulation override fun close() diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/Destructor.kt b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/Destructor.kt new file mode 100644 index 0000000..2f9a6f9 --- /dev/null +++ b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/Destructor.kt @@ -0,0 +1,8 @@ +package ru.landgrafhomyak.utility.closeable_state_1 + +/** + * Utility annotation to simplify searching method that closes/destructs/deallocs object. + */ +@Target(AnnotationTarget.FUNCTION) +@Retention(AnnotationRetention.SOURCE) +public annotation class Destructor() diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/ErrorOnConcurrentAccessState.kt b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/ErrorOnConcurrentAccessState.kt index 0a86903..ddb5edb 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/ErrorOnConcurrentAccessState.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/ErrorOnConcurrentAccessState.kt @@ -24,6 +24,7 @@ public expect open class ErrorOnConcurrentAccessState : CloseableState.Externall @ManualStateManipulation public final override fun finishUsage(close: Boolean) + @Destructor @ManualStateManipulation public final override fun close() diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/HandleWrapper.kt b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/HandleWrapper.kt index 7d274fe..81b7a0f 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/HandleWrapper.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/HandleWrapper.kt @@ -16,6 +16,7 @@ public class HandleWrapper( return this.state.withUse { method(this.handle) } } + @Destructor @ManualStateManipulation public fun close() { this.state.close() diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/UsagesCounter.kt b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/UsagesCounter.kt index b514da2..6cb2f4f 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/UsagesCounter.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/UsagesCounter.kt @@ -22,6 +22,7 @@ public expect open class UsagesCounter : CloseableState.AllowsConcurrency { @ManualStateManipulation public final override fun finishUsage() + @Destructor @ManualStateManipulation public final override fun close() diff --git a/src/jvmMain/java/ru/landgrafhomyak/utility/closeable_state_1/jCloseableStateCloseableWrapper.java b/src/jvmMain/java/ru/landgrafhomyak/utility/closeable_state_1/jCloseableStateCloseableWrapper.java index 6bbfa21..f6d6c02 100644 --- a/src/jvmMain/java/ru/landgrafhomyak/utility/closeable_state_1/jCloseableStateCloseableWrapper.java +++ b/src/jvmMain/java/ru/landgrafhomyak/utility/closeable_state_1/jCloseableStateCloseableWrapper.java @@ -58,6 +58,7 @@ public final class jCloseableStateCloseableWrapper this._self.finishUsage(close); } + @Destructor @Override public void close() { this._self.close(); diff --git a/src/jvmMain/java/ru/landgrafhomyak/utility/closeable_state_1/jErrorOnConcurrentAccessState.java b/src/jvmMain/java/ru/landgrafhomyak/utility/closeable_state_1/jErrorOnConcurrentAccessState.java index 432eeb5..57da347 100644 --- a/src/jvmMain/java/ru/landgrafhomyak/utility/closeable_state_1/jErrorOnConcurrentAccessState.java +++ b/src/jvmMain/java/ru/landgrafhomyak/utility/closeable_state_1/jErrorOnConcurrentAccessState.java @@ -65,6 +65,7 @@ public /* open */ class jErrorOnConcurrentAccessState this._finishUsage(close ? State.CLOSED : State.OPEN); } + @Destructor @Override public final void close() { switch (this._currentState.compareAndExchange(State.OPEN, State.CLOSED)) { diff --git a/src/jvmMain/java/ru/landgrafhomyak/utility/closeable_state_1/jUsagesCounter.java b/src/jvmMain/java/ru/landgrafhomyak/utility/closeable_state_1/jUsagesCounter.java index 348ece1..0be54c7 100644 --- a/src/jvmMain/java/ru/landgrafhomyak/utility/closeable_state_1/jUsagesCounter.java +++ b/src/jvmMain/java/ru/landgrafhomyak/utility/closeable_state_1/jUsagesCounter.java @@ -50,6 +50,7 @@ public /* open */ class jUsagesCounter } } + @Destructor @Override public final void close() { long currentReferencesCount; diff --git a/src/nonJvmMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/CloseableStateCloseableWrapper.kt b/src/nonJvmMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/CloseableStateCloseableWrapper.kt index 63889ff..d6494a4 100644 --- a/src/nonJvmMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/CloseableStateCloseableWrapper.kt +++ b/src/nonJvmMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/CloseableStateCloseableWrapper.kt @@ -48,6 +48,7 @@ public actual class CloseableStateCloseableWrapper : CloseableState.ExternallySy this._self.finishUsage(close) } + @Destructor @ManualStateManipulation actual override fun close() { this._self.close() diff --git a/src/nonJvmMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/ErrorOnConcurrentAccessState.kt b/src/nonJvmMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/ErrorOnConcurrentAccessState.kt index ff9e2a1..0834fc9 100644 --- a/src/nonJvmMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/ErrorOnConcurrentAccessState.kt +++ b/src/nonJvmMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/ErrorOnConcurrentAccessState.kt @@ -59,6 +59,7 @@ public actual open class ErrorOnConcurrentAccessState : CloseableState.Externall public actual final override fun finishUsage(close: Boolean): Unit = this._finishUsage(if (close) State.CLOSED else State.OPEN) + @Destructor @ManualStateManipulation public actual final override fun close() { when (this._state.compareAndExchange(State.OPEN, State.CLOSED)) { diff --git a/src/nonJvmMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/UsagesCounter.kt b/src/nonJvmMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/UsagesCounter.kt index a1302fc..648ded7 100644 --- a/src/nonJvmMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/UsagesCounter.kt +++ b/src/nonJvmMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/UsagesCounter.kt @@ -43,6 +43,7 @@ public actual open class UsagesCounter : CloseableState.AllowsConcurrency { this._value.update(Long::dec) } + @Destructor @ManualStateManipulation public actual final override fun close() { val state = this._value.compareAndExchange(0, _MiscMultiplatform.CLOSED_STATE_VALUE)