Home | History | Annotate | Download | only in std
      1 //
      2 // std::map
      3 //
      4 
      5 %include <std_pair.i>
      6 %include <std_container.i>
      7 
      8 %define %std_map_methods_common(map...)
      9   %std_container_methods(map);
     10 
     11   size_type erase(const key_type& x);
     12   size_type count(const key_type& x) const;
     13 
     14 #ifdef SWIG_EXPORT_ITERATOR_METHODS
     15 //  iterator insert(iterator position, const value_type& x);
     16   void erase(iterator position);
     17   void erase(iterator first, iterator last);
     18 
     19   iterator find(const key_type& x);
     20   iterator lower_bound(const key_type& x);
     21   iterator upper_bound(const key_type& x);
     22 #endif
     23 %enddef
     24 
     25 %define %std_map_methods(map...)
     26   %std_map_methods_common(map);
     27 
     28   #ifdef SWIG_EXPORT_ITERATOR_METHODS
     29 //  iterator insert(const value_type& x);
     30   #endif
     31 %enddef
     32 
     33 
     34 // ------------------------------------------------------------------------
     35 // std::map
     36 //
     37 // const declarations are used to guess the intent of the function being
     38 // exported; therefore, the following rationale is applied:
     39 //
     40 //   -- f(std::map<T>), f(const std::map<T>&):
     41 //      the parameter being read-only, either a sequence or a
     42 //      previously wrapped std::map<T> can be passed.
     43 //   -- f(std::map<T>&), f(std::map<T>*):
     44 //      the parameter may be modified; therefore, only a wrapped std::map
     45 //      can be passed.
     46 //   -- std::map<T> f(), const std::map<T>& f():
     47 //      the map is returned by copy; therefore, a sequence of T:s
     48 //      is returned which is most easily used in other functions
     49 //   -- std::map<T>& f(), std::map<T>* f():
     50 //      the map is returned by reference; therefore, a wrapped std::map
     51 //      is returned
     52 //   -- const std::map<T>* f(), f(const std::map<T>*):
     53 //      for consistency, they expect and return a plain map pointer.
     54 // ------------------------------------------------------------------------
     55 
     56 %{
     57 #include <map>
     58 #include <algorithm>
     59 #include <stdexcept>
     60 %}
     61 
     62 // exported class
     63 
     64 namespace std {
     65 
     66   template<class _Key, class _Tp, class _Compare = std::less<_Key >,
     67 	   class _Alloc = allocator<std::pair<const _Key, _Tp > > >
     68   class map {
     69   public:
     70     typedef size_t size_type;
     71     typedef ptrdiff_t difference_type;
     72     typedef _Key key_type;
     73     typedef _Tp mapped_type;
     74     typedef std::pair<const _Key, _Tp> value_type;
     75 
     76     typedef value_type* pointer;
     77     typedef const value_type* const_pointer;
     78     typedef value_type& reference;
     79     typedef const value_type& const_reference;
     80     typedef _Alloc allocator_type;
     81 
     82     %traits_swigtype(_Key);
     83     %traits_swigtype(_Tp);
     84 
     85     %fragment(SWIG_Traits_frag(std::pair< _Key, _Tp >), "header",
     86 	      fragment=SWIG_Traits_frag(_Key),
     87 	      fragment=SWIG_Traits_frag(_Tp),
     88 	      fragment="StdPairTraits") {
     89       namespace swig {
     90 	template <>  struct traits<std::pair< _Key, _Tp > > {
     91 	  typedef pointer_category category;
     92 	  static const char* type_name() {
     93 	    return "std::pair<" #_Key "," #_Tp " >";
     94 	  }
     95 	};
     96       }
     97     }
     98 
     99     %fragment(SWIG_Traits_frag(std::map<_Key, _Tp, _Compare, _Alloc >), "header",
    100 	      fragment=SWIG_Traits_frag(std::pair<_Key, _Tp >),
    101 	      fragment="StdMapTraits") {
    102       namespace swig {
    103 	template <>  struct traits<std::map<_Key, _Tp, _Compare, _Alloc > > {
    104 	  typedef pointer_category category;
    105 	  static const char* type_name() {
    106 	    return "std::map<" #_Key "," #_Tp "," #_Compare "," #_Alloc " >";
    107 	  }
    108 	};
    109       }
    110     }
    111 
    112     %typemap_traits_ptr(SWIG_TYPECHECK_MAP, std::map<_Key, _Tp, _Compare, _Alloc >);
    113 
    114     map( const _Compare& );
    115 
    116 #ifdef %swig_map_methods
    117     // Add swig/language extra methods
    118     %swig_map_methods(std::map<_Key, _Tp, _Compare, _Alloc >);
    119 #endif
    120 
    121     %std_map_methods(map);
    122   };
    123 
    124 }
    125