开发者

Best approach for creating a SWIG API to a library that writes to stdout?

开发者 https://www.devze.com 2023-01-06 09:31 出处:网络
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

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.

Gratef开发者_如何学JAVAully, Aaron


@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.

0

精彩评论

暂无评论...
验证码 换一张
取 消