Thanks for the ideas. I think my ideal case would be to use an adapter
to manage the pointer access, but I'm not entirely sure how the
specifics would work. Here's an example of what I'm thinking...
Let's say we have a contrived event service that looks something like
the following in C++:
class EventService {
public:
std::shared_ptr<Event> getNextEvent();
};
class Event {
public:
int getType();
};
class StringEvent : public Event {
std::string getString();
};
I would love to define it on the JavaCPP side as follows:
@Name("EventService")
public static class EventService extends Pointer {
public native @Adapter("SharedPointerAdapter<Event>") Event
getNextEvent();
}
@Name("Event")
public static class Event extends Pointer {
public native int getType();
}
@Name("StringEvent")
public static class StringEvent extends Pointer {
public StringEvent(Pointer p) {
super(p);
}
public native String getString();
}
And code that would use the above:
EventService service = new EventService();
Event event = service.getNextEvent();
if (event.getType() == 12345) {
StringEvent sev = new StringEvent(event);
System.out.println(sev.getString());
}
I see a similar use for a UniquePointerAdapter. In fact it would be
awesome if Adapters in general were an extensible concept. I know
VectorAdapter exists, but I could see registering adapter code snippets,
a la VectorAdapter.h, SharedPointerAdapter.h, UniquePointerAdapter.h,
etc. as well as project-specific Adapter snippets.
To making something work like the above example of casting Event to
StringEvent, I think Adapters would have to be instantiated on a
per-Pointer-object basis and copied alongside in Constructor(Pointer p),
but that doesn't seem too bad.
Oh well, I guess I'm probably dreaming a bit here. Anyway, for now I'll
explore some of the ideas you mentioned. The extensible Adapter idea is
definitely a wish-list item I'd vote for though. =)
Thanks again for the input!
Bob