469,949 Members | 2,697 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,949 developers. It's quick & easy.

SWIG std::string& passing

Hello,

I have been trying to get this simple call to work with a SWIG
interface. The problem is I do not know how to pass a const char * or a
std::string & in python to SWIG wrapped code. I tried several of the
*.i libraries at http://www.swig.org/Doc1.3/Library.html. Most notably
the "std_string.i" And get the following:
w.SetDestFilename("test.bmp")

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File
"/home/soa/dev/users/reder/Dshell++Pkg-reder01/lib/PYTHON/Dspace/Dnoise_Py.py",
line 1340, in SetDestFilename
def SetDestFilename(*args): return
_Dnoise_Py.WriterBMP_SetDestFilename(*args)
TypeError: argument number 2: a 'std::string *' is expected,
'str(test.bmp)' is received

The C++ method is:

void WriterBMP::SetDestFilename (const std::string& filename)

This should be easy to pass the filename to? Do you have an example?
What do I add to the *.i file?

Thanks for any and all replies,

Len

--
===================================
Leonard J. Reder
Home office email : re***@ieee.org
Lab email : re***@jpl.nasa.gov
Lab web page : http://reder.jpl.nasa.gov
===================================
--
===================================
Leonard J. Reder
Home office email : re***@ieee.org
Lab email : re***@jpl.nasa.gov
Lab web page : http://reder.jpl.nasa.gov
===================================
Jul 19 '05 #1
1 4851
Add the line

%include stl.i

to your .i file. This will make other stl containers available, in
addition to string. Make sure you put this line before any include
directives for classes that use std::string. SWIG requires classes to
be declared before they are used in order for the interfaces to be
exposed completely.

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by KidLogik | last post: by
15 posts views Thread by roberts.noah | last post: by
2 posts views Thread by zhege | last post: by
3 posts views Thread by sernamar | last post: by
1 post views Thread by gabriel.becedillas | last post: by
reply views Thread by Amitabh Saikia | last post: by
2 posts views Thread by ragged_hippy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.