[英]$stdin compatibility with std::istream using swig, C++, and Ruby
I have a function in C++ that takes in an std::istream as the input: 我在C ++中有一个函数,将std :: istream作为输入:
class Foo {
Foo(std::istream &);
}
Using SWIG, I've bound it to Ruby, but Ruby's $stdin variable is fundamentally different from anything like the stream classes in C++, so I'm not sure how to either 1) expose the C++ class to Ruby in a way that I can use $stdin, or 2) convert $stdin into something the C++ class can understand. 使用SWIG,我已将其绑定到Ruby,但是Ruby的$ stdin变量与C ++中的流类有本质上的区别,因此我不确定如何进行以下操作:1)以一种我将C ++类公开给Ruby的方式可以使用$ stdin,或2)将$ stdin转换为C ++类可以理解的内容。
Anyone have experience with binding iostreams in C++ to Ruby? 任何人都具有将C ++中的iostream绑定到Ruby的经验吗?
Thanks. 谢谢。
You can use an instance of std::istream that implements its operations with Ruby methods on $stdin called through the C interface (eg, using rb_funcall). 您可以使用std :: istream实例,该实例通过Ruby方法在通过C接口调用的$ stdin上实现其操作(例如,使用rb_funcall)。 You can't do it by deriving a class from std::istream itself, because its methods are not virtual;
您不能通过从std :: istream本身派生一个类来做到这一点,因为它的方法不是虚拟的。 instead you'll need to derive from std::stream_buf and instantiate an istream that uses your stream buffer.
相反,您需要从std :: stream_buf派生并实例化使用您的流缓冲区的istream。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.