FAQ
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

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJan 8, '03 at 8:41p
activeJan 8, '03 at 8:41p
posts1
users1
websitepython.org

1 user in discussion

Marcus Stojek: 1 post

People

Translate

site design / logo © 2022 Grokbase