PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/std/std_list.i

#
Swig | 148 lines | 118 code | 30 blank | 0 comment | 0 complexity | 6cbc61ecfdacae2bef96c1af11b6debb MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. //
  2. // std::list
  3. //
  4. %include <std_container.i>
  5. // List
  6. %define %std_list_methods(list)
  7. %std_sequence_methods(list)
  8. void pop_front();
  9. void push_front(const value_type& x);
  10. void reverse();
  11. %enddef
  12. %define %std_list_methods_val(list)
  13. %std_sequence_methods_val(list)
  14. void pop_front();
  15. void push_front(value_type x);
  16. void remove(value_type x);
  17. void unique();
  18. void reverse();
  19. void sort();
  20. void merge(list& x);
  21. %enddef
  22. // ------------------------------------------------------------------------
  23. // std::list
  24. //
  25. // const declarations are used to guess the intent of the function being
  26. // exported; therefore, the following rationale is applied:
  27. //
  28. // -- f(std::list<T>), f(const std::list<T>&):
  29. // the parameter being read-only, either a sequence or a
  30. // previously wrapped std::list<T> can be passed.
  31. // -- f(std::list<T>&), f(std::list<T>*):
  32. // the parameter may be modified; therefore, only a wrapped std::list
  33. // can be passed.
  34. // -- std::list<T> f(), const std::list<T>& f():
  35. // the list is returned by copy; therefore, a sequence of T:s
  36. // is returned which is most easily used in other functions
  37. // -- std::list<T>& f(), std::list<T>* f():
  38. // the list is returned by reference; therefore, a wrapped std::list
  39. // is returned
  40. // -- const std::list<T>* f(), f(const std::list<T>*):
  41. // for consistency, they expect and return a plain list pointer.
  42. // ------------------------------------------------------------------------
  43. %{
  44. #include <list>
  45. %}
  46. // exported classes
  47. namespace std {
  48. template<class _Tp, class _Alloc = allocator<_Tp> >
  49. class list {
  50. public:
  51. typedef size_t size_type;
  52. typedef ptrdiff_t difference_type;
  53. typedef _Tp value_type;
  54. typedef value_type* pointer;
  55. typedef const value_type* const_pointer;
  56. typedef value_type& reference;
  57. typedef const value_type& const_reference;
  58. typedef _Alloc allocator_type;
  59. %traits_swigtype(_Tp);
  60. %fragment(SWIG_Traits_frag(std::list<_Tp, _Alloc >), "header",
  61. fragment=SWIG_Traits_frag(_Tp),
  62. fragment="StdListTraits") {
  63. namespace swig {
  64. template <> struct traits<std::list<_Tp, _Alloc > > {
  65. typedef pointer_category category;
  66. static const char* type_name() {
  67. return "std::list<" #_Tp ", " #_Alloc " >";
  68. }
  69. };
  70. }
  71. }
  72. %typemap_traits_ptr(SWIG_TYPECHECK_LIST, std::list<_Tp, _Alloc >);
  73. #ifdef %swig_list_methods
  74. // Add swig/language extra methods
  75. %swig_list_methods(std::list<_Tp, _Alloc >);
  76. #endif
  77. %std_list_methods(list);
  78. };
  79. template<class _Tp, class _Alloc >
  80. class list<_Tp*, _Alloc> {
  81. public:
  82. typedef size_t size_type;
  83. typedef ptrdiff_t difference_type;
  84. typedef _Tp* value_type;
  85. typedef value_type* pointer;
  86. typedef const value_type* const_pointer;
  87. typedef value_type reference;
  88. typedef value_type const_reference;
  89. typedef _Alloc allocator_type;
  90. %traits_swigtype(_Tp);
  91. %fragment(SWIG_Traits_frag(std::list<_Tp*, _Alloc >), "header",
  92. fragment=SWIG_Traits_frag(_Tp),
  93. fragment="StdListTraits") {
  94. namespace swig {
  95. template <> struct traits<std::list<_Tp*, _Alloc > > {
  96. typedef value_category category;
  97. static const char* type_name() {
  98. return "std::list<" #_Tp " *," #_Alloc " >";
  99. }
  100. };
  101. }
  102. }
  103. %typemap_traits_ptr(SWIG_TYPECHECK_LIST, std::list<_Tp*, _Alloc >);
  104. #ifdef %swig_list_methods_val
  105. // Add swig/language extra methods
  106. %swig_list_methods_val(std::list<_Tp*, _Alloc >);
  107. #endif
  108. %std_list_methods_val(list);
  109. };
  110. }
  111. %define %std_extequal_list(...)
  112. %extend std::list<__VA_ARGS__ > {
  113. void remove(const value_type& x) { self->remove(x); }
  114. void merge(std::list<__VA_ARGS__ >& x){ self->merge(x); }
  115. void unique() { self->unique(); }
  116. void sort() { self->sort(); }
  117. }
  118. %enddef