bytedeco / javacpp

The missing bridge between Java and native C++
Other
4.46k stars 581 forks source link

Generalize automatic addition of adapter annotations #670

Open HGuillemet opened 1 year ago

HGuillemet commented 1 year ago

It would be nice to generalize this logic for, eg, containers or arrays. Currently, if we must map a std::vector<std::shared_ptr<M>>, we need to add an info new Info("std::shared_ptr<M>").pointerTypes("M"). While this is not needed if std::shared_ptr<M> is the type of a function argument or a return type. But adding such manual info also cancel the automatic additions of @Cast and possibly others performed by the parser.

Could this logic be moved from declarator() to type() ?

saudet commented 1 year ago

You mean supporting multiple adapter annotations like @StdVector @SharedPtr? That's not supported at all by the current implementation of adapters in Generator. This needs to be completely rethought, along with other issues like the ones reported by @equeim as per issue #374.

HGuillemet commented 1 year ago

No, I meant the possibility of defining std::vector<std::shared_ptr<M>> without having to add Info("std::shared_ptr<M>").pointerTypes("M").

saudet commented 1 year ago

So you're talking about containers(). For that, we'd need to delay the instantiation until their first use.

HGuillemet commented 1 year ago

I'm not sure how it would solve this specific issue, but instantiating them when needed seems a good improvement. No need to define() them any more, just like other classes. You must have already though about this: would that be difficult to do ?

saudet commented 1 year ago

No one just never had a reason to do it like that. If you want to give it a try, feel free to experiment!