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.

244 lines
4.9 KiB

  1. %include <std/std_except.i>
  2. //
  3. // Use the following macro with modern STL implementations
  4. //
  5. //#define SWIG_STD_MODERN_STL
  6. //
  7. // Use this to deactive the previous definition, when using gcc-2.95
  8. // or similar old compilers.
  9. //
  10. //#define SWIG_STD_NOMODERN_STL
  11. // Here, we identify compilers we now have problems with STL.
  12. %{
  13. #if defined(__SUNPRO_CC) && defined(_RWSTD_VER)
  14. # define SWIG_STD_NOASSIGN_STL
  15. # define SWIG_STD_NOINSERT_TEMPLATE_STL
  16. # define SWIG_STD_NOITERATOR_TRAITS_STL
  17. #endif
  18. #if defined(__GNUC__)
  19. # if __GNUC__ == 2 && __GNUC_MINOR <= 96
  20. # define SWIG_STD_NOMODERN_STL
  21. # endif
  22. #endif
  23. %}
  24. //
  25. // Common code for supporting the STD C++ namespace
  26. //
  27. %{
  28. #include <string>
  29. #include <stdexcept>
  30. %}
  31. %fragment("StdIteratorTraits","header") %{
  32. #if !defined(SWIG_STD_NOITERATOR_TRAITS_STL)
  33. #include <iterator>
  34. #else
  35. namespace std {
  36. template <class Iterator>
  37. struct iterator_traits {
  38. typedef ptrdiff_t difference_type;
  39. typedef typename Iterator::value_type value_type;
  40. };
  41. #if defined(__SUNPRO_CC) && defined(_RWSTD_VER)
  42. template <class Iterator, class Category,class T, class Reference, class Pointer, class Distance>
  43. struct iterator_traits<__reverse_bi_iterator<Iterator,Category,T,Reference,Pointer,Distance> > {
  44. typedef Distance difference_type;
  45. typedef T value_type;
  46. };
  47. #endif
  48. template <class T>
  49. struct iterator_traits<T*> {
  50. typedef T value_type;
  51. typedef ptrdiff_t difference_type;
  52. };
  53. template<typename _InputIterator>
  54. inline typename iterator_traits<_InputIterator>::difference_type
  55. distance(_InputIterator __first, _InputIterator __last)
  56. {
  57. typename iterator_traits<_InputIterator>::difference_type __n = 0;
  58. while (__first != __last) {
  59. ++__first; ++__n;
  60. }
  61. return __n;
  62. }
  63. }
  64. #endif
  65. %}
  66. %fragment("StdTraitsCommon","header") %{
  67. namespace swig {
  68. template <class Type>
  69. struct noconst_traits {
  70. typedef Type noconst_type;
  71. };
  72. template <class Type>
  73. struct noconst_traits<const Type> {
  74. typedef Type noconst_type;
  75. };
  76. /*
  77. type categories
  78. */
  79. struct pointer_category { };
  80. struct value_category { };
  81. /*
  82. General traits that provides type_name and type_info
  83. */
  84. template <class Type> struct traits { };
  85. template <class Type>
  86. inline const char* type_name() {
  87. return traits<typename noconst_traits<Type >::noconst_type >::type_name();
  88. }
  89. template <class Type>
  90. struct traits_info {
  91. static swig_type_info *type_query(std::string name) {
  92. name += " *";
  93. return SWIG_TypeQuery(name.c_str());
  94. }
  95. static swig_type_info *type_info() {
  96. static swig_type_info *info = type_query(type_name<Type>());
  97. return info;
  98. }
  99. };
  100. template <class Type>
  101. inline swig_type_info *type_info() {
  102. return traits_info<Type>::type_info();
  103. }
  104. /*
  105. Partial specialization for pointers
  106. */
  107. template <class Type> struct traits <Type *> {
  108. typedef pointer_category category;
  109. static std::string make_ptr_name(const char* name) {
  110. std::string ptrname = name;
  111. ptrname += " *";
  112. return ptrname;
  113. }
  114. static const char* type_name() {
  115. static std::string name = make_ptr_name(swig::type_name<Type>());
  116. return name.c_str();
  117. }
  118. };
  119. template <class Type, class Category>
  120. struct traits_as { };
  121. template <class Type, class Category>
  122. struct traits_check { };
  123. }
  124. %}
  125. /*
  126. Generate the traits for a swigtype
  127. */
  128. %define %traits_swigtype(Type...)
  129. %fragment(SWIG_Traits_frag(Type),"header",fragment="StdTraits") {
  130. namespace swig {
  131. template <> struct traits<Type > {
  132. typedef pointer_category category;
  133. static const char* type_name() { return #Type; }
  134. };
  135. }
  136. }
  137. %enddef
  138. /*
  139. Generate the typemaps for a class that has 'value' traits
  140. */
  141. %define %typemap_traits(Code,Type...)
  142. %typemaps_asvalfrom(%arg(Code),
  143. %arg(swig::asval<Type >),
  144. %arg(swig::from),
  145. %arg(SWIG_Traits_frag(Type)),
  146. %arg(SWIG_Traits_frag(Type)),
  147. Type);
  148. %enddef
  149. /*
  150. Generate the typemaps for a class that behaves more like a 'pointer' or
  151. plain wrapped Swigtype.
  152. */
  153. %define %typemap_traits_ptr(Code,Type...)
  154. %typemaps_asptrfrom(%arg(Code),
  155. %arg(swig::asptr),
  156. %arg(swig::from),
  157. %arg(SWIG_Traits_frag(Type)),
  158. %arg(SWIG_Traits_frag(Type)),
  159. Type);
  160. %enddef
  161. /*
  162. Equality methods
  163. */
  164. %define %std_equal_methods(Type...)
  165. %extend Type {
  166. bool operator == (const Type& v) {
  167. return *self == v;
  168. }
  169. bool operator != (const Type& v) {
  170. return *self != v;
  171. }
  172. }
  173. %enddef
  174. /*
  175. Order methods
  176. */
  177. %define %std_order_methods(Type...)
  178. %extend Type {
  179. bool operator > (const Type& v) {
  180. return *self > v;
  181. }
  182. bool operator < (const Type& v) {
  183. return *self < v;
  184. }
  185. bool operator >= (const Type& v) {
  186. return *self >= v;
  187. }
  188. bool operator <= (const Type& v) {
  189. return *self <= v;
  190. }
  191. }
  192. %enddef
  193. /*
  194. Comparison methods
  195. */
  196. %define %std_comp_methods(Type...)
  197. %std_equal_methods(Type )
  198. %std_order_methods(Type )
  199. %enddef