diff --git a/Examples/test-suite/cpp0x_hash_tables.i b/Examples/test-suite/cpp0x_hash_tables.i index 0888590cd..a4829ce1f 100644 --- a/Examples/test-suite/cpp0x_hash_tables.i +++ b/Examples/test-suite/cpp0x_hash_tables.i @@ -2,17 +2,19 @@ %inline %{ #include -#include +//#include #include -#include +//#include %} %include "std_set.i" -%include "std_map.i" +//%include "std_map.i" +%include "std_unordered_set.i" +//%include "std_unordered_map.i" %template (SetInt) std::set; -%template (MapIntInt) std::map; +//%template (MapIntInt) std::map; %template (UnorderedSetInt) std::unordered_set; -%template (UnorderedMapIntInt) std::unordered_map; +//%template (UnorderedMapIntInt) std::unordered_map; %inline %{ using namespace std; @@ -21,19 +23,19 @@ class MyClass { public: set getSet() { return _set; } void addSet(int elt) { _set.insert(_set.begin(), elt); } - map getMap() { return _map; } - void addMap(int elt1, int elt2) { _map.insert(make_pair(elt1, elt2)); } +// map getMap() { return _map; } +// void addMap(int elt1, int elt2) { _map.insert(make_pair(elt1, elt2)); } unordered_set getUnorderedSet() { return _unordered_set; } void addUnorderedSet(int elt) { _unordered_set.insert(_unordered_set.begin(), elt); } - unordered_map getUnorderedMap() { return _unordered_map; } - void addUnorderedMap(int elt1, int elt2) { _unordered_map.insert(make_pair(elt1, elt2)); } +// unordered_map getUnorderedMap() { return _unordered_map; } +// void addUnorderedMap(int elt1, int elt2) { _unordered_map.insert(make_pair(elt1, elt2)); } private: set _set; - map _map; +// map _map; unordered_set _unordered_set; - unordered_map _unordered_map; +// unordered_map _unordered_map; }; %} diff --git a/Lib/python/std_unordered_map.i b/Lib/python/std_unordered_map.i new file mode 100644 index 000000000..b456035e2 --- /dev/null +++ b/Lib/python/std_unordered_map.i @@ -0,0 +1,251 @@ +/* + Unordered Maps +*/ + +%fragment("StdMapTraits","header",fragment="StdSequenceTraits") +{ + namespace swig { + template + inline void + assign(const SwigPySeq& swigpyseq, std::unordered_map *unordered_map) { + typedef typename std::unordered_map::value_type value_type; + typename SwigPySeq::const_iterator it = swigpyseq.begin(); + for (;it != swigpyseq.end(); ++it) { + unordered_map->insert(value_type(it->first, it->second)); + } + } + + template + struct traits_asptr > { + typedef std::unordered_map unordered_map_type; + static int asptr(PyObject *obj, unordered_map_type **val) { + int res = SWIG_ERROR; + if (PyDict_Check(obj)) { + SwigVar_PyObject items = PyObject_CallMethod(obj,(char *)"items",NULL); +%#if PY_VERSION_HEX >= 0x03000000 + /* In Python 3.x the ".items()" method return a dict_items object */ + items = PySequence_Fast(items, ".items() havn't returned a sequence!"); +%#endif + res = traits_asptr_stdseq, std::pair >::asptr(items, val); + } else { + unordered_map_type *p; + res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info(),0); + if (SWIG_IsOK(res) && val) *val = p; + } + return res; + } + }; + + template + struct traits_from > { + typedef std::unordered_map unordered_map_type; + typedef typename unordered_map_type::const_iterator const_iterator; + typedef typename unordered_map_type::size_type size_type; + + static PyObject *from(const unordered_map_type& unordered_map) { + swig_type_info *desc = swig::type_info(); + if (desc && desc->clientdata) { + return SWIG_NewPointerObj(new unordered_map_type(unordered_map), desc, SWIG_POINTER_OWN); + } else { + size_type size = unordered_map.size(); + int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1; + if (pysize < 0) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetString(PyExc_OverflowError, + "unordered_map size not valid in python"); + SWIG_PYTHON_THREAD_END_BLOCK; + return NULL; + } + PyObject *obj = PyDict_New(); + for (const_iterator i= unordered_map.begin(); i!= unordered_map.end(); ++i) { + swig::SwigVar_PyObject key = swig::from(i->first); + swig::SwigVar_PyObject val = swig::from(i->second); + PyDict_SetItem(obj, key, val); + } + return obj; + } + } + }; + + template + struct from_key_oper + { + typedef const ValueType& argument_type; + typedef PyObject *result_type; + result_type operator()(argument_type v) const + { + return swig::from(v.first); + } + }; + + template + struct from_value_oper + { + typedef const ValueType& argument_type; + typedef PyObject *result_type; + result_type operator()(argument_type v) const + { + return swig::from(v.second); + } + }; + + template + struct SwigPyMapIterator_T : SwigPyIteratorClosed_T + { + SwigPyMapIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq) + : SwigPyIteratorClosed_T(curr, first, last, seq) + { + } + }; + + + template > + struct SwigPyMapKeyIterator_T : SwigPyMapIterator_T + { + SwigPyMapKeyIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq) + : SwigPyMapIterator_T(curr, first, last, seq) + { + } + }; + + template + inline SwigPyIterator* + make_output_key_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0) + { + return new SwigPyMapKeyIterator_T(current, begin, end, seq); + } + + template > + struct SwigPyMapValueITerator_T : SwigPyMapIterator_T + { + SwigPyMapValueITerator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq) + : SwigPyMapIterator_T(curr, first, last, seq) + { + } + }; + + + template + inline SwigPyIterator* + make_output_value_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0) + { + return new SwigPyMapValueITerator_T(current, begin, end, seq); + } + } +} + +%define %swig_unordered_map_common(Map...) + %swig_sequence_iterator(Map); + %swig_container_methods(Map) + + %extend { + mapped_type __getitem__(const key_type& key) const throw (std::out_of_range) { + Map::const_iterator i = self->find(key); + if (i != self->end()) + return i->second; + else + throw std::out_of_range("key not found"); + } + + void __delitem__(const key_type& key) throw (std::out_of_range) { + Map::iterator i = self->find(key); + if (i != self->end()) + self->erase(i); + else + throw std::out_of_range("key not found"); + } + + bool has_key(const key_type& key) const { + Map::const_iterator i = self->find(key); + return i != self->end(); + } + + PyObject* keys() { + Map::size_type size = self->size(); + int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1; + if (pysize < 0) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetString(PyExc_OverflowError, + "unordered_map size not valid in python"); + SWIG_PYTHON_THREAD_END_BLOCK; + return NULL; + } + PyObject* keyList = PyList_New(pysize); + Map::const_iterator i = self->begin(); + for (int j = 0; j < pysize; ++i, ++j) { + PyList_SET_ITEM(keyList, j, swig::from(i->first)); + } + return keyList; + } + + PyObject* values() { + Map::size_type size = self->size(); + int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1; + if (pysize < 0) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetString(PyExc_OverflowError, + "unordered_map size not valid in python"); + SWIG_PYTHON_THREAD_END_BLOCK; + return NULL; + } + PyObject* valList = PyList_New(pysize); + Map::const_iterator i = self->begin(); + for (int j = 0; j < pysize; ++i, ++j) { + PyList_SET_ITEM(valList, j, swig::from(i->second)); + } + return valList; + } + + PyObject* items() { + Map::size_type size = self->size(); + int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1; + if (pysize < 0) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetString(PyExc_OverflowError, + "unordered_map size not valid in python"); + SWIG_PYTHON_THREAD_END_BLOCK; + return NULL; + } + PyObject* itemList = PyList_New(pysize); + Map::const_iterator i = self->begin(); + for (int j = 0; j < pysize; ++i, ++j) { + PyList_SET_ITEM(itemList, j, swig::from(*i)); + } + return itemList; + } + + // Python 2.2 methods + bool __contains__(const key_type& key) { + return self->find(key) != self->end(); + } + + %newobject key_iterator(PyObject **PYTHON_SELF); + swig::SwigPyIterator* key_iterator(PyObject **PYTHON_SELF) { + return swig::make_output_key_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF); + } + + %newobject value_iterator(PyObject **PYTHON_SELF); + swig::SwigPyIterator* value_iterator(PyObject **PYTHON_SELF) { + return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF); + } + + %pythoncode {def __iter__(self): return self.key_iterator()} + %pythoncode {def iterkeys(self): return self.key_iterator()} + %pythoncode {def itervalues(self): return self.value_iterator()} + %pythoncode {def iteritems(self): return self.iterator()} + } +%enddef + +%define %swig_unordered_map_methods(Map...) + %swig_unordered_map_common(Map) + %extend { + void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) { + (*self)[key] = x; + } + } +%enddef + + +%include diff --git a/Lib/python/std_unordered_multimap.i b/Lib/python/std_unordered_multimap.i new file mode 100644 index 000000000..adf86f251 --- /dev/null +++ b/Lib/python/std_unordered_multimap.i @@ -0,0 +1,79 @@ +/* + Unordered Multimaps +*/ +%include + +%fragment("StdUnorderedMultimapTraits","header",fragment="StdSequenceTraits") +{ + namespace swig { + template + inline void + assign(const SwigPySeq& swigpyseq, std::unordered_multimap *unordered_multimap) { + typedef typename std::unordered_multimap::value_type value_type; + typename SwigPySeq::const_iterator it = swigpyseq.begin(); + for (;it != swigpyseq.end(); ++it) { + unordered_multimap->insert(value_type(it->first, it->second)); + } + } + + template + struct traits_asptr > { + typedef std::unordered_multimap unordered_multimap_type; + static int asptr(PyObject *obj, std::unordered_multimap **val) { + int res = SWIG_ERROR; + if (PyDict_Check(obj)) { + SwigVar_PyObject items = PyObject_CallMethod(obj,(char *)"items",NULL); + return traits_asptr_stdseq, std::pair >::asptr(items, val); + } else { + unordered_multimap_type *p; + res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info(),0); + if (SWIG_IsOK(res) && val) *val = p; + } + return res; + } + }; + + template + struct traits_from > { + typedef std::unordered_multimap unordered_multimap_type; + typedef typename unordered_multimap_type::const_iterator const_iterator; + typedef typename unordered_multimap_type::size_type size_type; + + static PyObject *from(const unordered_multimap_type& unordered_multimap) { + swig_type_info *desc = swig::type_info(); + if (desc && desc->clientdata) { + return SWIG_NewPointerObj(new unordered_multimap_type(unordered_multimap), desc, SWIG_POINTER_OWN); + } else { + size_type size = unordered_multimap.size(); + int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1; + if (pysize < 0) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetString(PyExc_OverflowError, + "unordered_multimap size not valid in python"); + SWIG_PYTHON_THREAD_END_BLOCK; + return NULL; + } + PyObject *obj = PyDict_New(); + for (const_iterator i= unordered_multimap.begin(); i!= unordered_multimap.end(); ++i) { + swig::SwigVar_PyObject key = swig::from(i->first); + swig::SwigVar_PyObject val = swig::from(i->second); + PyDict_SetItem(obj, key, val); + } + return obj; + } + } + }; + } +} + +%define %swig_unordered_multimap_methods(Type...) + %swig_map_common(Type); + %extend { + void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) { + self->insert(Type::value_type(key,x)); + } + } +%enddef + +%include + diff --git a/Lib/python/std_unordered_multiset.i b/Lib/python/std_unordered_multiset.i new file mode 100644 index 000000000..d5b9ff61c --- /dev/null +++ b/Lib/python/std_unordered_multiset.i @@ -0,0 +1,41 @@ +/* + Unordered Multisets +*/ + +%include + +%fragment("StdUnorderedMultisetTraits","header",fragment="StdSequenceTraits") +%{ + namespace swig { + template + inline void + assign(const SwigPySeq& swigpyseq, std::unordered_multiset* seq) { + // seq->insert(swigpyseq.begin(), swigpyseq.end()); // not used as not always implemented + typedef typename SwigPySeq::value_type value_type; + typename SwigPySeq::const_iterator it = swigpyseq.begin(); + for (;it != swigpyseq.end(); ++it) { + seq->insert(seq->end(),(value_type)(*it)); + } + } + + template + struct traits_asptr > { + static int asptr(PyObject *obj, std::unordered_multiset **m) { + return traits_asptr_stdseq >::asptr(obj, m); + } + }; + + template + struct traits_from > { + static PyObject *from(const std::unordered_multiset& vec) { + return traits_from_stdseq >::from(vec); + } + }; + } +%} + +#define %swig_unordered_multiset_methods(Set...) %swig_set_methods(Set) + + + +%include diff --git a/Lib/python/std_unordered_set.i b/Lib/python/std_unordered_set.i new file mode 100644 index 000000000..a021cb4ed --- /dev/null +++ b/Lib/python/std_unordered_set.i @@ -0,0 +1,55 @@ +/* + Unordered Sets +*/ + +%fragment("StdUnorderedSetTraits","header",fragment="StdSequenceTraits") +%{ + namespace swig { + template + inline void + assign(const SwigPySeq& swigpyseq, std::unordered_set* seq) { + // seq->insert(swigpyseq.begin(), swigpyseq.end()); // not used as not always implemented + typedef typename SwigPySeq::value_type value_type; + typename SwigPySeq::const_iterator it = swigpyseq.begin(); + for (;it != swigpyseq.end(); ++it) { + seq->insert(seq->end(),(value_type)(*it)); + } + } + + template + struct traits_asptr > { + static int asptr(PyObject *obj, std::unordered_set **s) { + return traits_asptr_stdseq >::asptr(obj, s); + } + }; + + template + struct traits_from > { + static PyObject *from(const std::unordered_set& vec) { + return traits_from_stdseq >::from(vec); + } + }; + } +%} + +%define %swig_unordered_set_methods(unordered_set...) + %swig_sequence_iterator(unordered_set); + %swig_container_methods(unordered_set); + + %extend { + void append(value_type x) { + self->insert(x); + } + + bool __contains__(value_type x) { + return self->find(x) != self->end(); + } + + value_type __getitem__(difference_type i) const throw (std::out_of_range) { + return *(swig::cgetpos(self, i)); + } + + }; +%enddef + +%include diff --git a/Lib/std/std_multimap.i b/Lib/std/std_multimap.i index f165e5f33..829d1b9de 100644 --- a/Lib/std/std_multimap.i +++ b/Lib/std/std_multimap.i @@ -1,5 +1,5 @@ // -// std::map +// std::multimap // %include diff --git a/Lib/std/std_multiset.i b/Lib/std/std_multiset.i index 98a7fb9d7..b63fb92b9 100644 --- a/Lib/std/std_multiset.i +++ b/Lib/std/std_multiset.i @@ -1,5 +1,5 @@ // -// std::set +// std::multiset // %include diff --git a/Lib/std/std_unordered_map.i b/Lib/std/std_unordered_map.i new file mode 100644 index 000000000..f205bd573 --- /dev/null +++ b/Lib/std/std_unordered_map.i @@ -0,0 +1,124 @@ +// +// std::unordered_map +// + +%include +%include + +%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), f(const std::unordered_map&): +// the parameter being read-only, either a sequence or a +// previously wrapped std::unordered_map can be passed. +// -- f(std::unordered_map&), f(std::unordered_map*): +// the parameter may be modified; therefore, only a wrapped std::unordered_map +// can be passed. +// -- std::unordered_map f(), const std::unordered_map& 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& f(), std::unordered_map* f(): +// the unordered_map is returned by reference; therefore, a wrapped std::unordered_map +// is returned +// -- const std::unordered_map* f(), f(const std::unordered_map*): +// for consistency, they expect and return a plain unordered_map pointer. +// ------------------------------------------------------------------------ + +%{ +#include +#include +#include +%} + +// exported class + +namespace std { + + template, + class _Alloc = allocator > > + 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 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 > { + 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 > { + 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); + }; + +} diff --git a/Lib/std/std_unordered_multimap.i b/Lib/std/std_unordered_multimap.i new file mode 100644 index 000000000..bbdfeb82d --- /dev/null +++ b/Lib/std/std_unordered_multimap.i @@ -0,0 +1,87 @@ +// +// std::unordered_multimap +// + +%include + + +%define %std_unordered_multimap_methods(mmap...) + %std_map_methods_common(mmap); + +#ifdef SWIG_EXPORT_ITERATOR_METHODS + std::pair equal_range(const key_type& x); + std::pair 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), f(const std::unordered_multimap&): +// the parameter being read-only, either a sequence or a +// previously wrapped std::unordered_multimap can be passed. +// -- f(std::unordered_multimap&), f(std::unordered_multimap*): +// the parameter may be modified; therefore, only a wrapped std::unordered_multimap +// can be passed. +// -- std::unordered_multimap f(), const std::unordered_multimap& 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& f(), std::unordered_multimap* f(): +// the map is returned by reference; therefore, a wrapped std::unordered_multimap +// is returned +// -- const std::unordered_multimap* f(), f(const std::unordered_multimap*): +// for consistency, they expect and return a plain map pointer. +// ------------------------------------------------------------------------ + + +// exported class + + +namespace std { + template, + class _Alloc = allocator > > + 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 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 > { + 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); + }; +} diff --git a/Lib/std/std_unordered_multiset.i b/Lib/std/std_unordered_multiset.i new file mode 100644 index 000000000..5ef76612d --- /dev/null +++ b/Lib/std/std_unordered_multiset.i @@ -0,0 +1,83 @@ +// +// std::unordered_multiset +// + +%include + +// 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), f(const std::unordered_multiset&): +// the parameter being read-only, either a sequence or a +// previously wrapped std::unordered_multiset can be passed. +// -- f(std::unordered_multiset&), f(std::unordered_multiset*): +// the parameter may be modified; therefore, only a wrapped std::unordered_multiset +// can be passed. +// -- std::unordered_multiset f(), const std::unordered_multiset& 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& f(), std::unordered_multiset* f(): +// the set is returned by reference; therefore, a wrapped std::unordered_multiset +// is returned +// -- const std::unordered_multiset* f(), f(const std::unordered_multiset*): +// for consistency, they expect and return a plain set pointer. +// ------------------------------------------------------------------------ + + +// exported classes + +namespace std { + + //unordered_multiset + + template , + 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 > { + 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); + }; +} diff --git a/Lib/std/std_unordered_set.i b/Lib/std/std_unordered_set.i new file mode 100644 index 000000000..0eac339e0 --- /dev/null +++ b/Lib/std/std_unordered_set.i @@ -0,0 +1,116 @@ +// +// std::unordered_set +// + +%include +%include + +// 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 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 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), f(const std::unordered_set&): +// the parameter being read-only, either a sequence or a +// previously wrapped std::unordered_set can be passed. +// -- f(std::unordered_set&), f(std::unordered_set*): +// the parameter may be modified; therefore, only a wrapped std::unordered_set +// can be passed. +// -- std::unordered_set f(), const std::unordered_set& 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& f(), std::unordered_set* f(): +// the unordered_set is returned by reference; therefore, a wrapped std::unordered_set +// is returned +// -- const std::unordered_set* f(), f(const std::unordered_set*): +// for consistency, they expect and return a plain unordered_set pointer. +// ------------------------------------------------------------------------ + +%{ +#include +%} + +// exported classes + +namespace std { + + template , + 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 > { + 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); + }; +}