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