[PyKDE] SIP and C++ templates

Claus, Richard claus at slac.stanford.edu
Fri May 6 19:00:19 BST 2005


Are there any issues with, or better ways to do, the following:

.h file:

namespace MyNamespace
{
  template<unsigned T>
  class Klass : public BaseKlass<T> 
  {
  public:
    Klass();
    virtual ~Klass();

    void method1();

    ...
  };
  typedef Klass<1024> Small
  typedef Klass<4096> Large
};

.sip file:

namespace MyNamespace 
{
  class Small
  {
%TypeHeaderCode
#include "Klass.h"
%End

  public:
    Small();
    virtual ~Small();

    void method1();

    ...
  };

  class Large
  {
%TypeHeaderCode
#include "Klass.h"
%End

  public:
    Large();
    virtual ~Large();

    void method1();

    ...
  };
};


This seems to work fine.  Small and Large are visible from Python and method1() executes fine.  The methods of BaseKlass are not accessible from Python, but that's okay for my purposes since they're used only by methods of Klass.

Another solution might be to make Small and Large bona fide classes that are derived from Klass<1024> and Klass<4096>, resp., rather than typedefs.  

Are these blessed ways to do things or am I climbing through a loophole?

	Thanks,
		Ric 




More information about the PyQt mailing list