title: How to use SWIG to create a dispatching wrapper class for a C++ template class
body: <p>We are trying to use SWIG to wrap a C++ template library for different languages (Python, Java, R..). We do not want to use a different class name in the traget language for every type instantiation. Instead, we'd like to get a single dispatching class (just like SWIG handles overloaded functions). As we have many classes, we also want to let SWIG extract the classes and methods from given C++ headers.</p>
  
  <p>Example: Assume a c++ header (read-only) containing</p>
  
  <pre><code>template&lt; typename T &gt;
  class Foo {
      Foo(const T * t);
      const T* getVal() const;
      void setVal(const T* t);
  };
  </code></pre>
  
  <p>Now we'd like to write an interface file for SWIG which creates a <strong>single</strong> class which dispatches to the right template instantiation (it'd be ok if this happened in every function call). In Python we'd like to allow something like this</p>
  
  <pre><code>from foo import Foo
  v_int = Foo(1)
  v_int.setVal(v_int.getVal())
  v_str = Foo("string")
  v_str.setVal(v_str.getVal())
  </code></pre>
  
  <p>I have some idea how to do this manually, but it would basically mean I have to write my own wrapping class in C++ with every member function in it that the template class defines. With the large number of classes we want to wrap this becomes an unpractical solution.</p>
  
  <p>Any idea? E.g. is there a way to "iterate" through all member functions in a SWIG interface file?</p>