From: Fletcher, J. P <j.p...@as...> - 2007-09-19 15:17:16
|
Christopher I am not sure if it is yet answered by someone else, but here is what I hav= e used for the output of an STL vector, working with C++ and Ruby. I hope this helps. John /* Headers for C++ */ %{ #include <sstream> using namespace std; /* End of headers passed to C++ */ %} // This contains the typemaps to handle vector classes properly. // These are part of the SWIG Ruby distribution. // Using this loads typemaps for STL string, vector and map. %include "stl.i" namespace std { /* This makes available an STL vector of type double */ %template (Vector_Double) std::vector<double>; %extend vector<double> { std::string __str__() { std::ostringstream out; typedef std::vector<double> Vector_Double; out << "( "; Vector_Double::iterator i1 =3D self->begin(); Vector_Double::iterator i1end =3D self->end(); for ( ; i1!=3Di1end; i1++) out << *i1 << " "; out << ")" << std::endl; return out.str(); } } } Dr John P. Fletcher Tel: (44) 121 204 3389 (direct line) Chemical Engineering and Applied Chemistry (CEAC), School of Engineering and Applied Science (SEAS), Aston University, Aston Triangle, BIRMINGHAM B4 7ET U.K. CEAC Web site http://www.ceac.aston.ac.uk/ FAX: (44) 121 204 3679 -----Original Message----- From: swi...@li... [mailto:swig-user-bounces@lis= ts.sourceforge.net] On Behalf Of Christopher Barker Sent: 18 September 2007 01:21 To: swi...@li... Subject: Re: [Swig-user] How to use std_vector.i ?? Sorry to answer my own question, but I finally found: Doc/Manual/Library.html#Library_stl_cpp_library in which I found just what I was looking for: namespace std { %template(vectori) vector<int>; %template(vectord) vector<double>; }; bingo! Now if I can just figure out how to write a nice __str__ and/or __repr__ fo= r them, so I can just print them and get something useful! Thanks anyway, -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chr...@no... ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft= (R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Swig-user mailing list Swi...@li... https://lists.sourceforge.net/lists/listinfo/swig-user |