从生成的类名称中删除 SWIGTYPE
是否有办法从生成的类名中删除 SWIGTYPE 部分并替换为另一个字符串文字?
即,将 SWIGTYPE_p_ex_session.java 更改为 ex_session.java(剥离生成的“SWIGTYPE_p_”)
SWIG .i 文件:
%module Example
%{
#include "ExampleApi.h"
struct ex_session{};
%}
%include "ExampleApi.h"
ExampleApi.h 包含以下内容:
typedef struct ex_session session_t;
Is there anyway to remove the SWIGTYPE part from the generated class names and replace with another string literal?
i.e. change SWIGTYPE_p_ex_session.java to ex_session.java (strip off generated "SWIGTYPE_p_")
SWIG .i file:
%module Example
%{
#include "ExampleApi.h"
struct ex_session{};
%}
%include "ExampleApi.h"
ExampleApi.h contains the below:
typedef struct ex_session session_t;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设这里真正的问题是“丑陋的名称”,那么我将通过确保 SWIG 在生成包装器时至少有一个可见的空定义(而不仅仅是声明)来解决这个问题,例如给出:
SWIG 生成
SWIGTYPE_p_ExampleNiceName.java
我们可以通过执行以下操作来使其变得更好:
而不是
在本例中,这会导致 SWIG 生成
ExampleNiceName.java
作为而是包裹类型。它不会暴露比以前暴露的更多的东西,并且完全合法/理智。通过这样做,我们不仅告诉 SWIG“此类型存在”,而且“此类型存在,我们希望您不要包装除其名称之外的任何内容”。您还可以使用
%rename
使 Java 端的名称与 C++ 类名称不同,例如:使用前面的示例将导致就地使用
JavaClassName
生成的 Java 中的ExampleNiceName
。Assuming the real issue here is the "ugly name" then I'd solve this one by making sure SWIG has at least an empty definition (not just a declaration) visible when it's generating the wrapper, for example given:
SWIG generates
SWIGTYPE_p_ExampleNiceName.java
We can make this a whole lot better just by doing something like:
instead of
in this example, which causes SWIG to generate
ExampleNiceName.java
as a wrapped type instead. It doesn't expose anything more than previously exposed and is perfectly legal/sane. We're telling SWIG not just "this type exists", but "this type exists and we'd like you to wrap nothing beyond it's name" by doing this.You can also use
%rename
to make the name on the Java side different from the C++ class name, for example:with the previous example would cause
JavaClassName
to be used in place ofExampleNiceName
in the generated Java.