swig problem with std::string &s
Marcus Stojek
stojek at part-gmbh.de
Wed Jan 8 15:41:50 EST 2003
Hi,
I am trying to get a C++ extension running with Swig (1.3.17)
(Swig newbie and no idea of C, Windows NT,VC++ 6.0, Python 2.2.1)
Example code:
/*----------------------------------------------*/
guiModel.h :
#include <vector>
#include <string>
class guiModel {
protected:
std::vector<std::string> ElsetNameList;
std::string idbName;
public:
void GetElsets (std::vector<std::string> &ElsetNames);
bool LimitToElset (std::string &ElsetName)
{
return ElsetName.compare(idbName) ? false : true;
}
guiModel (std::string &idb);
~guiModel();
} ;
/*----------------------------------------------*/
guiModel.cpp:
#include "guiModel.h"
guiModel::guiModel (std::string &idb) : idbName (idb)
{
ElsetNameList.push_back (idbName);
ElsetNameList.push_back ("This ");
ElsetNameList.push_back ("is ");
ElsetNameList.push_back ("the ");
ElsetNameList.push_back ("end!");
}
guiModel::~guiModel ()
{
ElsetNameList.clear();
}
void guiModel::GetElsets (std::vector<std::string> &ElsetNames)
{
for (int i=0; i < ElsetNameList.size(); i++)
ElsetNames.push_back (ElsetNameList[i]);
}
/*----------------------------------------------*/
Interface file:
/* File : guiModel.i */
%module guiModel
%{
#include "guiModel.h"
%}
%include std_string.i
%include std_vector.i
%include "guiModel.h"
/*----------------------------------------------*/
Compiling and linking the dll works fine.
after:
from guimodel import *
g=guimodel('test')
i get the output:
Traceback (most recent call last):
File "E:\test.py", line 6, in ?
g=guiModel('test')
File "E:\guiModel.py", line 38, in __init__
self.this = apply(_guiModel.new_guiModel,args)
TypeError: Type error. Expected _p_std__string
In the Swig documentation i found for std_string.i module:
"This module only supports types std::string and const std::string &.
Pointers and non-const references are left unmodified and returned as
SWIG pointers. "
What can I do without changing the C-code?
Thanks a lot for any help.
Marcus
More information about the Python-list
mailing list