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