Skip to content

Commit 0ef9ad9

Browse files
committed
pointers *.NULL
1 parent 6057f92 commit 0ef9ad9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/main/kotlin/kool/pointers.kt

+28
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ inline class BytePtr(val adr: Adr) {
3434

3535
inline operator fun plus(offset: Int): BytePtr = BytePtr(adr + offset * Byte.BYTES)
3636
// inline operator fun plus(pByte: BytePtr): BytePtr = BytePtr(adr + pByte.adr)
37+
38+
companion object {
39+
val NULL get() = BytePtr(MemoryUtil.NULL)
40+
}
3741
}
3842

3943
inline fun BytePtr(intPtr: IntPtr) = BytePtr(intPtr.adr)
@@ -61,6 +65,10 @@ inline class ShortPtr(val adr: Adr) {
6165
inline operator fun invoke(): Short = UNSAFE.getShort(null, adr)
6266

6367
inline operator fun plus(offset: Int): ShortPtr = ShortPtr(adr + offset * Short.BYTES)
68+
69+
companion object {
70+
val NULL get() = ShortPtr(MemoryUtil.NULL)
71+
}
6472
}
6573

6674
inline fun ShortPtr(bytePtr: BytePtr) = ShortPtr(bytePtr.adr)
@@ -83,6 +91,10 @@ inline class IntPtr(val adr: Adr) {
8391
inline operator fun invoke(): Int = UNSAFE.getInt(null, adr)
8492

8593
inline operator fun plus(offset: Int): IntPtr = IntPtr(adr + offset * Int.BYTES)
94+
95+
companion object {
96+
val NULL get() = IntPtr(MemoryUtil.NULL)
97+
}
8698
}
8799

88100
inline fun IntPtr(bytePtr: BytePtr) = IntPtr(bytePtr.adr)
@@ -106,6 +118,10 @@ inline class LongPtr(val adr: Adr) {
106118
inline operator fun invoke(): Long = UNSAFE.getLong(null, adr)
107119

108120
inline operator fun plus(offset: Int): LongPtr = LongPtr(adr + offset * Long.BYTES)
121+
122+
companion object {
123+
val NULL get() = LongPtr(MemoryUtil.NULL)
124+
}
109125
}
110126

111127
inline fun LongPtr(bytePtr: BytePtr) = LongPtr(bytePtr.adr)
@@ -129,6 +145,10 @@ inline class FloatPtr(val adr: Adr) {
129145
inline operator fun invoke(): Float = UNSAFE.getFloat(null, adr)
130146

131147
inline operator fun plus(offset: Int): FloatPtr = FloatPtr(adr + offset * Float.BYTES)
148+
149+
companion object {
150+
val NULL get() = FloatPtr(MemoryUtil.NULL)
151+
}
132152
}
133153

134154
inline fun FloatPtr(bytePtr: BytePtr) = FloatPtr(bytePtr.adr)
@@ -152,6 +172,10 @@ inline class DoublePtr(val adr: Adr) {
152172
inline operator fun invoke(): Double = UNSAFE.getDouble(null, adr)
153173

154174
inline operator fun plus(offset: Int): DoublePtr = DoublePtr(adr + offset * Double.BYTES)
175+
176+
companion object {
177+
val NULL get() = DoublePtr(MemoryUtil.NULL)
178+
}
155179
}
156180

157181
inline fun DoublePtr(bytePtr: BytePtr) = DoublePtr(bytePtr.adr)
@@ -177,6 +201,10 @@ inline class PointerPtr(val adr: Adr) {
177201
inline operator fun invoke(): Ptr = UNSAFE.getLong(null, adr)
178202

179203
inline operator fun plus(offset: Int): PointerPtr = PointerPtr(adr + offset * Long.BYTES)
204+
205+
companion object {
206+
val NULL get() = PointerPtr(MemoryUtil.NULL)
207+
}
180208
}
181209

182210
inline fun PointerPtr(bytePtr: BytePtr) = PointerPtr(bytePtr.adr)

0 commit comments

Comments
 (0)