Skip to content

Commit

Permalink
* Add support for std::basic_string basic container (issue bytedec…
Browse files Browse the repository at this point in the history
  • Loading branch information
saudet committed Sep 20, 2023
1 parent 190f6dd commit 7227ec6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Add support for `std::basic_string` basic container ([issue bytedeco/javacpp-presets#1311](https://github.com/bytedeco/javacpp-presets/issues/1311))
* Enhance `Parser` by adding downcast constructors for polymorphic classes ([pull #700](https://github.com/bytedeco/javacpp/pull/700))
* Let `Generator` pick up `@Name` annotations on `allocate()` as well ([pull #700](https://github.com/bytedeco/javacpp/pull/700))
* Fix `Parser` failing to place annotations on default constructors ([pull #699](https://github.com/bytedeco/javacpp/pull/699))
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/bytedeco/javacpp/tools/InfoMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class InfoMap extends HashMap<String,List<Info>> {
.put(new Info("basic/containers").cppTypes("std::array", "std::bitset", "std::deque", "std::list", "std::map", "std::queue", "std::set",
"std::stack", "std::vector", "std::valarray", "std::pair", "std::tuple", "std::forward_list",
"std::priority_queue", "std::unordered_map", "std::unordered_set", "std::optional", "std::variant",
"std::function"))
"std::function", "std::basic_string"))
.put(new Info("basic/types").cppTypes("signed", "unsigned", "char", "short", "int", "long", "bool", "float", "double",
"__int8", "__int16", "__int32", "__int64", "_Bool", "_Complex", "_Imaginary", "complex", "imaginary"))
.put(new Info("noexcept").annotations("@NoException(true)"))
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/org/bytedeco/javacpp/tools/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ void containers(Context context, DeclarationList declList) throws ParserExceptio
|| containerName.toLowerCase().endsWith("tuple")
|| containerName.toLowerCase().endsWith("function")
|| containerName.toLowerCase().endsWith("pair") ? 0 : 1;
boolean string = containerName.toLowerCase().endsWith("string");
boolean constant = info.cppNames[0].startsWith("const "), resizable = !constant;
Type containerType = new Parser(this, info.cppNames[0]).type(context),
indexType, valueType, firstType = null, secondType = null;
Expand Down Expand Up @@ -362,10 +363,15 @@ void containers(Context context, DeclarationList declList) throws ParserExceptio
}
}
if (!purify) {
decl.text += " public " + containerType.javaName + "() { allocate(); }\n" + (!resizable ? ""
: " public " + containerType.javaName + "(long n) { allocate(n); }\n")
+ " private native void allocate();\n" + (!resizable ? ""
: " private native void allocate(@Cast(\"size_t\") long n);\n") + (constant ? "\n\n"
String initArg = "", initParam = "";
if (string) {
initArg = ", (" + removeAnnotations(valueType.javaName) + ")0";
initParam = ", " + removeAnnotations(valueType.javaName) + " value";
}
decl.text += " public " + containerType.javaName + "() { allocate(); }\n" + (!resizable ? ""
: " public " + containerType.javaName + "(long n) { allocate(n" + initArg + "); }\n")
+ " private native void allocate();\n" + (!resizable ? ""
: " private native void allocate(@Cast(\"size_t\") long n" + initParam + ");\n") + (constant ? "\n\n"
: " public native @Name(\"operator =\") @ByRef " + containerType.javaName + " put(@ByRef " + containerType.annotations + containerType.javaName + " x);\n\n");
}

Expand Down

0 comments on commit 7227ec6

Please sign in to comment.