PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Swig | 110 lines | 89 code | 21 blank | 0 comment | 0 complexity | 79899ffcc076294ac6c4aef4dc1e5b93 MD5 | raw file
  1%module li_std_vector
  2
  3%include "std_vector.i"
  4%include "std_string.i"
  5
  6%{
  7#include <algorithm>
  8#include <functional>
  9#include <numeric>
 10%}
 11
 12namespace std {
 13    %template(IntVector) vector<int>;
 14}
 15
 16%template(BoolVector) std::vector<bool>;
 17%template(CharVector) std::vector<char>;
 18%template(ShortVector) std::vector<short>;
 19%template(LongVector) std::vector<long>;
 20%template(UCharVector) std::vector<unsigned char>;
 21%template(UIntVector) std::vector<unsigned int>;
 22%template(UShortVector) std::vector<unsigned short>;
 23%template(ULongVector) std::vector<unsigned long>;
 24%template(DoubleVector) std::vector<double>;
 25%template(StringVector) std::vector<std::string>;
 26
 27
 28%inline %{
 29typedef float Real;
 30size_t typedef_test(std::vector<int>::size_type s) { return s; }
 31%}
 32
 33namespace std {
 34    %template(RealVector) vector<Real>;
 35}
 36
 37%inline %{
 38
 39double average(std::vector<int> v) {
 40    return std::accumulate(v.begin(),v.end(),0.0)/v.size();
 41}
 42
 43std::vector<Real> half(const std::vector<Real>& v) {
 44    std::vector<Real> w(v);
 45    for (std::vector<Real>::size_type i=0; i<w.size(); i++)
 46        w[i] /= 2.0;
 47    return w;
 48}
 49
 50void halve_in_place(std::vector<double>& v) {
 51    std::transform(v.begin(),v.end(),v.begin(),
 52                   std::bind2nd(std::divides<double>(),2.0));
 53}
 54
 55struct Struct {
 56  double num;
 57  Struct() : num(0.0) {}
 58  Struct(double d) : num(d) {}
 59};
 60
 61struct Structure {
 62  double num;
 63  Structure() : num(0.0) {}
 64  Structure(double d) : num(d) {}
 65};
 66
 67const std::vector<Real> & vecreal(const std::vector<Real> & vec) { return vec; }
 68
 69const std::vector<int> & vecintptr(const std::vector<int> & vec) { return vec; }
 70const std::vector<int *> & vecintptr(const std::vector<int *> & vec) { return vec; }
 71const std::vector<const int *> & vecintconstptr(const std::vector<const int *> & vec) { return vec; }
 72
 73const std::vector<Struct> & vecstruct(const std::vector<Struct> & vec) { return vec; }
 74const std::vector<Struct *> & vecstructptr(const std::vector<Struct *> & vec) { return vec; }
 75const std::vector<const Struct *> & vecstructconstptr(const std::vector<const Struct *> & vec) { return vec; }
 76%}
 77
 78#if !defined(SWIGR)
 79%template(IntPtrVector) std::vector<int *>;
 80%template(IntConstPtrVector) std::vector<const int *>;
 81#endif
 82%template(StructVector) std::vector<Struct>;
 83%template(StructPtrVector) std::vector<Struct *>;
 84%template(StructConstPtrVector) std::vector<const Struct *>;
 85
 86%inline {
 87  struct MyClass {};
 88  typedef MyClass *MyClassPtr;
 89  typedef std::vector<MyClassPtr> MyClassVector;
 90}
 91%template(MyClassPtrVector) std::vector<MyClassPtr>;
 92
 93%inline {
 94  class RetsMetadata
 95  {
 96  public:
 97    MyClassVector GetAllResources(size_t n) const
 98    {
 99      return MyClassVector(n, 0);
100    }
101  };
102}
103
104#if defined(SWIGRUBY)
105%template(LanguageVector) std::vector< swig::LANGUAGE_OBJ >;
106
107%inline {
108  std::vector< swig::LANGUAGE_OBJ > LanguageVector; 
109}
110#endif