Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
4.9 KiB

  1. //
  2. // std::vector
  3. //
  4. %include <std_container.i>
  5. // Vector
  6. %define %std_vector_methods(vector...)
  7. %std_sequence_methods(vector)
  8. void reserve(size_type n);
  9. size_type capacity() const;
  10. %enddef
  11. %define %std_vector_methods_val(vector...)
  12. %std_sequence_methods_val(vector)
  13. void reserve(size_type n);
  14. size_type capacity() const;
  15. %enddef
  16. // ------------------------------------------------------------------------
  17. // std::vector
  18. //
  19. // The aim of all that follows would be to integrate std::vector with
  20. // as much as possible, namely, to allow the user to pass and
  21. // be returned tuples or lists.
  22. // const declarations are used to guess the intent of the function being
  23. // exported; therefore, the following rationale is applied:
  24. //
  25. // -- f(std::vector<T>), f(const std::vector<T>&):
  26. // the parameter being read-only, either a sequence or a
  27. // previously wrapped std::vector<T> can be passed.
  28. // -- f(std::vector<T>&), f(std::vector<T>*):
  29. // the parameter may be modified; therefore, only a wrapped std::vector
  30. // can be passed.
  31. // -- std::vector<T> f(), const std::vector<T>& f():
  32. // the vector is returned by copy; therefore, a sequence of T:s
  33. // is returned which is most easily used in other functions
  34. // -- std::vector<T>& f(), std::vector<T>* f():
  35. // the vector is returned by reference; therefore, a wrapped std::vector
  36. // is returned
  37. // -- const std::vector<T>* f(), f(const std::vector<T>*):
  38. // for consistency, they expect and return a plain vector pointer.
  39. // ------------------------------------------------------------------------
  40. %{
  41. #include <vector>
  42. %}
  43. // exported classes
  44. namespace std {
  45. template<class _Tp, class _Alloc = allocator< _Tp > >
  46. class vector {
  47. public:
  48. typedef size_t size_type;
  49. typedef ptrdiff_t difference_type;
  50. typedef _Tp value_type;
  51. typedef value_type* pointer;
  52. typedef const value_type* const_pointer;
  53. typedef _Tp& reference;
  54. typedef const _Tp& const_reference;
  55. typedef _Alloc allocator_type;
  56. %traits_swigtype(_Tp);
  57. %fragment(SWIG_Traits_frag(std::vector<_Tp, _Alloc >), "header",
  58. fragment=SWIG_Traits_frag(_Tp),
  59. fragment="StdVectorTraits") {
  60. namespace swig {
  61. template <> struct traits<std::vector<_Tp, _Alloc > > {
  62. typedef pointer_category category;
  63. static const char* type_name() {
  64. return "std::vector<" #_Tp "," #_Alloc " >";
  65. }
  66. };
  67. }
  68. }
  69. %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<_Tp, _Alloc >);
  70. #ifdef %swig_vector_methods
  71. // Add swig/language extra methods
  72. %swig_vector_methods(std::vector<_Tp, _Alloc >);
  73. #endif
  74. %std_vector_methods(vector);
  75. };
  76. // ***
  77. // This specialization should dissapear or get simplified when
  78. // a 'const SWIGTYPE*&' can be defined
  79. // ***
  80. template<class _Tp, class _Alloc >
  81. class vector<_Tp*, _Alloc > {
  82. public:
  83. typedef size_t size_type;
  84. typedef ptrdiff_t difference_type;
  85. typedef _Tp* value_type;
  86. typedef value_type* pointer;
  87. typedef const value_type* const_pointer;
  88. typedef value_type reference;
  89. typedef value_type const_reference;
  90. typedef _Alloc allocator_type;
  91. %traits_swigtype(_Tp);
  92. %fragment(SWIG_Traits_frag(std::vector<_Tp*, _Alloc >), "header",
  93. fragment=SWIG_Traits_frag(_Tp),
  94. fragment="StdVectorTraits") {
  95. namespace swig {
  96. template <> struct traits<std::vector<_Tp*, _Alloc > > {
  97. typedef value_category category;
  98. static const char* type_name() {
  99. return "std::vector<" #_Tp " *," #_Alloc " >";
  100. }
  101. };
  102. }
  103. }
  104. %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<_Tp*, _Alloc >);
  105. #ifdef %swig_vector_methods_val
  106. // Add swig/language extra methods
  107. %swig_vector_methods_val(std::vector<_Tp*, _Alloc >);
  108. #endif
  109. %std_vector_methods_val(vector);
  110. };
  111. // ***
  112. // ***
  113. // bool specialization
  114. template<class _Alloc >
  115. class vector<bool,_Alloc > {
  116. public:
  117. typedef size_t size_type;
  118. typedef ptrdiff_t difference_type;
  119. typedef bool value_type;
  120. typedef value_type* pointer;
  121. typedef const value_type* const_pointer;
  122. typedef value_type reference;
  123. typedef value_type const_reference;
  124. typedef _Alloc allocator_type;
  125. %traits_swigtype(bool);
  126. %fragment(SWIG_Traits_frag(std::vector<bool, _Alloc >), "header",
  127. fragment=SWIG_Traits_frag(bool),
  128. fragment="StdVectorTraits") {
  129. namespace swig {
  130. template <> struct traits<std::vector<bool, _Alloc > > {
  131. typedef value_category category;
  132. static const char* type_name() {
  133. return "std::vector<bool, _Alloc >";
  134. }
  135. };
  136. }
  137. }
  138. %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<bool, _Alloc >);
  139. #ifdef %swig_vector_methods_val
  140. // Add swig/language extra methods
  141. %swig_vector_methods_val(std::vector<bool, _Alloc >);
  142. #endif
  143. %std_vector_methods_val(vector);
  144. #if defined(SWIG_STD_MODERN_STL) && !defined(SWIG_STD_NOMODERN_STL)
  145. void flip();
  146. #endif
  147. };
  148. }