From 24de8b3752af04606ef8763b0998201fe3808a37 Mon Sep 17 00:00:00 2001 From: squid233 <60126026+squid233@users.noreply.github.com> Date: Fri, 3 Jan 2025 19:16:54 +0800 Subject: [PATCH 1/2] feat(api): [core] remove tuples --- .../src/main/java/module-info.java | 1 - .../main/java/overrungl/util/value/Pair.java | 114 ----------------- .../main/java/overrungl/util/value/Quad.java | 110 ---------------- .../java/overrungl/util/value/Triplet.java | 119 ------------------ .../java/overrungl/util/value/Tuple2.java | 106 ---------------- .../java/overrungl/util/value/Tuple3.java | 73 ----------- .../java/overrungl/util/value/Tuple4.java | 61 --------- .../java/overrungl/nfd/NFDEnumerator.java | 24 +++- .../test/java/overrungl/demo/nfd/NFDTest.java | 4 +- 9 files changed, 21 insertions(+), 591 deletions(-) delete mode 100644 modules/overrungl.core/src/main/java/overrungl/util/value/Pair.java delete mode 100644 modules/overrungl.core/src/main/java/overrungl/util/value/Quad.java delete mode 100644 modules/overrungl.core/src/main/java/overrungl/util/value/Triplet.java delete mode 100644 modules/overrungl.core/src/main/java/overrungl/util/value/Tuple2.java delete mode 100644 modules/overrungl.core/src/main/java/overrungl/util/value/Tuple3.java delete mode 100644 modules/overrungl.core/src/main/java/overrungl/util/value/Tuple4.java diff --git a/modules/overrungl.core/src/main/java/module-info.java b/modules/overrungl.core/src/main/java/module-info.java index 5309931e..5ce0a9e6 100644 --- a/modules/overrungl.core/src/main/java/module-info.java +++ b/modules/overrungl.core/src/main/java/module-info.java @@ -26,7 +26,6 @@ exports overrungl.struct; exports overrungl.upcall; exports overrungl.util; - exports overrungl.util.value; exports overrungl.internal to overrungl.glfw, overrungl.nfd, diff --git a/modules/overrungl.core/src/main/java/overrungl/util/value/Pair.java b/modules/overrungl.core/src/main/java/overrungl/util/value/Pair.java deleted file mode 100644 index 2fa291f4..00000000 --- a/modules/overrungl.core/src/main/java/overrungl/util/value/Pair.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2023 Overrun Organization - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - */ - -package overrungl.util.value; - -/** - * A pair of the same type objects. - * - * @param the type. - * @param x the first value. - * @param y the second value. - * @author squid233 - * @since 0.1.0 - */ -public /* value */ record Pair(T x, T y) { - /** - * {@return {@link #x}} - */ - public T first() { - return x; - } - - /** - * {@return {@link #y}} - */ - public T second() { - return y; - } - - /** - * {@return {@link #x}} - */ - public T left() { - return x; - } - - /** - * {@return {@link #y}} - */ - public T right() { - return y; - } - - /** - * {@return {@link #x}} - */ - public T key() { - return x; - } - - /** - * {@return {@link #y}} - */ - public T value() { - return y; - } - - /** - * A pair of integers. - * - * @param x the first value. - * @param y the second value. - * @author squid233 - * @since 0.1.0 - */ - public record OfInt(int x, int y) { - } - - /** - * A pair of longs. - * - * @param x the first value. - * @param y the second value. - * @author squid233 - * @since 0.1.0 - */ - public record OfLong(long x, long y) { - } - - /** - * A pair of floats. - * - * @param x the first value. - * @param y the second value. - * @author squid233 - * @since 0.1.0 - */ - public record OfFloat(float x, float y) { - } - - /** - * A pair of doubles. - * - * @param x the first value. - * @param y the second value. - * @author squid233 - * @since 0.1.0 - */ - public record OfDouble(double x, double y) { - } -} diff --git a/modules/overrungl.core/src/main/java/overrungl/util/value/Quad.java b/modules/overrungl.core/src/main/java/overrungl/util/value/Quad.java deleted file mode 100644 index ae1e2235..00000000 --- a/modules/overrungl.core/src/main/java/overrungl/util/value/Quad.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2023 Overrun Organization - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - */ - -package overrungl.util.value; - -/** - * A quad of thsame type objects. - * - * @param the type. - * @param x the first value. - * @param y the second value. - * @param z the third value. - * @param w the fourth value. - * @author squid233 - * @since 0.1.0 - */ -public /* value */ record Quad(T x, T y, T z, T w) { - /** - * {@return {@link #x}} - */ - public T first() { - return x; - } - - /** - * {@return {@link #y}} - */ - public T second() { - return y; - } - - /** - * {@return {@link #z}} - */ - public T third() { - return z; - } - - /** - * {@return {@link #w}} - */ - public T fourth() { - return w; - } - - /** - * A quad of integers. - * - * @param x the first value. - * @param y the second value. - * @param z the third value. - * @param w the fourth value. - * @author squid233 - * @since 0.1.0 - */ - public record OfInt(int x, int y, int z, int w) { - } - - /** - * A quad of longs. - * - * @param x the first value. - * @param y the second value. - * @param z the third value. - * @param w the fourth value. - * @author squid233 - * @since 0.1.0 - */ - public record OfLong(long x, long y, long z, long w) { - } - - /** - * A quad of floats. - * - * @param x the first value. - * @param y the second value. - * @param z the third value. - * @param w the fourth value. - * @author squid233 - * @since 0.1.0 - */ - public record OfFloat(float x, float y, float z, float w) { - } - - /** - * A quad of doubles. - * - * @param x the first value. - * @param y the second value. - * @param z the third value. - * @param w the fourth value. - * @author squid233 - * @since 0.1.0 - */ - public record OfDouble(double x, double y, double z, double w) { - } -} diff --git a/modules/overrungl.core/src/main/java/overrungl/util/value/Triplet.java b/modules/overrungl.core/src/main/java/overrungl/util/value/Triplet.java deleted file mode 100644 index 527c23ee..00000000 --- a/modules/overrungl.core/src/main/java/overrungl/util/value/Triplet.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2023 Overrun Organization - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - */ - -package overrungl.util.value; - -/** - * A triplet of the same type objects. - * - * @param the type. - * @param x the first value. - * @param y the second value. - * @param z the third value. - * @author squid233 - * @since 0.1.0 - */ -public /* value */ record Triplet(T x, T y, T z) { - /** - * {@return {@link #x}} - */ - public T first() { - return x; - } - - /** - * {@return {@link #y}} - */ - public T second() { - return y; - } - - /** - * {@return {@link #z}} - */ - public T third() { - return z; - } - - /** - * {@return {@link #x}} - */ - public T left() { - return x; - } - - /** - * {@return {@link #y}} - */ - public T middle() { - return y; - } - - /** - * {@return {@link #z}} - */ - public T right() { - return z; - } - - /** - * A triplet of integers. - * - * @param x the first value. - * @param y the second value. - * @param z the third value. - * @author squid233 - * @since 0.1.0 - */ - public record OfInt(int x, int y, int z) { - } - - /** - * A triplet of longs. - * - * @param x the first value. - * @param y the second value. - * @param z the third value. - * @author squid233 - * @since 0.1.0 - */ - public record OfLong(long x, long y, long z) { - } - - /** - * A triplet of floats. - * - * @param x the first value. - * @param y the second value. - * @param z the third value. - * @author squid233 - * @since 0.1.0 - */ - public record OfFloat(float x, float y, float z) { - } - - /** - * A triplet of doubles. - * - * @param x the first value. - * @param y the second value. - * @param z the third value. - * @author squid233 - * @since 0.1.0 - */ - public record OfDouble(double x, double y, double z) { - } -} diff --git a/modules/overrungl.core/src/main/java/overrungl/util/value/Tuple2.java b/modules/overrungl.core/src/main/java/overrungl/util/value/Tuple2.java deleted file mode 100644 index 7dcd8abf..00000000 --- a/modules/overrungl.core/src/main/java/overrungl/util/value/Tuple2.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2022-2023 Overrun Organization - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - */ - -package overrungl.util.value; - -/** - * A tuple of 2 objects. - * - * @param the first type. - * @param the second type. - * @param x the first value. - * @param y the second value. - * @author squid233 - * @since 0.1.0 - */ -public /* value */ record Tuple2(T x, U y) { - /** - * {@return {@link #x}} - */ - public T first() { - return x; - } - - /** - * {@return {@link #y}} - */ - public U second() { - return y; - } - - /** - * {@return {@link #x}} - */ - public T left() { - return x; - } - - /** - * {@return {@link #y}} - */ - public U right() { - return y; - } - - /** - * {@return {@link #x}} - */ - public T key() { - return x; - } - - /** - * {@return {@link #y}} - */ - public U value() { - return y; - } - - /** - * A value object with an object and an integer. - * - * @param x the first value. - * @param y the second value. - * @param the type of first value object. - * @author squid233 - * @since 0.1.0 - */ - public record OfObjInt(T x, int y) { - } - - /** - * A tuple of an object and a long. - * - * @param x the first value. - * @param y the second value. - * @param the first type. - * @author squid233 - * @since 0.1.0 - */ - public record OfObjLong(T x, long y) { - } - - /** - * A tuple of an int and a long. - * - * @param x the first value. - * @param y the second value. - * @author squid233 - * @since 0.1.0 - */ - public record OfIntLong(int x, long y) { - } -} diff --git a/modules/overrungl.core/src/main/java/overrungl/util/value/Tuple3.java b/modules/overrungl.core/src/main/java/overrungl/util/value/Tuple3.java deleted file mode 100644 index d18e458a..00000000 --- a/modules/overrungl.core/src/main/java/overrungl/util/value/Tuple3.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2023 Overrun Organization - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - */ - -package overrungl.util.value; - -/** - * A tuple of 3 objects. - * - * @param the first type. - * @param the second type. - * @param the third type. - * @param x the first value. - * @param y the second value. - * @param z the third value. - * @author squid233 - * @since 0.1.0 - */ -public /* value */ record Tuple3(T x, U y, V z) { - /** - * {@return {@link #x}} - */ - public T first() { - return x; - } - - /** - * {@return {@link #y}} - */ - public U second() { - return y; - } - - /** - * {@return {@link #z}} - */ - public V third() { - return z; - } - - /** - * {@return {@link #x}} - */ - public T left() { - return x; - } - - /** - * {@return {@link #y}} - */ - public U middle() { - return y; - } - - /** - * {@return {@link #z}} - */ - public V right() { - return z; - } -} diff --git a/modules/overrungl.core/src/main/java/overrungl/util/value/Tuple4.java b/modules/overrungl.core/src/main/java/overrungl/util/value/Tuple4.java deleted file mode 100644 index b6a10235..00000000 --- a/modules/overrungl.core/src/main/java/overrungl/util/value/Tuple4.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2023 Overrun Organization - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - */ - -package overrungl.util.value; - -/** - * A tuple of 4 objects. - * - * @param the first type. - * @param the second type. - * @param the third type. - * @param the fourth type. - * @param x the first value. - * @param y the second value. - * @param z the third value. - * @param w the fourth value. - * @author squid233 - * @since 0.1.0 - */ -public /* value */ record Tuple4(T x, U y, V z, W w) { - /** - * {@return {@link #x}} - */ - public T first() { - return x; - } - - /** - * {@return {@link #y}} - */ - public U second() { - return y; - } - - /** - * {@return {@link #z}} - */ - public V third() { - return z; - } - - /** - * {@return {@link #w}} - */ - public W fourth() { - return w; - } -} diff --git a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDEnumerator.java b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDEnumerator.java index 37e8a504..5087afa9 100644 --- a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDEnumerator.java +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDEnumerator.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2023-2024 Overrun Organization + * Copyright (c) 2023-2025 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -19,11 +19,11 @@ import org.jetbrains.annotations.NotNull; import overrungl.util.MemoryStack; import overrungl.util.Unmarshal; -import overrungl.util.value.Tuple2; import java.lang.foreign.MemoryLayout; import java.lang.foreign.MemorySegment; import java.lang.foreign.SegmentAllocator; +import java.lang.foreign.StructLayout; import java.util.Iterator; import java.util.NoSuchElementException; @@ -40,6 +40,8 @@ * @since 0.1.0 */ public final class NFDEnumerator implements Iterable, AutoCloseable { + /// The struct layout of `nfdpathsetenum_t` + public static final StructLayout STRUCT_LAYOUT = MemoryLayout.structLayout(ADDRESS.withName("ptr")); private static final Iterator EMPTY_ITERATOR = new Iterator<>() { @Override public boolean hasNext() { @@ -92,6 +94,18 @@ public String next() { } } + /** + * A result of {@link #fromPathSet(SegmentAllocator, MemorySegment) fromPathSet} + * + * @param enumerator the enumerator if {@code result} is {@link NFD#NFD_OKAY NFD_OKAY}; otherwise {@code null} + * @param result the result of {@link NFD#NFD_PathSet_GetEnum(MemorySegment, MemorySegment) NFD_PathSet_GetEnum} + */ + public record Result( + NFDEnumerator enumerator, + int result + ) { + } + /** * Creates an enumerator from the given path set created with * {@link NFD#NFD_OpenDialogMultiple(MemorySegment, NFDFilterItem, String) NFD_OpenDialogMultiple}. @@ -100,10 +114,10 @@ public String next() { * @param pathSet the path set. * @return the result and the enumerator. */ - public static Tuple2.OfObjInt fromPathSet(SegmentAllocator allocator, MemorySegment pathSet) { - MemorySegment struct = allocator.allocate(MemoryLayout.structLayout(ADDRESS)); + public static Result fromPathSet(SegmentAllocator allocator, MemorySegment pathSet) { + MemorySegment struct = allocator.allocate(STRUCT_LAYOUT); int result = NFD_PathSet_GetEnum(pathSet, struct); - return new Tuple2.OfObjInt<>(result == NFD_OKAY ? + return new Result(result == NFD_OKAY ? new NFDEnumerator(struct) : null, result); diff --git a/modules/samples/src/test/java/overrungl/demo/nfd/NFDTest.java b/modules/samples/src/test/java/overrungl/demo/nfd/NFDTest.java index 2b51baa8..9ac73738 100644 --- a/modules/samples/src/test/java/overrungl/demo/nfd/NFDTest.java +++ b/modules/samples/src/test/java/overrungl/demo/nfd/NFDTest.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2023-2024 Overrun Organization + * Copyright (c) 2023-2025 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -127,7 +127,7 @@ private static void openDialogMultipleEnum() { case NFD_OKAY -> { System.out.println("Success!"); - try (NFDEnumerator enumerator = NFDEnumerator.fromPathSet(stack, outPaths).x()) { + try (NFDEnumerator enumerator = NFDEnumerator.fromPathSet(stack, outPaths).enumerator()) { int i = 0; for (String path : enumerator) { System.out.println("Path " + i + ": " + path); From 9361e464981b511874f7f925675a5f46d15bc850 Mon Sep 17 00:00:00 2001 From: squid233 <60126026+squid233@users.noreply.github.com> Date: Fri, 3 Jan 2025 19:23:14 +0800 Subject: [PATCH 2/2] docs: update copyright of module-info.java --- modules/overrungl.core/src/main/java/module-info.java | 2 +- modules/overrungl.glfw/src/main/java/module-info.java | 2 +- modules/overrungl.joml/src/main/java/module-info.java | 2 +- modules/overrungl.nfd/src/main/java/module-info.java | 2 +- modules/overrungl.stb/src/main/java/module-info.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/overrungl.core/src/main/java/module-info.java b/modules/overrungl.core/src/main/java/module-info.java index 5ce0a9e6..fe784f3b 100644 --- a/modules/overrungl.core/src/main/java/module-info.java +++ b/modules/overrungl.core/src/main/java/module-info.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2023-2024 Overrun Organization + * Copyright (c) 2023-2025 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/modules/overrungl.glfw/src/main/java/module-info.java b/modules/overrungl.glfw/src/main/java/module-info.java index ac5fb419..5c5fd321 100644 --- a/modules/overrungl.glfw/src/main/java/module-info.java +++ b/modules/overrungl.glfw/src/main/java/module-info.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2023-2024 Overrun Organization + * Copyright (c) 2023-2025 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/modules/overrungl.joml/src/main/java/module-info.java b/modules/overrungl.joml/src/main/java/module-info.java index 413eddba..6dd335ca 100644 --- a/modules/overrungl.joml/src/main/java/module-info.java +++ b/modules/overrungl.joml/src/main/java/module-info.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2023-2024 Overrun Organization + * Copyright (c) 2023-2025 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/modules/overrungl.nfd/src/main/java/module-info.java b/modules/overrungl.nfd/src/main/java/module-info.java index 72224dba..88e53d15 100644 --- a/modules/overrungl.nfd/src/main/java/module-info.java +++ b/modules/overrungl.nfd/src/main/java/module-info.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2023-2024 Overrun Organization + * Copyright (c) 2023-2025 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/modules/overrungl.stb/src/main/java/module-info.java b/modules/overrungl.stb/src/main/java/module-info.java index 15fb80f2..562563d7 100644 --- a/modules/overrungl.stb/src/main/java/module-info.java +++ b/modules/overrungl.stb/src/main/java/module-info.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2023-2024 Overrun Organization + * Copyright (c) 2023-2025 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal