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.

128 lines
3.4 KiB

  1. /**
  2. * @file std_stack.i
  3. * @date Sun May 6 01:48:07 2007
  4. *
  5. * @brief A wrapping of std::stack for Ruby.
  6. *
  7. *
  8. */
  9. %include <std_container.i>
  10. // Stack
  11. %define %std_stack_methods(stack...)
  12. stack();
  13. stack( const _Sequence& );
  14. bool empty() const;
  15. size_type size() const;
  16. const value_type& top() const;
  17. void pop();
  18. void push( const value_type& );
  19. %enddef
  20. %define %std_stack_methods_val(stack...)
  21. %std_stack_methods(stack)
  22. %enddef
  23. // ------------------------------------------------------------------------
  24. // std::stack
  25. //
  26. // const declarations are used to guess the intent of the function being
  27. // exported; therefore, the following rationale is applied:
  28. //
  29. // -- f(std::stack<T>), f(const std::stack<T>&):
  30. // the parameter being read-only, either a sequence or a
  31. // previously wrapped std::stack<T> can be passed.
  32. // -- f(std::stack<T>&), f(std::stack<T>*):
  33. // the parameter may be modified; therefore, only a wrapped std::stack
  34. // can be passed.
  35. // -- std::stack<T> f(), const std::stack<T>& f():
  36. // the stack is returned by copy; therefore, a sequence of T:s
  37. // is returned which is most easily used in other functions
  38. // -- std::stack<T>& f(), std::stack<T>* f():
  39. // the stack is returned by reference; therefore, a wrapped std::stack
  40. // is returned
  41. // -- const std::stack<T>* f(), f(const std::stack<T>*):
  42. // for consistency, they expect and return a plain stack pointer.
  43. // ------------------------------------------------------------------------
  44. %{
  45. #include <stack>
  46. %}
  47. // exported classes
  48. namespace std {
  49. template<class _Tp, class _Sequence = std::deque<_Tp> >
  50. class stack {
  51. public:
  52. typedef size_t size_type;
  53. typedef _Tp value_type;
  54. typedef value_type& reference;
  55. typedef const value_type& const_reference;
  56. typedef _Sequence container_type;
  57. %traits_swigtype(_Tp);
  58. %fragment(SWIG_Traits_frag(std::stack<_Tp, _Sequence >), "header",
  59. fragment=SWIG_Traits_frag(_Tp),
  60. fragment="StdStackTraits") {
  61. namespace swig {
  62. template <> struct traits<std::stack<_Tp, _Sequence > > {
  63. typedef pointer_category category;
  64. static const char* type_name() {
  65. return "std::stack<" #_Tp "," #_Sequence " >";
  66. }
  67. };
  68. }
  69. }
  70. %typemap_traits_ptr(SWIG_TYPECHECK_STACK, std::stack<_Tp, _Sequence >);
  71. #ifdef %swig_stack_methods
  72. // Add swig/language extra methods
  73. %swig_stack_methods(std::stack<_Tp, _Sequence >);
  74. #endif
  75. %std_stack_methods(stack);
  76. };
  77. template<class _Tp, class _Sequence >
  78. class stack<_Tp*, _Sequence > {
  79. public:
  80. typedef size_t size_type;
  81. typedef _Sequence::value_type value_type;
  82. typedef value_type reference;
  83. typedef value_type const_reference;
  84. typedef _Sequence container_type;
  85. %traits_swigtype(_Tp);
  86. %fragment(SWIG_Traits_frag(std::stack<_Tp*, _Sequence >), "header",
  87. fragment=SWIG_Traits_frag(_Tp),
  88. fragment="StdStackTraits") {
  89. namespace swig {
  90. template <> struct traits<std::stack<_Tp*, _Sequence > > {
  91. typedef value_category category;
  92. static const char* type_name() {
  93. return "std::stack<" #_Tp "," #_Sequence " * >";
  94. }
  95. };
  96. }
  97. }
  98. %typemap_traits_ptr(SWIG_TYPECHECK_STACK, std::stack<_Tp*, _Sequence >);
  99. #ifdef %swig_stack_methods_val
  100. // Add swig/language extra methods
  101. %swig_stack_methods_val(std::stack<_Tp*, _Sequence >);
  102. #endif
  103. %std_stack_methods_val(std::stack<_Tp*, _Sequence >);
  104. };
  105. }