Skip to content

Commit

Permalink
Array: add 2 erase() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Oct 18, 2024
1 parent b7eb70d commit 2e0be7a
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/BodyIdVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/BodyVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/Constraints.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/ContactList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/template/Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
12 changes: 12 additions & 0 deletions src/main/native/glue/bo/BodyIdVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_BodyIdVector_createB
return reinterpret_cast<jlong> (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<BodyIDVector *> (vectorVa);
BodyIDVector::iterator origin = pVector->begin();
pVector->erase(origin + startIndex, origin + stopIndex);
}

/*
* Class: com_github_stephengold_joltjni_BodyIdVector
* Method: free
Expand Down
12 changes: 12 additions & 0 deletions src/main/native/glue/bo/BodyVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BodyVector *> (vectorVa);
BodyVector::iterator origin = pVector->begin();
pVector->erase(origin + startIndex, origin + stopIndex);
}

/*
* Class: com_github_stephengold_joltjni_BodyVector
* Method: getBody
Expand Down
12 changes: 12 additions & 0 deletions src/main/native/glue/co/Constraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Constraints *> (arrayVa);
Constraints::iterator origin = pArray->begin();
pArray->erase(origin + startIndex, origin + stopIndex);
}

/*
* Class: com_github_stephengold_joltjni_Constraints
* Method: get
Expand Down
13 changes: 13 additions & 0 deletions src/main/native/glue/co/ContactList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CharacterVirtual::ContactList *> (listVa);
CharacterVirtual::ContactList::iterator origin = pList->begin();
pList->erase(origin + startIndex, origin + stopIndex);
}

/*
* Class: com_github_stephengold_joltjni_ContactList
* Method: free
Expand Down
13 changes: 13 additions & 0 deletions src/main/native/glue/i/IndexedTriangleList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_IndexedTriangleList_
return reinterpret_cast<jlong> (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<IndexedTriangleList *> (listVa);
IndexedTriangleList::iterator origin = pList->begin();
pList->erase(origin + startIndex, origin + stopIndex);
}

/*
* Class: com_github_stephengold_joltjni_IndexedTriangleList
* Method: free
Expand Down
13 changes: 13 additions & 0 deletions src/main/native/glue/p/PhysicsMaterialList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_PhysicsMaterialList_
return reinterpret_cast<jlong> (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<PhysicsMaterialList *> (listVa);
PhysicsMaterialList::iterator origin = pList->begin();
pList->erase(origin + startIndex, origin + stopIndex);
}

/*
* Class: com_github_stephengold_joltjni_PhysicsMaterialList
* Method: free
Expand Down

0 comments on commit 2e0be7a

Please sign in to comment.