I have a simple user defined StringList class in C++
. Its underlying container is a std::vector.
It would be convenient, when using this class in python, to have any StringList
object converted to a Python list whenever returned by a python wrapped object.
The StringList class do contain a function, getContainer()
, that do return a reference to the underlying vector<string>
object, and I would think this function could be used somehow?
For example, the C++ code
Raven aRaven;
StringList molecules;
molecules = aRaven.getMoleculesInDB();
populates the molecules object with a list of moleculenames (strings).
In Python, this looks like this, including code to loop over the list:
aRaven = Raven()
molecules = aRaven.getMoleculesInDB()
print 'There are ' + `molecules.count()` +' available.'
for mol in range(molecules.count()):
molName = molecules.at(mol)
...
It is desirable to instead of creating a StringList object in the aRaven.getMoleculesInDb(), creating a Python list with strings (from the underlying std::vector container). Then the user could write
aRaven = Raven()
molecules = aRaven.getMoleculesInDB() # <--- Returns a Python list of strings
for molName in molecules:
print 'molName'
...
Any pointers on how to achieve this in the swig interface file?