Added initial support for hash tables unordered_ types.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11418 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
048fa12533
commit
523817e4ee
11 changed files with 851 additions and 13 deletions
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// std::map
|
||||
// std::multimap
|
||||
//
|
||||
|
||||
%include <std_map.i>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// std::set
|
||||
// std::multiset
|
||||
//
|
||||
|
||||
%include <std_set.i>
|
||||
|
|
|
|||
124
Lib/std/std_unordered_map.i
Normal file
124
Lib/std/std_unordered_map.i
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
//
|
||||
// std::unordered_map
|
||||
//
|
||||
|
||||
%include <std_pair.i>
|
||||
%include <std_container.i>
|
||||
|
||||
%define %std_unordered_map_methods_common(unordered_map...)
|
||||
%std_container_methods(unordered_map);
|
||||
|
||||
size_type erase(const key_type& x);
|
||||
size_type count(const key_type& x) const;
|
||||
|
||||
#ifdef SWIG_EXPORT_ITERATOR_METHODS
|
||||
// iterator insert(iterator position, const value_type& x);
|
||||
void erase(iterator position);
|
||||
void erase(iterator first, iterator last);
|
||||
|
||||
iterator find(const key_type& x);
|
||||
iterator lower_bound(const key_type& x);
|
||||
iterator upper_bound(const key_type& x);
|
||||
#endif
|
||||
%enddef
|
||||
|
||||
%define %std_unordered_map_methods(unordered_map...)
|
||||
%std_unordered_map_methods_common(unordered_map);
|
||||
|
||||
#ifdef SWIG_EXPORT_ITERATOR_METHODS
|
||||
// iterator insert(const value_type& x);
|
||||
#endif
|
||||
%enddef
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// std::unordered_map
|
||||
//
|
||||
// const declarations are used to guess the intent of the function being
|
||||
// exported; therefore, the following rationale is applied:
|
||||
//
|
||||
// -- f(std::unordered_map<T>), f(const std::unordered_map<T>&):
|
||||
// the parameter being read-only, either a sequence or a
|
||||
// previously wrapped std::unordered_map<T> can be passed.
|
||||
// -- f(std::unordered_map<T>&), f(std::unordered_map<T>*):
|
||||
// the parameter may be modified; therefore, only a wrapped std::unordered_map
|
||||
// can be passed.
|
||||
// -- std::unordered_map<T> f(), const std::unordered_map<T>& f():
|
||||
// the unordered_map is returned by copy; therefore, a sequence of T:s
|
||||
// is returned which is most easily used in other functions
|
||||
// -- std::unordered_map<T>& f(), std::unordered_map<T>* f():
|
||||
// the unordered_map is returned by reference; therefore, a wrapped std::unordered_map
|
||||
// is returned
|
||||
// -- const std::unordered_map<T>* f(), f(const std::unordered_map<T>*):
|
||||
// for consistency, they expect and return a plain unordered_map pointer.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
%{
|
||||
#include <unordered_map>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
%}
|
||||
|
||||
// exported class
|
||||
|
||||
namespace std {
|
||||
|
||||
template<class _Key, class _Tp, class _Compare = std::less<_Key >,
|
||||
class _Alloc = allocator<std::pair<const _Key, _Tp > > >
|
||||
class unordered_map {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef _Key key_type;
|
||||
typedef _Tp mapped_type;
|
||||
typedef std::pair<const _Key, _Tp> value_type;
|
||||
|
||||
typedef value_type* pointer;
|
||||
typedef const value_type* const_pointer;
|
||||
typedef value_type& reference;
|
||||
typedef const value_type& const_reference;
|
||||
typedef _Alloc allocator_type;
|
||||
|
||||
%traits_swigtype(_Key);
|
||||
%traits_swigtype(_Tp);
|
||||
|
||||
%fragment(SWIG_Traits_frag(std::pair< _Key, _Tp >), "header",
|
||||
fragment=SWIG_Traits_frag(_Key),
|
||||
fragment=SWIG_Traits_frag(_Tp),
|
||||
fragment="StdPairTraits") {
|
||||
namespace swig {
|
||||
template <> struct traits<std::pair< _Key, _Tp > > {
|
||||
typedef pointer_category category;
|
||||
static const char* type_name() {
|
||||
return "std::pair<" #_Key "," #_Tp " >";
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_Traits_frag(std::unordered_map<_Key, _Tp, _Compare, _Alloc >), "header",
|
||||
fragment=SWIG_Traits_frag(std::pair<_Key, _Tp >),
|
||||
fragment="StdMapTraits") {
|
||||
namespace swig {
|
||||
template <> struct traits<std::unordered_map<_Key, _Tp, _Compare, _Alloc > > {
|
||||
typedef pointer_category category;
|
||||
static const char* type_name() {
|
||||
return "std::unordered_map<" #_Key "," #_Tp "," #_Compare "," #_Alloc " >";
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
%typemap_traits_ptr(SWIG_TYPECHECK_MAP, std::unordered_map<_Key, _Tp, _Compare, _Alloc >);
|
||||
|
||||
unordered_map( const _Compare& );
|
||||
|
||||
#ifdef %swig_unordered_map_methods
|
||||
// Add swig/language extra methods
|
||||
%swig_unordered_map_methods(std::unordered_map<_Key, _Tp, _Compare, _Alloc >);
|
||||
#endif
|
||||
|
||||
%std_unordered_map_methods(unordered_map);
|
||||
};
|
||||
|
||||
}
|
||||
87
Lib/std/std_unordered_multimap.i
Normal file
87
Lib/std/std_unordered_multimap.i
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
//
|
||||
// std::unordered_multimap
|
||||
//
|
||||
|
||||
%include <std_unordered_map.i>
|
||||
|
||||
|
||||
%define %std_unordered_multimap_methods(mmap...)
|
||||
%std_map_methods_common(mmap);
|
||||
|
||||
#ifdef SWIG_EXPORT_ITERATOR_METHODS
|
||||
std::pair<iterator,iterator> equal_range(const key_type& x);
|
||||
std::pair<const_iterator,const_iterator> equal_range(const key_type& x) const;
|
||||
#endif
|
||||
%enddef
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// std::unordered_multimap
|
||||
//
|
||||
// const declarations are used to guess the intent of the function being
|
||||
// exported; therefore, the following rationale is applied:
|
||||
//
|
||||
// -- f(std::unordered_multimap<T>), f(const std::unordered_multimap<T>&):
|
||||
// the parameter being read-only, either a sequence or a
|
||||
// previously wrapped std::unordered_multimap<T> can be passed.
|
||||
// -- f(std::unordered_multimap<T>&), f(std::unordered_multimap<T>*):
|
||||
// the parameter may be modified; therefore, only a wrapped std::unordered_multimap
|
||||
// can be passed.
|
||||
// -- std::unordered_multimap<T> f(), const std::unordered_multimap<T>& f():
|
||||
// the map is returned by copy; therefore, a sequence of T:s
|
||||
// is returned which is most easily used in other functions
|
||||
// -- std::unordered_multimap<T>& f(), std::unordered_multimap<T>* f():
|
||||
// the map is returned by reference; therefore, a wrapped std::unordered_multimap
|
||||
// is returned
|
||||
// -- const std::unordered_multimap<T>* f(), f(const std::unordered_multimap<T>*):
|
||||
// for consistency, they expect and return a plain map pointer.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
// exported class
|
||||
|
||||
|
||||
namespace std {
|
||||
template<class _Key, class _Tp, class _Compare = std::less<_Key >,
|
||||
class _Alloc = allocator<std::pair<const _Key, _Tp > > >
|
||||
class unordered_multimap {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef _Key key_type;
|
||||
typedef _Tp mapped_type;
|
||||
typedef std::pair<const _Key, _Tp> value_type;
|
||||
|
||||
typedef value_type* pointer;
|
||||
typedef const value_type* const_pointer;
|
||||
typedef value_type& reference;
|
||||
typedef const value_type& const_reference;
|
||||
typedef _Alloc allocator_type;
|
||||
|
||||
%traits_swigtype(_Key);
|
||||
%traits_swigtype(_Tp);
|
||||
|
||||
%fragment(SWIG_Traits_frag(std::unordered_multimap<_Key, _Tp, _Compare, _Alloc >), "header",
|
||||
fragment=SWIG_Traits_frag(std::pair<_Key, _Tp >),
|
||||
fragment="StdMultimapTraits") {
|
||||
namespace swig {
|
||||
template <> struct traits<std::unordered_multimap<_Key, _Tp, _Compare, _Alloc > > {
|
||||
typedef pointer_category category;
|
||||
static const char* type_name() {
|
||||
return "std::unordered_multimap<" #_Key "," #_Tp "," #_Compare "," #_Alloc " >";
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
%typemap_traits_ptr(SWIG_TYPECHECK_MULTIMAP, std::unordered_multimap<_Key, _Tp, _Compare, _Alloc >);
|
||||
|
||||
unordered_multimap( const _Compare& );
|
||||
|
||||
#ifdef %swig_unordered_multimap_methods
|
||||
// Add swig/language extra methods
|
||||
%swig_unordered_multimap_methods(std::unordered_multimap<_Key, _Tp, _Compare, _Alloc >);
|
||||
#endif
|
||||
|
||||
%std_unordered_multimap_methods(unordered_multimap);
|
||||
};
|
||||
}
|
||||
83
Lib/std/std_unordered_multiset.i
Normal file
83
Lib/std/std_unordered_multiset.i
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
//
|
||||
// std::unordered_multiset
|
||||
//
|
||||
|
||||
%include <std_unordered_set.i>
|
||||
|
||||
// Unordered Multiset
|
||||
|
||||
%define %std_unordered_multiset_methods(unordered_multiset...)
|
||||
%std_unordered_set_methods_common(unordered_multiset);
|
||||
%enddef
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// std::unordered_multiset
|
||||
//
|
||||
// const declarations are used to guess the intent of the function being
|
||||
// exported; therefore, the following rationale is applied:
|
||||
//
|
||||
// -- f(std::unordered_multiset<T>), f(const std::unordered_multiset<T>&):
|
||||
// the parameter being read-only, either a sequence or a
|
||||
// previously wrapped std::unordered_multiset<T> can be passed.
|
||||
// -- f(std::unordered_multiset<T>&), f(std::unordered_multiset<T>*):
|
||||
// the parameter may be modified; therefore, only a wrapped std::unordered_multiset
|
||||
// can be passed.
|
||||
// -- std::unordered_multiset<T> f(), const std::unordered_multiset<T>& f():
|
||||
// the set is returned by copy; therefore, a sequence of T:s
|
||||
// is returned which is most easily used in other functions
|
||||
// -- std::unordered_multiset<T>& f(), std::unordered_multiset<T>* f():
|
||||
// the set is returned by reference; therefore, a wrapped std::unordered_multiset
|
||||
// is returned
|
||||
// -- const std::unordered_multiset<T>* f(), f(const std::unordered_multiset<T>*):
|
||||
// for consistency, they expect and return a plain set pointer.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
// exported classes
|
||||
|
||||
namespace std {
|
||||
|
||||
//unordered_multiset
|
||||
|
||||
template <class _Key, class _Compare = std::less<_Key>,
|
||||
class _Alloc = allocator<_Key> >
|
||||
class unordered_multiset {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef _Key value_type;
|
||||
typedef _Key key_type;
|
||||
typedef value_type* pointer;
|
||||
typedef const value_type* const_pointer;
|
||||
typedef value_type& reference;
|
||||
typedef const value_type& const_reference;
|
||||
typedef _Alloc allocator_type;
|
||||
|
||||
%traits_swigtype(_Key);
|
||||
|
||||
%fragment(SWIG_Traits_frag(std::unordered_multiset<_Key, _Compare, _Alloc >), "header",
|
||||
fragment=SWIG_Traits_frag(_Key),
|
||||
fragment="StdMultisetTraits") {
|
||||
namespace swig {
|
||||
template <> struct traits<std::unordered_multiset<_Key, _Compare, _Alloc > > {
|
||||
typedef pointer_category category;
|
||||
static const char* type_name() {
|
||||
return "std::unordered_multiset<" #_Key "," #_Compare "," #_Alloc " >";
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
%typemap_traits_ptr(SWIG_TYPECHECK_MULTISET, std::unordered_multiset<_Key, _Compare, _Alloc >);
|
||||
|
||||
unordered_multiset( const _Compare& );
|
||||
|
||||
#ifdef %swig_unordered_multiset_methods
|
||||
// Add swig/language extra methods
|
||||
%swig_unordered_multiset_methods(std::unordered_multiset<_Key, _Compare, _Alloc >);
|
||||
#endif
|
||||
|
||||
%std_unordered_multiset_methods(unordered_multiset);
|
||||
};
|
||||
}
|
||||
116
Lib/std/std_unordered_set.i
Normal file
116
Lib/std/std_unordered_set.i
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
//
|
||||
// std::unordered_set
|
||||
//
|
||||
|
||||
%include <std_container.i>
|
||||
%include <std_pair.i>
|
||||
|
||||
// Unordered Set
|
||||
%define %std_unordered_set_methods_common(unordered_set...)
|
||||
unordered_set();
|
||||
unordered_set( const unordered_set& );
|
||||
|
||||
bool empty() const;
|
||||
size_type size() const;
|
||||
void clear();
|
||||
|
||||
void swap(unordered_set& v);
|
||||
|
||||
|
||||
size_type erase(const key_type& x);
|
||||
size_type count(const key_type& x) const;
|
||||
|
||||
#ifdef SWIG_EXPORT_ITERATOR_METHODS
|
||||
class iterator;
|
||||
|
||||
iterator begin();
|
||||
iterator end();
|
||||
|
||||
void erase(iterator pos);
|
||||
void erase(iterator first, iterator last);
|
||||
|
||||
iterator find(const key_type& x);
|
||||
std::pair<iterator,iterator> equal_range(const key_type& x);
|
||||
#endif
|
||||
%enddef
|
||||
|
||||
%define %std_unordered_set_methods(unordered_set...)
|
||||
%std_unordered_set_methods_common(unordered_set);
|
||||
#ifdef SWIG_EXPORT_ITERATOR_METHODS
|
||||
std::pair<iterator,bool> insert(const value_type& __x);
|
||||
#endif
|
||||
%enddef
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// std::unordered_set
|
||||
//
|
||||
// const declarations are used to guess the intent of the function being
|
||||
// exported; therefore, the following rationale is applied:
|
||||
//
|
||||
// -- f(std::unordered_set<T>), f(const std::unordered_set<T>&):
|
||||
// the parameter being read-only, either a sequence or a
|
||||
// previously wrapped std::unordered_set<T> can be passed.
|
||||
// -- f(std::unordered_set<T>&), f(std::unordered_set<T>*):
|
||||
// the parameter may be modified; therefore, only a wrapped std::unordered_set
|
||||
// can be passed.
|
||||
// -- std::unordered_set<T> f(), const std::unordered_set<T>& f():
|
||||
// the unordered_set is returned by copy; therefore, a sequence of T:s
|
||||
// is returned which is most easily used in other functions
|
||||
// -- std::unordered_set<T>& f(), std::unordered_set<T>* f():
|
||||
// the unordered_set is returned by reference; therefore, a wrapped std::unordered_set
|
||||
// is returned
|
||||
// -- const std::unordered_set<T>* f(), f(const std::unordered_set<T>*):
|
||||
// for consistency, they expect and return a plain unordered_set pointer.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
%{
|
||||
#include <unordered_set>
|
||||
%}
|
||||
|
||||
// exported classes
|
||||
|
||||
namespace std {
|
||||
|
||||
template <class _Key, class _Hash = std::hash<_Key>,
|
||||
class _Compare = std::equal_to<_Key>,
|
||||
class _Alloc = allocator<_Key> >
|
||||
class unordered_set {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef _Hash hasher;
|
||||
typedef _Key value_type;
|
||||
typedef _Key key_type;
|
||||
typedef value_type* pointer;
|
||||
typedef const value_type* const_pointer;
|
||||
typedef value_type& reference;
|
||||
typedef const value_type& const_reference;
|
||||
typedef _Alloc allocator_type;
|
||||
|
||||
%traits_swigtype(_Key);
|
||||
|
||||
%fragment(SWIG_Traits_frag(std::unordered_set<_Key, _Hash, _Compare, _Alloc >), "header",
|
||||
fragment=SWIG_Traits_frag(_Key),
|
||||
fragment="StdUnorderedSetTraits") {
|
||||
namespace swig {
|
||||
template <> struct traits<std::unordered_set<_Key, _Hash, _Compare, _Alloc > > {
|
||||
typedef pointer_category category;
|
||||
static const char* type_name() {
|
||||
return "std::unordered_set<" #_Key "," #_Hash "," #_Compare "," #_Alloc " >";
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
%typemap_traits_ptr(SWIG_TYPECHECK_SET, std::unordered_set<_Key, _Hash, _Compare, _Alloc >);
|
||||
|
||||
unordered_set( const _Compare& );
|
||||
|
||||
#ifdef %swig_unordered_set_methods
|
||||
// Add swig/language extra methods
|
||||
%swig_unordered_set_methods(std::unordered_set<_Key, _Hash, _Compare, _Alloc >);
|
||||
#endif
|
||||
|
||||
%std_unordered_set_methods(unordered_set);
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue