I've got some python code that generates a StringIO variable. I'd like to pass this variable to a C++ function using a stringstream parameter (on the assumption C++ stringstream is the closest match to a python StringIO). Is there a simple way using swig to do this translation?
I see in the swig modules there is a std_sstream.i which contains some stringstream code, but I can't find any references to it in the swig documentation, or any examples of its use on a web search.
To try and make it a little clearer, I'll include some very simple code below. Here's test.cpp which is fixed and I can't change:
#include <iostream>
#include <sstream>
#include "test.h"
using namespace std;
void StTest(stringstream &ss)
{
cout << ss << endl;
}
Here's test.h which is also fixed:
#include <sstream>
using namespace std;
void StTest(stringstream &ss);
Here's the python code which I can edit and which calls the C++ StTest function (we'll call this test_test.py):
#!/usr/bin/env python
import StringIO
import test
ss = StringIO.StringIO()
ss.write("Hello")
# Maybe some thing here to convert ss from StringIO to stringstream
test.StTest(ss)
So I'm looking for something that can do the conversion from StringIO to stringstream in the commented line above.
Here's my initial dig at the test.i file for swig do its stuff:
/* test.i */
%module test
%{
#include "test.h"
%}
%include "std_sstream.i"
%include "test.h"
I've included "std_sstream.i" in test.i as this is what ought to be used, I assume. Do I need to add something to this file to get it to do something?
Currently the error report when running test_test.py is:
TypeError: in method 'StTest', argument 1 of type 'stringstream &'