Problem on SWIG/Python

clio wangye1 at auburn.edu
Tue Oct 2 12:34:35 EDT 2001


Hi,
I am working on wrapping the C++ class for Python by using SWIG. The C++ 
code uses Template like this:

template<class T>
class NRSimpleAttribute : public NRAttribute{
public:
    NRSimpleAttribute(int key, int type, int op, T val, int size = 0) :
       NRAttribute(key, type, op, sizeof(T)) {

       assert(type != STRING_TYPE && type != BLOB_TYPE);
       val_ = new T(val);
    }

    ~NRSimpleAttribute() {
       assert(type_ != STRING_TYPE && type_ != BLOB_TYPE);
       delete (T*) val_;
    };

    T getVal() { return *(T*)val_; };
    int getLen() { return len_; };
    void setVal(T value) { *(T *)val_ = value; };
};

class NRSimpleAttribute<char *>: public NRAttribute {
public:
    NRSimpleAttribute(int key, int type, int op, char *val, int size = 0);

    ~NRSimpleAttribute() {
       assert(type_ == STRING_TYPE);
       delete [] (char *) val_;
    };

    char * getVal() { return (char *)val_; };
    int getLen() {return len_; };
    void setVal(char *value);
};
.......

When I try to use siwg -c++ -python  XXX.i, the SWIG gave me this:

Syntax error
lkup.i:30. Syntax error in input.
lkup.i:42. Syntax error in input.
lkup.i:44. Syntax error in input.
lkup.i:56. Syntax error in input.

My questions are:
1) Does SWIG support Template in C++;
2) How to do that?

Thanks for any help!

clio




More information about the Python-list mailing list