diff options
Diffstat (limited to 'Lib/python')
-rw-r--r-- | Lib/python/std_map.i | 142 | ||||
-rw-r--r-- | Lib/python/std_multimap.i | 2 |
2 files changed, 74 insertions, 70 deletions
diff --git a/Lib/python/std_map.i b/Lib/python/std_map.i index 37d749790..66ed68da5 100644 --- a/Lib/python/std_map.i +++ b/Lib/python/std_map.i @@ -2,7 +2,79 @@ Maps */ -%fragment("StdMapTraits","header",fragment="StdSequenceTraits") +%fragment("StdMapCommonTraits","header",fragment="StdSequenceTraits") +{ + namespace swig { + template <class ValueType> + 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 <class ValueType> + 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<class OutIterator, class FromOper, class ValueType = typename OutIterator::value_type> + struct SwigPyMapIterator_T : SwigPyIteratorClosed_T<OutIterator, ValueType, FromOper> + { + SwigPyMapIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq) + : SwigPyIteratorClosed_T<OutIterator,ValueType,FromOper>(curr, first, last, seq) + { + } + }; + + + template<class OutIterator, + class FromOper = from_key_oper<typename OutIterator::value_type> > + struct SwigPyMapKeyIterator_T : SwigPyMapIterator_T<OutIterator, FromOper> + { + SwigPyMapKeyIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq) + : SwigPyMapIterator_T<OutIterator, FromOper>(curr, first, last, seq) + { + } + }; + + template<typename OutIter> + inline SwigPyIterator* + make_output_key_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0) + { + return new SwigPyMapKeyIterator_T<OutIter>(current, begin, end, seq); + } + + template<class OutIterator, + class FromOper = from_value_oper<typename OutIterator::value_type> > + struct SwigPyMapValueITerator_T : SwigPyMapIterator_T<OutIterator, FromOper> + { + SwigPyMapValueITerator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq) + : SwigPyMapIterator_T<OutIterator, FromOper>(curr, first, last, seq) + { + } + }; + + + template<typename OutIter> + inline SwigPyIterator* + make_output_value_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0) + { + return new SwigPyMapValueITerator_T<OutIter>(current, begin, end, seq); + } + } +} + +%fragment("StdMapTraits","header",fragment="StdMapCommonTraits") { namespace swig { template <class SwigPySeq, class K, class T, class Compare, class Alloc > @@ -73,74 +145,6 @@ } } }; - - template <class ValueType> - 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 <class ValueType> - 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<class OutIterator, class FromOper, class ValueType = typename OutIterator::value_type> - struct SwigPyMapIterator_T : SwigPyIteratorClosed_T<OutIterator, ValueType, FromOper> - { - SwigPyMapIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq) - : SwigPyIteratorClosed_T<OutIterator,ValueType,FromOper>(curr, first, last, seq) - { - } - }; - - - template<class OutIterator, - class FromOper = from_key_oper<typename OutIterator::value_type> > - struct SwigPyMapKeyIterator_T : SwigPyMapIterator_T<OutIterator, FromOper> - { - SwigPyMapKeyIterator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq) - : SwigPyMapIterator_T<OutIterator, FromOper>(curr, first, last, seq) - { - } - }; - - template<typename OutIter> - inline SwigPyIterator* - make_output_key_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0) - { - return new SwigPyMapKeyIterator_T<OutIter>(current, begin, end, seq); - } - - template<class OutIterator, - class FromOper = from_value_oper<typename OutIterator::value_type> > - struct SwigPyMapValueITerator_T : SwigPyMapIterator_T<OutIterator, FromOper> - { - SwigPyMapValueITerator_T(OutIterator curr, OutIterator first, OutIterator last, PyObject *seq) - : SwigPyMapIterator_T<OutIterator, FromOper>(curr, first, last, seq) - { - } - }; - - - template<typename OutIter> - inline SwigPyIterator* - make_output_value_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, PyObject *seq = 0) - { - return new SwigPyMapValueITerator_T<OutIter>(current, begin, end, seq); - } - } } diff --git a/Lib/python/std_multimap.i b/Lib/python/std_multimap.i index 8a240ae10..c81e2ac5d 100644 --- a/Lib/python/std_multimap.i +++ b/Lib/python/std_multimap.i @@ -3,7 +3,7 @@ */ %include <std_map.i> -%fragment("StdMultimapTraits","header",fragment="StdSequenceTraits") +%fragment("StdMultimapTraits","header",fragment="StdMapCommonTraits") { namespace swig { template <class SwigPySeq, class K, class T > |