Skip to content

Commit

Permalink
* Let Parser define front() and back() for one-dimensional bas…
Browse files Browse the repository at this point in the history
…ic containers (pull #695)
  • Loading branch information
HGuillemet committed Jul 10, 2023
1 parent 2dacec9 commit ec90945
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Let `Parser` define `front()` and `back()` for one-dimensional basic containers ([pull #695](https://github.com/bytedeco/javacpp/pull/695))
* Let `Parser` map iterators of basic containers systematically ([pull #694](https://github.com/bytedeco/javacpp/pull/694))
* Fix `Parser` for function parameters contained in template arguments ([pull #693](https://github.com/bytedeco/javacpp/pull/693))
* Fix `Parser` on function pointer declarations starting with `typedef struct` ([pull bytedeco/javacpp-presets#1361](https://github.com/bytedeco/javacpp-presets/pull/1361))
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/bytedeco/javacpp/tools/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,12 @@ void containers(Context context, DeclarationList declList) throws ParserExceptio
}
} else {
if (indexType != null) {
decl.text += "\n"
+ " @Index" + indexFunction + " public native " + valueType.annotations + valueType.javaName + " get(" + params + ");\n";
decl.text += "\n";
if (dim == 1 && indexType.javaName.equals("long")) {
decl.text += " public " + removeAnnotations(valueType.javaName) + " front() { return get(0); }\n"
+ " public " + removeAnnotations(valueType.javaName) + " back() { return get(size() - 1); }\n";
}
decl.text += " @Index" + indexFunction + " public native " + valueType.annotations + valueType.javaName + " get(" + params + ");\n";
if (!constant) {
decl.text += " public native " + containerType.javaName + " put(" + params + separator + removeAnnotations(valueType.javaName) + " value);\n";
}
Expand Down Expand Up @@ -413,6 +417,9 @@ void containers(Context context, DeclarationList declList) throws ParserExceptio
}
if (dim == 1 && !containerName.toLowerCase().endsWith("bitset") && containerType.arguments.length >= 1 && containerType.arguments[containerType.arguments.length - 1].javaName.length() > 0) {
decl.text += "\n";
if (indexType == null || (!indexType.javaName.equals("long") && containerType.arguments.length == 1)) {
decl.text += " public " + removeAnnotations(valueType.javaName) + " front() { try (Iterator it = begin()) { return it.get(); } }\n";
}
if (!constant) {
if (list) {
decl.text += " public native @ByVal Iterator insert(@ByVal Iterator pos, " + valueType.annotations + valueType.javaName + " value);\n"
Expand Down

0 comments on commit ec90945

Please sign in to comment.