PageRenderTime 12ms CodeModel.GetById 10ms app.highlight 0ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-29/SWIG/Examples/test-suite/python/vector.i

#
Swig | 51 lines | 45 code | 6 blank | 0 comment | 0 complexity | f047874d6640cb96e65ef4da5e962ff9 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
 1%module vector
 2%{
 3#include <vector>
 4%}
 5
 6%define SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE...)
 7  public:
 8    typedef size_t size_type;
 9    typedef CTYPE value_type;
10    size_type size() const;
11    vector();
12    %extend {
13      static std::vector<CTYPE > *Repeat(const value_type& value, int count) /*throw (std::out_of_range)*/ {
14//        if (count < 0)
15//          throw std::out_of_range("count");
16        return new std::vector<CTYPE >(count, value);
17      }
18    }
19%enddef
20
21namespace std {
22  // primary (unspecialized) class template for std::vector
23  // does not require operator== to be defined
24  template<class T> class vector {
25    SWIG_STD_VECTOR_MINIMUM(T, T)
26  };
27}
28
29%define SWIG_STD_VECTOR_SPECIALIZE(CSTYPE, CTYPE...)
30namespace std {
31  template<> class vector<CTYPE > {
32    SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE)
33  };
34}
35%enddef
36
37SWIG_STD_VECTOR_SPECIALIZE(float, float)
38
39%inline %{
40typedef float Real;
41%}
42
43#if 1
44//fails
45namespace std {
46    %template(RealVector) vector<Real>;
47}
48#else
49//works
50%template(RealVector) std::vector<Real>;
51#endif