From 2e0be7aa1658f189fffedfe00bd3829748291020 Mon Sep 17 00:00:00 2001 From: stephengold Date: Thu, 17 Oct 2024 18:28:26 -0700 Subject: [PATCH] Array: add 2 erase() methods --- .../stephengold/joltjni/BodyIdVector.java | 15 +++++++++++++++ .../github/stephengold/joltjni/BodyVector.java | 15 +++++++++++++++ .../github/stephengold/joltjni/Constraints.java | 15 +++++++++++++++ .../github/stephengold/joltjni/ContactList.java | 15 +++++++++++++++ .../joltjni/IndexedTriangleList.java | 15 +++++++++++++++ .../joltjni/PhysicsMaterialList.java | 15 +++++++++++++++ .../stephengold/joltjni/template/Array.java | 17 +++++++++++++++++ src/main/native/glue/bo/BodyIdVector.cpp | 12 ++++++++++++ src/main/native/glue/bo/BodyVector.cpp | 12 ++++++++++++ src/main/native/glue/co/Constraints.cpp | 12 ++++++++++++ src/main/native/glue/co/ContactList.cpp | 13 +++++++++++++ src/main/native/glue/i/IndexedTriangleList.cpp | 13 +++++++++++++ src/main/native/glue/p/PhysicsMaterialList.cpp | 13 +++++++++++++ 13 files changed, 182 insertions(+) diff --git a/src/main/java/com/github/stephengold/joltjni/BodyIdVector.java b/src/main/java/com/github/stephengold/joltjni/BodyIdVector.java index 0c80cce7..1128d140 100644 --- a/src/main/java/com/github/stephengold/joltjni/BodyIdVector.java +++ b/src/main/java/com/github/stephengold/joltjni/BodyIdVector.java @@ -57,6 +57,18 @@ public int capacity() { return result; } + /** + * Remove all IDs in the specified range of indices. + * + * @param startIndex the index of the first element to remove (≥0) + * @param stopIndex one plus the index of the last element to remove (≥0) + */ + @Override + public void erase(int startIndex, int stopIndex) { + long vectorVa = va(); + erase(vectorVa, startIndex, stopIndex); + } + /** * Access the ID at the specified index. * @@ -115,6 +127,9 @@ public int size() { native private static long createBodyIdVector(); + native private static void erase( + long vectorVa, int startIndex, int stopIndex); + native private static void free(long vectorVa); native private static long getId(long vectorVa, int elementIndex); diff --git a/src/main/java/com/github/stephengold/joltjni/BodyVector.java b/src/main/java/com/github/stephengold/joltjni/BodyVector.java index c01d8c89..3269e806 100644 --- a/src/main/java/com/github/stephengold/joltjni/BodyVector.java +++ b/src/main/java/com/github/stephengold/joltjni/BodyVector.java @@ -72,6 +72,18 @@ public int capacity() { return result; } + /** + * Remove all bodies in the specified range of indices. + * + * @param startIndex the index of the first element to remove (≥0) + * @param stopIndex one plus the index of the last element to remove (≥0) + */ + @Override + public void erase(int startIndex, int stopIndex) { + long vectorVa = va(); + erase(vectorVa, startIndex, stopIndex); + } + /** * Access the body at the specified index. * @@ -134,6 +146,9 @@ public int size() { native private static int capacity(long vectorVa); + native private static void erase( + long vectorVa, int startIndex, int stopIndex); + native private static long getBody(long vectorVa, int elementIndex); native private static void resize(long vectorVa, int numBodies); diff --git a/src/main/java/com/github/stephengold/joltjni/Constraints.java b/src/main/java/com/github/stephengold/joltjni/Constraints.java index 7369fb9b..76845cb1 100644 --- a/src/main/java/com/github/stephengold/joltjni/Constraints.java +++ b/src/main/java/com/github/stephengold/joltjni/Constraints.java @@ -62,6 +62,18 @@ public int capacity() { return result; } + /** + * Remove all references in the specified range of indices. + * + * @param startIndex the index of the first element to remove (≥0) + * @param stopIndex one plus the index of the last element to remove (≥0) + */ + @Override + public void erase(int startIndex, int stopIndex) { + long vectorVa = va(); + erase(vectorVa, startIndex, stopIndex); + } + /** * Copy the reference at the specified index. * @@ -120,6 +132,9 @@ public int size() { native private static void free(long arrayVa); + native private static void erase( + long vectorVa, int startIndex, int stopIndex); + native private static long get(long arrayVa, int elementIndex); native private static void resize(long arrayVa, int numReferences); diff --git a/src/main/java/com/github/stephengold/joltjni/ContactList.java b/src/main/java/com/github/stephengold/joltjni/ContactList.java index 1b5e91da..1d7ff360 100644 --- a/src/main/java/com/github/stephengold/joltjni/ContactList.java +++ b/src/main/java/com/github/stephengold/joltjni/ContactList.java @@ -62,6 +62,18 @@ public int capacity() { return result; } + /** + * Remove all contacts in the specified range of indices. + * + * @param startIndex the index of the first element to remove (≥0) + * @param stopIndex one plus the index of the last element to remove (≥0) + */ + @Override + public void erase(int startIndex, int stopIndex) { + long vectorVa = va(); + erase(vectorVa, startIndex, stopIndex); + } + /** * Access the contact at the specified index. * @@ -118,6 +130,9 @@ public int size() { native private static int capacity(long listVa); + native private static void erase( + long vectorVa, int startIndex, int stopIndex); + native private static void free(long listVa); native private static long get(long listVa, int elementIndex); diff --git a/src/main/java/com/github/stephengold/joltjni/IndexedTriangleList.java b/src/main/java/com/github/stephengold/joltjni/IndexedTriangleList.java index 91659c05..24ed18c6 100644 --- a/src/main/java/com/github/stephengold/joltjni/IndexedTriangleList.java +++ b/src/main/java/com/github/stephengold/joltjni/IndexedTriangleList.java @@ -57,6 +57,18 @@ public int capacity() { return result; } + /** + * Remove all triangles in the specified range of indices. + * + * @param startIndex the index of the first element to remove (≥0) + * @param stopIndex one plus the index of the last element to remove (≥0) + */ + @Override + public void erase(int startIndex, int stopIndex) { + long vectorVa = va(); + erase(vectorVa, startIndex, stopIndex); + } + /** * Access the triangle at the specified index. * @@ -115,6 +127,9 @@ public int size() { native private static long createIndexedTriangleList(); + native private static void erase( + long vectorVa, int startIndex, int stopIndex); + native private static void free(long listVa); native private static long getTriangle(long listVa, int elementIndex); diff --git a/src/main/java/com/github/stephengold/joltjni/PhysicsMaterialList.java b/src/main/java/com/github/stephengold/joltjni/PhysicsMaterialList.java index 97cb7841..4086dd86 100644 --- a/src/main/java/com/github/stephengold/joltjni/PhysicsMaterialList.java +++ b/src/main/java/com/github/stephengold/joltjni/PhysicsMaterialList.java @@ -57,6 +57,18 @@ public int capacity() { return result; } + /** + * Remove all references in the specified range of indices. + * + * @param startIndex the index of the first element to remove (≥0) + * @param stopIndex one plus the index of the last element to remove (≥0) + */ + @Override + public void erase(int startIndex, int stopIndex) { + long vectorVa = va(); + erase(vectorVa, startIndex, stopIndex); + } + /** * Copy the reference at the specified index. * @@ -115,6 +127,9 @@ public int size() { native private static long createEmptyList(); + native private static void erase( + long vectorVa, int startIndex, int stopIndex); + native private static void free(long listVa); native private static long get(long listVa, int elementIndex); diff --git a/src/main/java/com/github/stephengold/joltjni/template/Array.java b/src/main/java/com/github/stephengold/joltjni/template/Array.java index f37197c2..39e6a7c5 100644 --- a/src/main/java/com/github/stephengold/joltjni/template/Array.java +++ b/src/main/java/com/github/stephengold/joltjni/template/Array.java @@ -83,6 +83,23 @@ public boolean empty() { } } + /** + * Remove the specified element. + * + * @param elementIndex the index of the element to remove (≥0) + */ + public void erase(int elementIndex) { + erase(elementIndex, elementIndex + 1); + } + + /** + * Remove all elements in the specified range of indices. + * + * @param startIndex the index of the first element to remove (≥0) + * @param stopIndex one plus the index of the last element to remove (≥0) + */ + abstract public void erase(int startIndex, int stopIndex); + /** * Access or copy the element at the specified index. * diff --git a/src/main/native/glue/bo/BodyIdVector.cpp b/src/main/native/glue/bo/BodyIdVector.cpp index 00fa475f..a9d85f6c 100644 --- a/src/main/native/glue/bo/BodyIdVector.cpp +++ b/src/main/native/glue/bo/BodyIdVector.cpp @@ -55,6 +55,18 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_BodyIdVector_createB return reinterpret_cast (pVector); } +/* + * Class: com_github_stephengold_joltjni_BodyIdVector + * Method: erase + * Signature: (JII)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_BodyIdVector_erase + (JNIEnv *, jclass, jlong vectorVa, jint startIndex, jint stopIndex) { + BodyIDVector * const pVector = reinterpret_cast (vectorVa); + BodyIDVector::iterator origin = pVector->begin(); + pVector->erase(origin + startIndex, origin + stopIndex); +} + /* * Class: com_github_stephengold_joltjni_BodyIdVector * Method: free diff --git a/src/main/native/glue/bo/BodyVector.cpp b/src/main/native/glue/bo/BodyVector.cpp index a1810575..52ad0cfd 100644 --- a/src/main/native/glue/bo/BodyVector.cpp +++ b/src/main/native/glue/bo/BodyVector.cpp @@ -43,6 +43,18 @@ JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_BodyVector_capacity return result; } +/* + * Class: com_github_stephengold_joltjni_BodyVector + * Method: erase + * Signature: (JII)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_BodyVector_erase + (JNIEnv *, jclass, jlong vectorVa, jint startIndex, jint stopIndex) { + BodyVector * const pVector = reinterpret_cast (vectorVa); + BodyVector::iterator origin = pVector->begin(); + pVector->erase(origin + startIndex, origin + stopIndex); +} + /* * Class: com_github_stephengold_joltjni_BodyVector * Method: getBody diff --git a/src/main/native/glue/co/Constraints.cpp b/src/main/native/glue/co/Constraints.cpp index d2c632d2..accfd7f1 100644 --- a/src/main/native/glue/co/Constraints.cpp +++ b/src/main/native/glue/co/Constraints.cpp @@ -55,6 +55,18 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_Constraints_free delete pArray; } +/* + * Class: com_github_stephengold_joltjni_Constraints + * Method: erase + * Signature: (JII)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_Constraints_erase + (JNIEnv *, jclass, jlong arrayVa, jint startIndex, jint stopIndex) { + Constraints * const pArray = reinterpret_cast (arrayVa); + Constraints::iterator origin = pArray->begin(); + pArray->erase(origin + startIndex, origin + stopIndex); +} + /* * Class: com_github_stephengold_joltjni_Constraints * Method: get diff --git a/src/main/native/glue/co/ContactList.cpp b/src/main/native/glue/co/ContactList.cpp index 68411601..99c51d56 100644 --- a/src/main/native/glue/co/ContactList.cpp +++ b/src/main/native/glue/co/ContactList.cpp @@ -43,6 +43,19 @@ JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_ContactList_capacity return result; } +/* + * Class: com_github_stephengold_joltjni_ContactList + * Method: erase + * Signature: (JII)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_ContactList_erase + (JNIEnv *, jclass, jlong listVa, jint startIndex, jint stopIndex) { + CharacterVirtual::ContactList * const pList + = reinterpret_cast (listVa); + CharacterVirtual::ContactList::iterator origin = pList->begin(); + pList->erase(origin + startIndex, origin + stopIndex); +} + /* * Class: com_github_stephengold_joltjni_ContactList * Method: free diff --git a/src/main/native/glue/i/IndexedTriangleList.cpp b/src/main/native/glue/i/IndexedTriangleList.cpp index 3257dd9e..e6f9d059 100644 --- a/src/main/native/glue/i/IndexedTriangleList.cpp +++ b/src/main/native/glue/i/IndexedTriangleList.cpp @@ -55,6 +55,19 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_IndexedTriangleList_ return reinterpret_cast (pList); } +/* + * Class: com_github_stephengold_joltjni_IndexedTriangleList + * Method: erase + * Signature: (JII)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_IndexedTriangleList_erase + (JNIEnv *, jclass, jlong listVa, jint startIndex, jint stopIndex) { + IndexedTriangleList * const pList + = reinterpret_cast (listVa); + IndexedTriangleList::iterator origin = pList->begin(); + pList->erase(origin + startIndex, origin + stopIndex); +} + /* * Class: com_github_stephengold_joltjni_IndexedTriangleList * Method: free diff --git a/src/main/native/glue/p/PhysicsMaterialList.cpp b/src/main/native/glue/p/PhysicsMaterialList.cpp index 0a4d3969..192a785c 100644 --- a/src/main/native/glue/p/PhysicsMaterialList.cpp +++ b/src/main/native/glue/p/PhysicsMaterialList.cpp @@ -55,6 +55,19 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_PhysicsMaterialList_ return reinterpret_cast (pList); } +/* + * Class: com_github_stephengold_joltjni_PhysicsMaterialList + * Method: erase + * Signature: (JII)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_PhysicsMaterialList_erase + (JNIEnv *, jclass, jlong listVa, jint startIndex, jint stopIndex) { + PhysicsMaterialList * const pList + = reinterpret_cast (listVa); + PhysicsMaterialList::iterator origin = pList->begin(); + pList->erase(origin + startIndex, origin + stopIndex); +} + /* * Class: com_github_stephengold_joltjni_PhysicsMaterialList * Method: free