diff --git a/CHANGELOG.md b/CHANGELOG.md index 40a5076bf..36c824d20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java b/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java index c7735191d..f776b4ca7 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java +++ b/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java @@ -44,7 +44,7 @@ public class InfoMap extends HashMap> { .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)")) diff --git a/src/main/java/org/bytedeco/javacpp/tools/Parser.java b/src/main/java/org/bytedeco/javacpp/tools/Parser.java index c5bd5f1b4..51bb7ab1d 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/Parser.java +++ b/src/main/java/org/bytedeco/javacpp/tools/Parser.java @@ -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; @@ -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"); }