From: Robert J. H. <rjh...@cs...> - 2006-07-18 20:20:54
|
I have a large set of header files which specify a set of template classes. In C++, I have operator<< overloaded so that you can dump an instance of this templatized class to an output stream of your choice. I understand I can get the same behavior from Python if in SWIG I use addmethod to add a __str__ method, but this strikes me as somewhat dangerous. All of the examples I've seen have included the class to be wrapped in the swig.i file itself, with addmethod used in the swig.i file to extend the class. Given the size of my headers, this seems to be a very bad idea. If I make adjustments to my headers, I don't want to have to remember to adjust the swig.i file to make sure the two remain in sync. Right now, the swig.i file is very simple and I'd love to keep it that way. In each of the Annealer classes specified in my swig.i file (listed below), there is a .solution() method which returns a std::string containing human-readable output. This would probably be the basis for any __str__ method. Can anyone give guidance on how to proceed in a way that will leave me with a terse, maintainable swig.i file? ===== %module Djinni %{ #include "Annealer.h" #include "TSPRoute.h" #include "Penalties.h" %} %include "Annealer.h" %include "TSPRoute.h" %include "Penalties.h" %template(TSP) TSPRoute<TSPTWWorld>; %template(CA_TSP) Annealer<Compressed, TravelingSalesman>; %template(SA_TSP) Annealer<Simulated, TravelingSalesman>; ===== |