From armstrong.whit at gmail.com  Tue Nov 18 21:02:01 2008
From: armstrong.whit at gmail.com (Whit Armstrong)
Date: Tue, 18 Nov 2008 15:02:01 -0500
Subject: [Rd] Fwd: Fwd: SWIG with R and C++ STL
In-Reply-To: <11c6cf4e0811181150t7789aea6jf3a91c762e814ff9@mail.gmail.com>
References: <11c6cf4e0811041355v16321693hdd53d2376dc0a8c4@mail.gmail.com>
	<11c6cf4e0811061016r4dc114d8l261948c4512c1e12@mail.gmail.com>
	<8ec76080811061129p2e54125eqee948a31bb4a4de8@mail.gmail.com>
	<11c6cf4e0811161910v25ce5f30r71e891673612c078@mail.gmail.com>
	<11c6cf4e0811161911y49ded77di905fc86ea630f4b5@mail.gmail.com>
	<18720.62067.394678.969716@ron.nulle.part>
	<11c6cf4e0811181150t7789aea6jf3a91c762e814ff9@mail.gmail.com>
Message-ID: <8ec76080811181202j214743a9y7f0d4c7e53cd46cd@mail.gmail.com>

no all compilers support the export keyword.

just put the template in a .h or .hpp file and include it in your .cpp
file.  that should be enough.

-Whit


On Tue, Nov 18, 2008 at 2:50 PM, charlie <charlie.xia.fdu at gmail.com> wrote:
> Thanks guys for all your kind heartedness.
>
> Yeah, I got messed up with a lot of things in my previous program, like
> missing the definition of one function and etc. I finally discovered a good
> example on:
> http://www.opensource.apple.com/darwinsource/Current/swig-4/swig/Examples/java/funcptr/index.html.
> And I was able to make a workable example as following:
>
> /* test.i */
> %module test
> %{
> #include "test.h"
> %}
> %include "test.h"
>
> %constant B (*F)( const A&)=f;
> //let a=A(), b=B()
> %template(ia) ex1<A>; // from Doc, works
> %template(jab) ex2<A, B>; // jab(a,b) works
> %template(kab) ex3<A, B>; // kab(a,b,1) works
> %template(lab) ex4<A, B>; // lab(a,b,1,F) works
> %template(fab) ex5<A, B>; // fab(a,b,1,F) ultimate goal
>
> /* test.h */
>
> #include<iostream>
> using namespace std;
>
> class A { };
> class B { };
> class E { };
> B f( const A& ) { cout<<"This is a function map A to B"<<endl; return *(new
> B); };
> typedef B (*fp)( const A& );
>
> template<class T> E ex1(T a, T b) { cout<<"ex1, one parameter
> template"<<endl; return *(new E); }
> // NOTE: simple template function
>
> template<class T, class S> E ex2(T t, S s) { cout<<"ex2, two parameters
> template"<<endl; return *(new E); }
> // NOTE: this extends the one above with two template parameters
>
> template<class T, class S> E ex3(T t, S s, int k) {
>   cout<<"ex3, two parameters template plus an int argument"<<endl; return
> *(new E); }
> // NOTE: this extends the one above with additional integer argument
>
> template<class T, class S> E ex4(T t, S s, int k, fp gp) {
>   cout<<"ex4, two parameters template, an int argument and an func ptr
> argument"<<endl;
>   A a=A(); B b=gp(a); return *(new E); }
> // NOTE: this extends the one above with one more function poiter argument
>
> template <class C, class D>  E ex5(C c, D& d, int n, D (*g)(const C&)) {
>   cout<<"ex5, two parameters template, an int argument and a template func
> ptr argument"<<endl;
>   g(c); return *(new E); }
> // NOTE: this temaplate function TF takes a template function poiter as
> argument, our ultimate goal
>
> And currently I got my program work now. But the ex. in 5.4.9 still seems
> not working. Anyway, so far good for me now. Maybe one last thing, currently
> I need to put the definition and declaration of a template function all in
> one file, otherwise I got undefined symbol error. How can I separate them
> into a .h and .cpp file? The 'export' keyword which suggested in TCPL seems
> do't work with gcc. Any comments?
>
> Thanks a bunch already!
>
> Charlie
>
>
>
>



[Rd] Fwd: Fwd: SWIG with R and C++ STL
Whit Armstrong