从生成的类名中删除 SWIGTYPE [英] Remove SWIGTYPE from Generated Class name

查看:33
本文介绍了从生成的类名中删除 SWIGTYPE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何要从生成的类名中删除 SWIGTYPE 部分并替换为另一个字符串文字?

Is there anyway to remove the SWIGTYPE part from the generated class names and replace with another string literal?

即将 SWIGTYPE_p_ex_session.java 更改为 ex_session.java(剥离生成的SWIGTYPE_p_")

i.e. change SWIGTYPE_p_ex_session.java to ex_session.java (strip off generated "SWIGTYPE_p_")

SWIG .i 文件:

SWIG .i file:

%module Example
%{
#include "ExampleApi.h"
struct ex_session{};
%}

%include "ExampleApi.h"

ExampleApi.h 包含以下内容:

ExampleApi.h contains the below:

typedef struct ex_session session_t;

推荐答案

假设这里真正的问题是丑陋的名字",那么我会通过确保 SWIG 至少有一个空定义(不仅仅是一个声明)来解决这个问题) 在生成包装器时可见,例如:

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:

%module test

class ExampleNiceName;

typedef ExampleNiceName example_t;

void func(example_t);

SWIG 生成 SWIGTYPE_p_ExampleNiceName.java

只需执行以下操作,我们就可以使这一切变得更好:

We can make this a whole lot better just by doing something like:

class ExampleNiceName {};

代替

class ExampleNiceName;

在此示例中,这会导致 SWIG 生成 ExampleNiceName.java 作为包装类型.它不会暴露比以前暴露的更多的东西,并且是完全合法/理智的.我们告诉 SWIG 不仅仅是这种类型存在",而是这种类型存在,我们希望您通过这样做来包装它的名称之外的任何东西".

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.

也可以使用%rename使Java端的名称与C++类名不同,例如:

You can also use %rename to make the name on the Java side different from the C++ class name, for example:

%rename(JavaClassName) ExampleNiceName;
class ExampleNiceName {};

使用前面的示例会导致在生成的 Java 中使用 JavaClassName 代替 ExampleNiceName.

with the previous example would cause JavaClassName to be used in place of ExampleNiceName in the generated Java.

这篇关于从生成的类名中删除 SWIGTYPE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆