为写入标准输出的库创建 SWIG API 的最佳方法?

发布于 2024-09-08 12:49:14 字数 450 浏览 0 评论 0原文

我维护着一组用于基因组学/生物信息学领域的 C++ 工具 (bedtools)。一些用户要求我为库创建 API,以便“钩子”可用于 Perl 和 Python(许多请求使用 Python)。因此,我对使用 SWIG 很感兴趣,因为它支持 C++,并且理论上可以用于创建多种语言的 API。

然而,上述工具的编写方式是为了使它们可以在 UNIX 流中“通过管道”连接在一起,因此所有库都会写入 stdout。我正在努力弄清楚如何使用 SWIG 将现有方法(printfs 和 couts)的输出作为 API 提供。我的理想愿景是工具的输出将是一个可以在 Python 中循环的迭代器/

有人有这方面的经验吗?我将非常感谢带有示例代码的具体示例。希望我遗漏了一些非常明显的东西。

值得庆幸的是, 亚伦

I maintain a set of C++ tools (bedtools) that are used in the genomics/bioinformatics field. Several users have asked that I create APIs to the libraries such that "hooks" are available for Perl and Python, for example (many requests for Python). Therefore, I am interested in using SWIG, as it has support for C++ and in theory, can be used to create APIs to several languages.

However, the aforementioned tools were written so that they could be "piped" together in an UNIX stream, and as such, all of the libraries write to stdout. I am struggling to figure out how to use SWIG to make the output from the existing methods (printfs and couts) available as an API. My ideal vision would be that the output of the tools would be a iterator that could be looped over in Python/

Does anyone have experience with this? I would be very grateful for concrete examples with sample code. Hopefully, I am missing something very obvious.

Gratefully,
Aaron

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帥小哥 2024-09-15 12:49:14

@jobu - SWIG 的重点是包装 C++ 代码 API,以便可以通过其他语言、python、perl 等访问它们,因此基于管道的访问是不合适的。这决不会阻止您根据需要管道输出或输入,您的用户只需要用自己的语言调用适当的打印函数。

但同样,重点是提供基于功能的访问。

@jobu - The point of SWIG is to wrap the C++ code-API's so that they can be accessed via the other language, python, perl, etc and as such pipe-based access would not be appropriate. This in no way would prevent you from piping outputs or inputs as needed either, your users would only need to call the appropriate print functions in their own language.

But again, the whole point is to provide function based access.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文