PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/ttn-post-libtool-1-4-3-upgrade/SWIG/Examples/python/template/example.h

#
C++ Header | 32 lines | 26 code | 4 blank | 2 comment | 0 complexity | 56c0b7f11fb002655fca03be448a9a4a MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* File : example.h */
  2. // Some template definitions
  3. template<class T> T max(T a, T b) { return a>b ? a : b; }
  4. template<class T> class vector {
  5. T *v;
  6. int sz;
  7. public:
  8. vector(int _sz) {
  9. v = new T[_sz];
  10. sz = _sz;
  11. }
  12. T &get(int index) {
  13. return v[index];
  14. }
  15. void set(int index, T &val) {
  16. v[index] = val;
  17. }
  18. #ifdef SWIG
  19. %extend {
  20. T getitem(int index) {
  21. return self->get(index);
  22. }
  23. void setitem(int index, T val) {
  24. self->set(index,val);
  25. }
  26. }
  27. #endif
  28. };