PageRenderTime 11ms CodeModel.GetById 2ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/features.i

#
Swig | 181 lines | 150 code | 31 blank | 0 comment | 0 complexity | 5d769d85b16bbea701e47820207d50d6 MD5 | raw file
  1%module features
  2
  3%warnfilter(SWIGWARN_LANG_IDENTIFIER,SWIGWARN_IGNORE_OPERATOR_PLUSEQ);
  4
  5// This testcase checks that %feature is working for templates and non user supplied constructors/destructors and is just generally working
  6
  7// If the default %exception is used it will not compile. It shouldn't get used.
  8%exception "this_will_not_compile";
  9
 10// Test 1: Test for no user supplied constructors and destructor
 11%exception Simple::Simple(const Simple&) "$action /*Simple::Simple*/";
 12%exception Simple::Simple() "$action /*Simple::Simple*/";
 13%exception Simple::~Simple() "$action /*Simple::~Simple*/";
 14
 15%inline %{
 16class Simple {};
 17%}
 18
 19
 20%exception NS::SimpleNS::SimpleNS(const NS::SimpleNS&) "$action /*NS::SimpleNS::SimpleNS*/";
 21%exception NS::SimpleNS::SimpleNS() "$action /*NS::SimpleNS::SimpleNS*/";
 22%exception NS::SimpleNS::~SimpleNS() "$action /*NS::SimpleNS::~SimpleNS*/";
 23// method tests
 24%exception NS::SimpleNS::method()       "_failed_ /*NS::Simple::method() const*/";
 25%exception NS::SimpleNS::method() const "$action /*NS::Simple::method() const*/";
 26%exception NS::SimpleNS::afunction() "$action /*NS::Simple::afunction()*/";
 27
 28%inline %{
 29  namespace NS 
 30  {
 31    
 32    class SimpleNS {
 33    public:
 34      void method() const {}
 35      void afunction() {}
 36    };
 37  }
 38  
 39%}
 40
 41// Test 2: Test templated functions
 42%exception foobar "caca";
 43%exception foobar<int>(int) "$action /*foobar<int>*/";
 44
 45%inline %{
 46template<class T> void foobar(T t) {}
 47%}
 48
 49%template(FooBarInt) foobar<int>;
 50
 51// Test 3: Test templates with no user supplied constructors and destructor
 52%exception SimpleTemplate<int>::SimpleTemplate(const SimpleTemplate<int>&) "$action /*SimpleTemplate<int>::SimpleTemplate<int>*/";
 53%exception SimpleTemplate<int>::SimpleTemplate() "$action /*SimpleTemplate<int>::SimpleTemplate<int>*/";
 54%exception SimpleTemplate<int>::~SimpleTemplate() "$action /*SimpleTemplate<int>::~SimpleTemplate*/";
 55
 56%inline %{
 57template<class T> class SimpleTemplate {
 58 public:
 59};
 60 
 61%}
 62
 63%template(SimpleInt) SimpleTemplate<int>;
 64
 65// Test 4: Test templates with user supplied constructors and destructor
 66%exception Template<int>::Template() "$action /*Template<int>::Template<int>*/";
 67%exception Template<int>::Template(const Template&) "$action /*Template<int>::Template<int>(const Template&)*/";
 68%exception Template<int>::~Template() "$action /*Template<int>::~Template*/";
 69// method tests
 70%exception Template<int>::foo "$action /*Template<int>::foo*/";
 71%exception Template::get "$action /*Template<int>::get*/";
 72%exception Template<int>::set(const int &t) "$action /*Template<int>::set(const int &t)*/";
 73%exception Template<int>::bar(const int &t)       "_failed_ /*Template<int>::bar(const int &t) const*/";
 74%exception Template<int>::bar(const int &t) const "$action /*Template<int>::bar(const int &t) const*/";
 75
 76%inline %{
 77template<class T> class Template {
 78public:
 79  Template(){}
 80
 81  Template(const Template&){}
 82  ~Template(){}
 83  void foo(){}
 84  void bar(const int &t) const {}
 85#ifdef SWIG
 86    %extend {
 87      T& get(int i) const {
 88        throw 1;
 89      }
 90      void set(const T &t) {}
 91    }
 92#endif
 93};
 94%}
 95
 96%template(TemplateInt) Template<int>; 
 97
 98// Test 5: wildcards
 99%exception Space::WildCards::WildCards(const Space::WildCards&) "$action /* Space::WildCards::WildCards() */";
100%exception Space::WildCards::WildCards() "$action /* Space::WildCards::WildCards() */";
101%exception Space::WildCards::~WildCards() "$action /* Space::WildCards::WildCards() */";
102%exception *::incy              "_failure_ /* *::incy */";
103%exception *::incy(int a)       "_failure_ /* *::incy(int a) */";
104%exception *::incy(int a) const "$action /* *::incy(int a) const */";
105%exception *::wincy(int a) "$action /* *::wincy(int a) */";
106%exception *::spider "$action /* *::spider */";
107%exception *::spider(int a) "_failure_ /* *::spider(int a)  */";
108
109%inline %{
110namespace Space {
111  struct WildCards {
112    virtual ~WildCards() {}
113    virtual WildCards* incy(int a) const { return 0; }
114    virtual WildCards* wincy(int a) { return 0; }
115    virtual WildCards* spider(int a) const { return 0; }
116  };
117}
118%}
119
120// Test 6: default arguments
121%exception Space::Animals::Animals(const Space::Animals&) "$action /* Space::Animals::Animals(int a = 0, double d = 0.0) */";
122%exception Space::Animals::Animals(int a = 0, double d = 0.0) "$action /* Space::Animals::Animals(int a = 0, double d = 0.0) */";
123%exception Space::Animals::~Animals() "$action /* Space::Animals::~Animals() */";
124%exception Space::Animals::lions(int a = 0, double d = 0.0) const "$action /* Space::Animals::lions(int a = 0, double d = 0.0) const */";
125%exception Space::Animals::leopards(int a = 0, double d = 0.0) "$action /* Space::Animals::leopards(int a = 0, double d = 0.0) */";
126%exception *::cheetahs(int a = 0, double d = 0.0) const "$action /* *::cheetahs(int a = 0, double d = 0.0) const */";
127%exception *::jackal(int a = 0, double d = 0.0) "$action /* *::jackal(int a = 0, double d = 0.0) */";
128%inline %{
129namespace Space {
130  struct Animals {
131    Animals(int a = 0, double d = 0.0) {}
132    void* lions(int a = 0, double d = 0.0) const { return 0; }
133    void* leopards(int a = 0, double d = 0.0) { return 0; }
134    int cheetahs(int a = 0, double d = 0.0) const { return 0; }
135    int jackal(int a = 0, double d = 0.0) { return 0; }
136  };
137}
138%}
139
140// Test 7: inheritance
141%exception Space::Base::Base(const Space::Base&) "$action /* Space::Base::Base() */";
142%exception Space::Base::Base() "$action /* Space::Base::Base() */";
143%exception Space::Base::~Base() "$action /* Space::Base::~Base() */";
144%exception Space::Derived::Derived(const Space::Derived&) "$action /* Space::Derived::Derived() */";
145%exception Space::Derived::Derived() "$action /* Space::Derived::Derived() */";
146%exception Space::Derived::~Derived() "$action /* Space::Derived::~Derived() */";
147// The following should apply to both Base and Derived
148%exception Space::Base::virtualmethod(int a) const "$action /* Space::Base::virtualmethod(int a) const */";
149
150%exception Space::Base::operator+=(int) "$action /* Space::Base::Base() */";
151
152%inline %{
153namespace Space {
154  struct Base {
155    int operator+=(int) { return 0; }    
156    virtual const char** virtualmethod(int a) const { return 0; }
157    virtual ~Base() {}
158  };
159  struct Derived : Base {
160    virtual const char** virtualmethod(int a) const { return 0; }
161  };
162}
163%}
164
165// Test 8 conversion operators
166%rename(opbool) operator bool;
167%rename(opuint) operator unsigned int;
168
169%exception ConversionOperators::ConversionOperators() "$action /* ConversionOperators::ConversionOperators() */";
170%exception ConversionOperators::~ConversionOperators() "$action /* ConversionOperators::~ConversionOperators() */";
171%exception ConversionOperators::operator bool "$action /* ConversionOperators::operator bool */";
172%exception ConversionOperators::operator unsigned int "$action /* ConversionOperators::unsigned int*/";
173
174%inline %{
175  class ConversionOperators {
176  public:
177    operator bool() { return false; }
178    operator unsigned int() { return 0; }
179  };
180%}
181