How to wrap the template class for csharp language

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to wrap the template class for csharp language

RAVI NANJUNDAPPA
Hi,
Can you please help me in resolving this problem ?

/* File : example.h */

// Some template definitions

template<class T> T max(T a, T b) { return  a>b ? a : b; }

namespace X{

  template<class T> class vector {
    T *v;
    int sz;
    public:
    vector(int _sz) {
      v = new T[_sz];
      sz = _sz;
    }
    T &get(int index) {
      return v[index];
    }
    void set(int index, T &val) {
      v[index] = val;
    }
#ifdef SWIG
    %extend {
      T getitem(int index) {
        return $self->get(index);
      }
      void setitem(int index, T val) {
        $self->set(index,val);
      }
    }
#endif
  };
}

namespace Y{

  template < typename t> class sig< void ( t) >
    {
      public:

        sig() { }

        ~sig() { }

        bool Empty() const
        {
          return true;
        }

    };

}


/* File : example.i */
%module example

%{
#include "example.h"
using namespace X;
using namespace Y;
%}

/*%nspace X::vector;*/

/* Let's just grab the original header file here */
%include "example.h"

/* Now instantiate some specific template declarations */

%template(maxint) max<int>;
%template(maxdouble) max<double>;
%template(vecint) X::vector<int>;
%template(vecdouble) X::vector<double>;
%template(sigArg1Float) Y::sig<void(float&)>;



The output of make is as below:

$ make
make -f ../../Makefile SRCDIR='' CXXSRCS='' \
        SWIG_LIB_DIR='../../../Lib' SWIGEXE='../../../swig' \
        SWIGOPT='' TARGET='example' INTERFACE='example.i' csharp_cpp
make[1]: Entering directory `/home/ravi.n/swig-3.0.9/Examples/csharp/template'
env SWIG_LIB=../../../Lib  ../../../swig -v -csharp -c++  -o example_wrap.cxx example.i
Language subdirectory: csharp
Search paths:
   ./
   ./swig_lib/csharp/
   ../../../Lib/csharp/
   ./swig_lib/
   ../../../Lib/
Preprocessing...
Starting language-specific parse...
example.h:39: Warning 317: Specialization of non-template 'sig'.
example.i:27: Error: Template 'sig' undefined.
Processing types...
C++ analysis...
Processing nested classes...
Generating wrappers...
make[1]: *** [csharp_cpp] Error 1
make[1]: Leaving directory `/home/ravi.n/swig-3.0.9/Examples/csharp/template'
make: *** [build] Error 2


Please help me in resolving this error asap.
Dono what am missing here.

Thanks and Best Regards,
N Ravi
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to wrap the template class for csharp language

RAVI NANJUNDAPPA
Samsung Enterprise Portal mySingle

 

 

Thanks and Best Regards,

N Ravi

 

 

 

------- Original Message -------

Sender : RAVI NANJUNDAPPA<[hidden email]> Chief Engineer/SRI-Bangalore-Advanced Web/Samsung Electronics

Date : Jun 07, 2016 18:11 (GMT+05:30)

Title : [Swig-user] How to wrap the template class for csharp language

 

Hi,
Can you please help me in resolving this problem ?

/* File : example.h */

// Some template definitions

template T max(T a, T b) { return  a>b ? a : b; }

namespace X{

  template class vector {
    T *v;
    int sz;
    public:
    vector(int _sz) {
      v = new T[_sz];
      sz = _sz;
    }
    T &get(int index) {
      return v[index];
    }
    void set(int index, T &val) {
      v[index] = val;
    }
#ifdef SWIG
    %extend {
      T getitem(int index) {
        return $self->get(index);
      }
      void setitem(int index, T val) {
        $self->set(index,val);
      }
    }
#endif
  };
}

namespace Y{

  template < typename t> class sig< void ( t) >
    {
      public:

        sig() { }

        ~sig() { }

        bool Empty() const
        {
          return true;
        }

    };

}


/* File : example.i */
%module example

%{
#include "example.h"
using namespace X;
using namespace Y;
%}

/*%nspace X::vector;*/

/* Let's just grab the original header file here */
%include "example.h"

/* Now instantiate some specific template declarations */

%template(maxint) max;
%template(maxdouble) max;
%template(vecint) X::vector;
%template(vecdouble) X::vector;
%template(sigArg1Float) Y::sig;



The output of make is as below:

$ make
make -f ../../Makefile SRCDIR='' CXXSRCS='' \
SWIG_LIB_DIR='../../../Lib' SWIGEXE='../../../swig' \
SWIGOPT='' TARGET='example' INTERFACE='example.i' csharp_cpp
make[1]: Entering directory `/home/ravi.n/swig-3.0.9/Examples/csharp/template'
env SWIG_LIB=../../../Lib  ../../../swig -v -csharp -c++  -o example_wrap.cxx example.i
Language subdirectory: csharp
Search paths:
   ./
   ./swig_lib/csharp/
   ../../../Lib/csharp/
   ./swig_lib/
   ../../../Lib/
Preprocessing...
Starting language-specific parse...
example.h:39: Warning 317: Specialization of non-template 'sig'.
example.i:27: Error: Template 'sig' undefined.
Processing types...
C++ analysis...
Processing nested classes...
Generating wrappers...
make[1]: *** [csharp_cpp] Error 1
make[1]: Leaving directory `/home/ravi.n/swig-3.0.9/Examples/csharp/template'
make: *** [build] Error 2


Please help me in resolving this error asap.
Dono what am missing here.

Thanks and Best Regards,
N Ravi


------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to wrap the template class for csharp language

RAVI NANJUNDAPPA
In reply to this post by RAVI NANJUNDAPPA
my bad ... resending the previous mail in plain-text format.

Thanks and Best Regards,
N Ravi

------- Original Message -------
Sender : RAVI NANJUNDAPPA<[hidden email]> Chief Engineer/SRI-Bangalore-Advanced Web/Samsung Electronics
Date : Jun 07, 2016 18:11 (GMT+05:30)
Title : [Swig-user] How to wrap the template class for csharp language

Hi,
Can you please help me in resolving this problem ?

/* File : example.h */

// Some template definitions

template T max(T a, T b) { return  a>b ? a : b; }

namespace X{

  template class vector {
    T *v;
    int sz;
    public:
    vector(int _sz) {
      v = new T[_sz];
      sz = _sz;
    }
    T &get(int index) {
      return v[index];
    }
    void set(int index, T &val) {
      v[index] = val;
    }
#ifdef SWIG
    %extend {
      T getitem(int index) {
        return $self->get(index);
      }
      void setitem(int index, T val) {
        $self->set(index,val);
      }
    }
#endif
  };
}

namespace Y{

  template < typename t> class sig< void ( t) >
    {
      public:

        sig() { }

        ~sig() { }

        bool Empty() const
        {
          return true;
        }

    };

}


/* File : example.i */
%module example

%{
#include "example.h"
using namespace X;
using namespace Y;
%}

/*%nspace X::vector;*/

/* Let's just grab the original header file here */
%include "example.h"

/* Now instantiate some specific template declarations */

%template(maxint) max;
%template(maxdouble) max;
%template(vecint) X::vector;
%template(vecdouble) X::vector;
%template(sigArg1Float) Y::sig;



The output of make is as below:

$ make
make -f ../../Makefile SRCDIR='' CXXSRCS='' \
SWIG_LIB_DIR='../../../Lib' SWIGEXE='../../../swig' \
SWIGOPT='' TARGET='example' INTERFACE='example.i' csharp_cpp
make[1]: Entering directory `/home/ravi.n/swig-3.0.9/Examples/csharp/template'
env SWIG_LIB=../../../Lib  ../../../swig -v -csharp -c++  -o example_wrap.cxx example.i
Language subdirectory: csharp
Search paths:
   ./
   ./swig_lib/csharp/
   ../../../Lib/csharp/
   ./swig_lib/
   ../../../Lib/
Preprocessing...
Starting language-specific parse...
example.h:39: Warning 317: Specialization of non-template 'sig'.
example.i:27: Error: Template 'sig' undefined.
Processing types...
C++ analysis...
Processing nested classes...
Generating wrappers...
make[1]: *** [csharp_cpp] Error 1
make[1]: Leaving directory `/home/ravi.n/swig-3.0.9/Examples/csharp/template'
make: *** [build] Error 2


Please help me in resolving this error asap.
Dono what am missing here.

Thanks and Best Regards,
N Ravi
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to wrap the template class for csharp language

William S Fulton
In reply to this post by RAVI NANJUNDAPPA
On 7 June 2016 at 13:41, RAVI NANJUNDAPPA <[hidden email]> wrote:

> example.h:39: Warning 317: Specialization of non-template 'sig'.
> example.i:27: Error: Template 'sig' undefined.

This is fairly self-explanatory... you can't specialize something that
is not a template. If you put your code through a C++ compiler you get
a similar error.

William

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to wrap the template class for csharp language

RAVI NANJUNDAPPA
In reply to this post by RAVI NANJUNDAPPA
Hi William,

Thanks for the information.
I guess, SWIG is not able to identify class templates of the below type.

template <typename t1> // TYPE1
class A1< void (t1)> {
public:
.....
.....
void method1( t1 arg0 )
  {
       .....
  }

};

All that I've seen so far is that SWIG generates the specialization code for the templates of this type:

template <typename t1> // TYPE2
class A1 {
public:
.....
.....
void method1( t1 arg0 )
  {
       .....
  }
};
 
As of now, am using a work-around for this by using %extend and inside each of the required member functions calling the corresponding methods using $self->.
For ex: (for float type)
template < typename t1> class A1< void ( t1) >;
template<> class A1< void(float&) >   { // TYPE3
public:
.....
.....
       void method1(float& arg0)
        {
          $self->Emit(arg0);
        }
};
 

Any idea if SWIG support code generation for TYPE 1? or anything we are missing here ?


Thanks and Best Regards,
N Ravi
------- Original Message -------
Sender : William S Fulton<[hidden email]>
Date : Jun 08, 2016 03:04 (GMT+05:30)
Title : Re: [Swig-user] How to wrap the template class for csharp language

On 7 June 2016 at 13:41, RAVI NANJUNDAPPA wrote:

> example.h:39: Warning 317: Specialization of non-template 'sig'.
> example.i:27: Error: Template 'sig' undefined.

This is fairly self-explanatory... you can't specialize something that
is not a template. If you put your code through a C++ compiler you get
a similar error.

William
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to wrap the template class for csharp language

William S Fulton
On 9 June 2016 at 05:33, RAVI NANJUNDAPPA <[hidden email]> wrote:

> Hi William,
>
> Thanks for the information.
> I guess, SWIG is not able to identify class templates of the below type.
>
> template <typename t1> // TYPE1
> class A1< void (t1)> {
> public:
> .....
> .....
> void method1( t1 arg0 )
>   {
>        .....
>   }
>
> };
>
> All that I've seen so far is that SWIG generates the specialization code for the templates of this type:
>
> template <typename t1> // TYPE2
> class A1 {
> public:
> .....
> .....
> void method1( t1 arg0 )
>   {
>        .....
>   }
> };
>
> As of now, am using a work-around for this by using %extend and inside each of the required member functions calling the corresponding methods using $self->.
> For ex: (for float type)
> template < typename t1> class A1< void ( t1) >;
> template<> class A1< void(float&) >   { // TYPE3
> public:
> .....
> .....
>        void method1(float& arg0)
>         {
>           $self->Emit(arg0);
>         }
> };
>
>
> Any idea if SWIG support code generation for TYPE 1? or anything we are missing here ?

Explicit specialisation (TYPE 3) does work. You can see this using the
-debug-template option:

swig -csharp -c++ -debug-template -o example_wrap.cxx example.i

example.i:42: template_debug: Searching for match to: 'sig<(f(r.float).void)>'
    searching for : 'sig<(f(r.float).void)>' (explicit specialization)
    explicit specialization found: 'sig<(f(r.float).void)>'
    chosen template:'sig<(f(r.float).void)>'

Partial specialisation (TYPE 1) has some limitations and I'm afraid
that it does not work for template parameters that are functions. You
can see it failing to match with the -template-debug option:

example.i:42: template_debug: Searching for match to: 'sig<(f(r.float).void)>'
    searching for : 'sig<(f(r.float).void)>' (explicit specialization)
    checking match: 'sig<(f($1).void)>' (partial specialization)
    matched partials: NONE
    chosen primary template: 'sig'
    chosen template:'sig'

I suggest you raise a github issue. The area of code to fix for anyone
inclined to do so is in Source/CParse/templ.c.

William

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Loading...