PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Swig | 37 lines | 32 code | 5 blank | 0 comment | 0 complexity | 9566a9a5ebe6d058b14ab700a4f8a779 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module smart_pointer_template_const_overload
  2. %warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED) SmartPointer<FooImplementation>::operator->; // Overloaded method SmartPointer< FooImplementation >::operator ->() ignored
  3. %inline %{
  4. template <class T> class SmartPointer {
  5. T *ptr;
  6. public:
  7. SmartPointer(T *t = 0) : ptr(t) {}
  8. inline const T * operator->() const { return ptr; }
  9. inline T * operator->() { return ptr; }
  10. };
  11. class FooImplementation {
  12. public:
  13. int mingy() { return 0; }
  14. int constmingy() const { return 0; }
  15. static int thingy() { return 0; }
  16. static int svariable;
  17. static const int constsvariable;
  18. int normalvariable;
  19. };
  20. int FooImplementation::svariable = 0;
  21. const int FooImplementation::constsvariable = 2;
  22. void tester() {
  23. SmartPointer<FooImplementation> p;
  24. p->mingy();
  25. p->constmingy();
  26. p->thingy();
  27. int a = p->svariable;
  28. a = p->constsvariable;
  29. a = p->normalvariable;
  30. }
  31. %}
  32. %template(FooSmartPointer) SmartPointer<FooImplementation>;