PageRenderTime 36ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Swig | 120 lines | 91 code | 29 blank | 0 comment | 0 complexity | b383e5972ab8d8b8c0bf447b8d248c46 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module("templatereduce") li_std_map
  2. %feature("trackobjects");
  3. %inline %{
  4. namespace another {
  5. struct map {
  6. int val;
  7. map(int x) : val(x) {}
  8. };
  9. }
  10. %}
  11. %include "std_pair.i"
  12. %include "std_map.i"
  13. %include "std_string.i"
  14. // Declare some maps to play around with
  15. %template(IntIntMap) std::map<int, int>;
  16. %template(StringIntMap) std::map<std::string, int>;
  17. %ignore Struct::operator<;
  18. %ignore Struct::operator==;
  19. // Add an inline function to test
  20. %inline %{
  21. double valueAverage(std::map<std::string, int> m) {
  22. if (m.size() == 0) {
  23. return 0.0;
  24. }
  25. double a = 0.0;
  26. for (std::map<std::string, int>::iterator i = m.begin(); i != m.end(); i++) {
  27. a += i->second;
  28. }
  29. return a / m.size();
  30. }
  31. std::string stringifyKeys(std::map<std::string, int> m) {
  32. std::string a;
  33. for (std::map<std::string, int>::iterator i = m.begin(); i != m.end(); i++) {
  34. a += " " + i->first;
  35. }
  36. return a;
  37. }
  38. struct Struct {
  39. double num;
  40. Struct() : num(0.0) {}
  41. Struct(double d) : num(d) {}
  42. bool operator<(const Struct &other) const { return num < other.num; }
  43. bool operator==(const Struct &other) const { return num == other.num; }
  44. };
  45. %}
  46. //#if !defined(SWIGR)
  47. // Test out some maps with pointer types
  48. %template(IntIntPtrMap) std::map<int, int *>;
  49. %template(IntConstIntPtrMap) std::map<int, const int *>;
  50. //#endif
  51. // Test out some maps with non-basic types and non-basic pointer types
  52. %template(IntStructMap) std::map<int, Struct>;
  53. %template(IntStructPtrMap) std::map<int, Struct *>;
  54. %template(IntStructConstPtrMap) std::map<int, const Struct *>;
  55. %template(StructPtrIntMap) std::map<Struct *, int>;
  56. // Test out a non-specialized map
  57. %template(StructIntMap) std::map<Struct, int>;
  58. // Additional map definitions for Ruby, Python and Octave tests
  59. %inline %{
  60. struct A{
  61. int val;
  62. A(int v = 0): val(v) {
  63. }
  64. };
  65. %}
  66. namespace std {
  67. %template(pairii) pair<int, int>;
  68. %template(pairAA) pair<int, A>;
  69. %template(pairA) pair<int, A*>;
  70. %template(mapA) map<int, A*>;
  71. %template(paircA1) pair<const int, A*>;
  72. %template(paircA2) pair<const int, const A*>;
  73. %template(pairiiA) pair<int,pair<int, A*> >;
  74. %template(pairiiAc) pair<int,const pair<int, A*> >;
  75. #ifdef SWIGRUBY
  76. %template() pair< swig::LANGUAGE_OBJ, swig::LANGUAGE_OBJ >;
  77. %template(LanguageMap) map< swig::LANGUAGE_OBJ, swig::LANGUAGE_OBJ >;
  78. #endif
  79. #ifdef SWIGPYTHON
  80. %template() pair<swig::SwigPtr_PyObject, swig::SwigPtr_PyObject>;
  81. %template(pymap) map<swig::SwigPtr_PyObject, swig::SwigPtr_PyObject>;
  82. #endif
  83. }
  84. %inline {
  85. std::pair<int, A*> p_identa(std::pair<int, A*> p) {
  86. return p;
  87. }
  88. std::map<int, A*> m_identa(const std::map<int,A*>& v) {
  89. return v;
  90. }
  91. }