-
Notifications
You must be signed in to change notification settings - Fork 62
C++ wrapper classes for generated C API #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C++ wrapper classes for generated C API #214
Conversation
| writeEnumOptionAll(w, e, idCpp.enum, "=", enumCasePrefix) | ||
| } | ||
|
|
||
| wrapExternC(w, (w: IndentWriter) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is better to review with whitespace ignored as there are some block indentation changes
| } | ||
|
|
||
| T get() const { return _ref; } | ||
| const T& get() const { return _ref; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made this const ref to ensure correct constructor overload is called when doing things like
Ref<djinni_ref> myRef = ....
WrapperClass myWrapper(myRef.get());
The lvalue constructor should be used to ensure the ref count is appropriately incremented
Add option to generate C++ wrapper classes for use with the C API. These can be used if you intend to use the C API from another C++ environment, eg across an ABI boundary.
The wrapper classes are generated if the
--c-wrapper-cpp-namespaceCLI argument is provided - this is the namespace for the wrappers.Example using
--c-wrapper-cpp-namespace snap::test::c_wrappers:my_module.djinni:Generated
Size.hGenerated
Window.h:The wrappers can then be used to simplify C API usage: