Hi all,
This may sound like a dumb question but I've spent so much
time and I'm still at a loss of how to do this,
I've got a class like so:
using String =
std::string; // just stating that i'm using type aliases
in cases that creates a problem
using StringVectorT =
std::vector<String>;
class ClassA
{
public:
virtual String getIt() const = 0;
virtual String
getWhich(const String& arg) const = 0;
virtual
StringVectorT getAll() const = 0;
}
I'm trying to expose said
class using the following config:
public class VacuumConfig
implements InfoMapper {
@Properties(..)
public class Config
implements InfoMapper {
public void map(InfoMap infoMap) {
infoMap.put(new Info("std::string",
"String").annotations("@StdString").pointerTypes("BytePointer"));
infoMap.put(new
Info("std::vector<std::string>",
"StringVectorT").pointerTypes("StringVector").define());
infoMap.put(new
Info("ClassA").pointerTypes("ClassA").purify(false).virtualize());
}
}
Since @StdString
maps to std::basic_string<char>& the overriding
function (created due to virtualize) has an conflicting
return type (std::basic_string<char>& instead of
String (aka std::string).
I've tried other
variations:
- infoMap.put(new
Info("std::string",
"veltio::vacuum::String").valueTypes("String").pointerTypes("@StdString
BytePointer")); No
effect, return const char* instead of basic_string
- infoMap.put(new
Info("std::string",
"veltio::vacuum::String").valueTypes("@Cast(\"std::string\")
String").pointerTypes("@StdString BytePointer")); This solves the problem for
the method getIt but creates a whole lot other
problems for StringVector (and any other type of
structure e.g. maps) since const char* cannot be cast
to std::string plus manual modification of the
produced java file is required b/c things like this
appear in the declaration of StringVector:
- @Cast("std::string")
String[] array = new @Cast("std::string")
String[size() < Integer.MAX_VALUE ? (int)size() :
Integer.MAX_VALUE];
- I've even tried defining
this:
@Documented @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.PARAMETER})
@Cast({"std::basic_string"}) @Adapter("StringAdapter")
public
@interface StdStringVal {
String value() default "char";
}
- This creates a problem for the method accepting
const String& as an argument (i.e. getWhich).
I've tried searching in javacpp-presets but could pin
down a solution to this..
What I need is a mapping that allows methods that accept
strings by-value or by const-ref and return string by-value to
be able to work okay, is there a way currently to do this?