[PyQt] template / container class default constructor
Phil Thompson
phil at riverbankcomputing.com
Thu Feb 3 11:11:58 GMT 2011
On Thu, 03 Feb 2011 11:50:10 +0100, John Beuving <johnbeuving at gmail.com>
wrote:
> Hi,
>
> I have the following c++ code which I want to SIP.
>
> class Input
> {
> Input(unsigned int windowSize=1, unsigned int stepSize=1);
>
> bool DataAvailable(unsigned int elements);
> };
>
> // Template implementation
> template<typename T>
> class InputT: public Input
> {
> public:
> InputT(unsigned int windowSize=1, unsigned int stepSize=1);
> ~InputT();
>
> const T& operator[] (unsigned int index) const;
> const T* operator-> () const;
> string DataType() const {return TypeName<T>();}
> };
>
> struct testData
> {
> testData();
>
> int cnt;
> };
>
> In the python code I want to construct an object of type:
>
> InputT<testData> test;
>
> which should probably going to look like:
>
> test = InputTestData()
>
> So now I already have a MappedType for InputT<TYPE>.
> But how do I add a constructor of some kind for this template class
> (like InputTestData())
>
>
> John
I don't understand the question... If you are adding a C++ ctor then add
it to the appropriate class definition. If you want to overload the
__init__ of a Python type then sub-class the Python type.
If InputT<TYPE> is a mapped type then you must have an existing Python
InputTestData type that you are mapping to and from.
If you want SIP to create the InputTestData type for you then InputT<TYPE>
is declared as class template and not a mapped type. You then provide a
typedef which specifies testData as the TYPE.
Phil
Phil
More information about the PyQt
mailing list