summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.current7
-rw-r--r--Examples/test-suite/cpp11_std_array.i10
-rw-r--r--Examples/test-suite/li_std_carray.i8
-rw-r--r--Examples/test-suite/octave/li_std_carray_runme.m52
-rw-r--r--Examples/test-suite/python/Makefile.in1
-rw-r--r--Examples/test-suite/python/cpp11_std_array_runme.py26
-rw-r--r--Examples/test-suite/python/li_std_carray_runme.py39
-rw-r--r--Examples/test-suite/python/li_std_containers_int_runme.py6
-rw-r--r--Examples/test-suite/python/li_std_set_runme.py10
-rw-r--r--Lib/octave/std_carray.i0
-rw-r--r--Lib/python/pyclasses.swg2
-rw-r--r--Lib/python/pycontainer.swg315
-rw-r--r--Lib/python/pyname_compat.i7
-rw-r--r--Lib/python/std_array.i46
-rw-r--r--Lib/python/std_carray.i54
-rw-r--r--Lib/python/std_map.i10
-rw-r--r--Lib/python/std_multimap.i10
-rw-r--r--Lib/python/std_multiset.i11
-rw-r--r--Lib/python/std_set.i11
-rw-r--r--Lib/python/std_unordered_map.i10
-rw-r--r--Lib/python/std_unordered_multimap.i10
-rw-r--r--Lib/python/std_unordered_multiset.i11
-rw-r--r--Lib/python/std_unordered_set.i11
-rw-r--r--Lib/std/std_carray.swg64
24 files changed, 149 insertions, 582 deletions
diff --git a/CHANGES.current b/CHANGES.current
index 1b5b8dfef..6e0033b3a 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -92,6 +92,13 @@ Version 4.2.0 (in progress)
*** POTENTIAL INCOMPATIBILITY ***
+2023-04-05: wsfulton
+ [Python] #2515 Add support for all STL containers to be constructible from a Python set.
+
+ The previous implementation used the Python Sequence Protocol to convert from Python types
+ to STL containers. The new implementation uses the Python Iterator Protocol instead and
+ thereby can convert from a Python set too.
+
2023-03-25: alatina
[Octave] #2512 Add support for Octave 8.1.
diff --git a/Examples/test-suite/cpp11_std_array.i b/Examples/test-suite/cpp11_std_array.i
index 9dc11ce9e..ce87db75a 100644
--- a/Examples/test-suite/cpp11_std_array.i
+++ b/Examples/test-suite/cpp11_std_array.i
@@ -57,6 +57,16 @@ void arrayInPtr(std::array<int, 6> * myarray) {
val *= 10;
}
}
+
+std::array<int, 6> overloadFunc(std::array<int, 6> myarray) {
+ std::array<int, 6> newarray(myarray);
+ for (auto& val : newarray) {
+ val *= 100;
+ }
+ return newarray;
+}
+void overloadFunc(int i, int j) {
+}
%}
#endif
diff --git a/Examples/test-suite/li_std_carray.i b/Examples/test-suite/li_std_carray.i
deleted file mode 100644
index b38e0e441..000000000
--- a/Examples/test-suite/li_std_carray.i
+++ /dev/null
@@ -1,8 +0,0 @@
-%module li_std_carray
-
-%include <std_carray.i>
-
-%template(Vector3) std::carray<double, 3>;
-
-%template(Matrix3) std::carray<std::carray<double, 3>, 3>;
-
diff --git a/Examples/test-suite/octave/li_std_carray_runme.m b/Examples/test-suite/octave/li_std_carray_runme.m
deleted file mode 100644
index f7212dc9a..000000000
--- a/Examples/test-suite/octave/li_std_carray_runme.m
+++ /dev/null
@@ -1,52 +0,0 @@
-li_std_carray
-
-
-v3 = Vector3();
-for i=0:len(v3),
- v3(i) = i;
-endfor
-
-i = 0;
-for d in v3,
- if (d != i)
- error("failed");
- endif
- i = i + 1;
-endfor
-
-
-m3 = Matrix3();
-
-for i=0:len(m3),
- v3 = m3(i);
- for j=0:len(v3),
- v3(j) = i + j;
- endfor
-endfor
-
-i = 0;
-for v3 in m3,
- j = 0;
- for d in v3,
- if (d != i + j)
- error("failed");
- endif
- j = j + 1;
- endfor
- i = i + 1
-endfor
-
-for i=0:len(m3),
- for j=0:len(m3),
- if (m3(i,j) != i + j)
- error("failed");
- endif
- endfor
-endfor
-
-da = Vector3([1,2,3]);
-ma = Matrix3({[1,2,3],[4,5,6],[7,8,9]});
-
-
-
-
diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in
index baa89859a..46e23dbe5 100644
--- a/Examples/test-suite/python/Makefile.in
+++ b/Examples/test-suite/python/Makefile.in
@@ -73,7 +73,6 @@ CPP_TEST_CASES += \
swigobject \
template_matrix \
-# li_std_carray
# director_profile
CPP11_TEST_CASES = \
diff --git a/Examples/test-suite/python/cpp11_std_array_runme.py b/Examples/test-suite/python/cpp11_std_array_runme.py
index 9e11a3e5b..dbf9bcee3 100644
--- a/Examples/test-suite/python/cpp11_std_array_runme.py
+++ b/Examples/test-suite/python/cpp11_std_array_runme.py
@@ -56,6 +56,14 @@ def setslice_exception(swigarray, newval):
# print("exception: {}".format(e))
pass
+def overload_type_exception(pythonlist):
+ try:
+ overloadFunc(pythonlist)
+ raise RuntimeError("overloadFunc({}) missed raising TypeError exception".format(pythonlist))
+ except TypeError as e:
+# print("exception: {}".format(e))
+ pass
+
# Check std::array has similar behaviour to a Python list
# except it is not resizable
@@ -161,3 +169,21 @@ compare_containers(ai, [90, 80, 70, 60, 50, 40])
# fill
ai.fill(111)
compare_containers(ai, [111, 111, 111, 111, 111, 111])
+
+# Overloading
+newarray = overloadFunc([9, 8, 7, 6, 5, 4])
+compare_containers(newarray, [900, 800, 700, 600, 500, 400])
+
+ai = ArrayInt6([9, 8, 7, 6, 5, 4])
+newarray = overloadFunc([9, 8, 7, 6, 5, 4])
+compare_containers(newarray, [900, 800, 700, 600, 500, 400])
+
+overloadFunc(1, 2)
+overload_type_exception([1, 2, 3, 4, 5, "6"])
+overload_type_exception([1, 2, 3, 4, 5])
+overload_type_exception([1, 2, 3, 4, 5, 6, 7])
+
+# Construct from Python set
+myset = {11, 12, 13, 14, 15, 16}
+ai = ArrayInt6(myset)
+compare_containers(ai, list(myset))
diff --git a/Examples/test-suite/python/li_std_carray_runme.py b/Examples/test-suite/python/li_std_carray_runme.py
deleted file mode 100644
index 36eeaf173..000000000
--- a/Examples/test-suite/python/li_std_carray_runme.py
+++ /dev/null
@@ -1,39 +0,0 @@
-from li_std_carray import *
-
-
-v3 = Vector3()
-for i in range(0, len(v3)):
- v3[i] = i
-
-i = 0
-for d in v3:
- if d != i:
- raise RuntimeError
- i = i + 1
-
-
-m3 = Matrix3()
-
-for i in range(0, len(m3)):
- v3 = m3[i]
- for j in range(0, len(v3)):
- v3[j] = i + j
-
-i = 0
-for v3 in m3:
- j = 0
- for d in v3:
- if d != i + j:
- raise RuntimeError
- j = j + 1
- pass
- i = i + 1
- pass
-
-for i in range(0, len(m3)):
- for j in range(0, len(m3)):
- if m3[i][j] != i + j:
- raise RuntimeError
-
-da = Vector3((1, 2, 3))
-ma = Matrix3(((1, 2, 3), (4, 5, 6), (7, 8, 9)))
diff --git a/Examples/test-suite/python/li_std_containers_int_runme.py b/Examples/test-suite/python/li_std_containers_int_runme.py
index f346de220..13c76d3aa 100644
--- a/Examples/test-suite/python/li_std_containers_int_runme.py
+++ b/Examples/test-suite/python/li_std_containers_int_runme.py
@@ -279,3 +279,9 @@ try:
raise RuntimeError("Zero step not caught")
except ValueError:
pass
+
+# Construct from set (Iterator protocol, not Sequence protocol)
+ps = {11, 22, 33}
+iv = vector_int(ps)
+il = vector_int(ps)
+compare_containers(list(ps), iv, il)
diff --git a/Examples/test-suite/python/li_std_set_runme.py b/Examples/test-suite/python/li_std_set_runme.py
index 34a1eb19c..7618f7dc8 100644
--- a/Examples/test-suite/python/li_std_set_runme.py
+++ b/Examples/test-suite/python/li_std_set_runme.py
@@ -92,3 +92,13 @@ for i in s:
if (len(sum) != 3 or (not 1 in sum) or (not "hello" in sum) or (not (1, 2) in sum)):
raise RuntimeError
+
+# Create from Python set
+s = set_string({"x", "y", "z"})
+sum = ""
+for i in s:
+ sum = sum + i
+
+if sum != "xyz":
+ raise RuntimeError
+
diff --git a/Lib/octave/std_carray.i b/Lib/octave/std_carray.i
deleted file mode 100644
index e69de29bb..000000000
--- a/Lib/octave/std_carray.i
+++ /dev/null
diff --git a/Lib/python/pyclasses.swg b/Lib/python/pyclasses.swg
index 31ebdd2a1..39c4e0316 100644
--- a/Lib/python/pyclasses.swg
+++ b/Lib/python/pyclasses.swg
@@ -11,7 +11,7 @@
or as a member variable:
struct A {
- SwigPtr_PyObject obj;
+ SwigPtr_PyObject _obj;
A(PyObject *o) : _obj(o) {
}
};
diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg
index 4910fecc0..ceee27f5d 100644
--- a/Lib/python/pycontainer.swg
+++ b/Lib/python/pycontainer.swg
@@ -456,239 +456,6 @@ namespace swig {
}
}
-%fragment("SwigPySequence_Cont","header",
- fragment="StdTraits",
- fragment="SwigPySequence_Base",
- fragment="SwigPyIterator_T")
-{
-namespace swig
-{
- template <class T>
- struct SwigPySequence_Ref
- {
- SwigPySequence_Ref(PyObject* seq, Py_ssize_t index)
- : _seq(seq), _index(index)
- {
- }
-
- operator T () const
- {
- swig::SwigVar_PyObject item = PySequence_GetItem(_seq, _index);
- try {
- return swig::as<T>(item);
- } catch (const std::invalid_argument& e) {
- char msg[1024];
- PyOS_snprintf(msg, sizeof(msg), "in sequence element %d ", (int)_index);
- if (!PyErr_Occurred()) {
- ::%type_error(swig::type_name<T>());
- }
- SWIG_Python_AddErrorMsg(msg);
- SWIG_Python_AddErrorMsg(e.what());
- throw;
- }
- }
-
- SwigPySequence_Ref& operator=(const T& v)
- {
- PySequence_SetItem(_seq, _index, swig::from<T>(v));
- return *this;
- }
-
- private:
- PyObject* _seq;
- Py_ssize_t _index;
- };
-
- template <class T>
- struct SwigPySequence_ArrowProxy
- {
- SwigPySequence_ArrowProxy(const T& x): m_value(x) {}
- const T* operator->() const { return &m_value; }
- operator const T*() const { return &m_value; }
- T m_value;
- };
-
- template <class T, class Reference >
- struct SwigPySequence_InputIterator
- {
- typedef SwigPySequence_InputIterator<T, Reference > self;
-
- typedef std::random_access_iterator_tag iterator_category;
- typedef Reference reference;
- typedef T value_type;
- typedef T* pointer;
- typedef Py_ssize_t difference_type;
-
- SwigPySequence_InputIterator()
- {
- }
-
- SwigPySequence_InputIterator(PyObject* seq, Py_ssize_t index)
- : _seq(seq), _index(index)
- {
- }
-
- reference operator*() const
- {
- return reference(_seq, _index);
- }
-
- SwigPySequence_ArrowProxy<T>
- operator->() const {
- return SwigPySequence_ArrowProxy<T>(operator*());
- }
-
- bool operator==(const self& ri) const
- {
- return (_index == ri._index) && (_seq == ri._seq);
- }
-
- bool operator!=(const self& ri) const
- {
- return !(operator==(ri));
- }
-
- self& operator ++ ()
- {
- ++_index;
- return *this;
- }
-
- self& operator -- ()
- {
- --_index;
- return *this;
- }
-
- self& operator += (difference_type n)
- {
- _index += n;
- return *this;
- }
-
- self operator +(difference_type n) const
- {
- return self(_seq, _index + n);
- }
-
- self& operator -= (difference_type n)
- {
- _index -= n;
- return *this;
- }
-
- self operator -(difference_type n) const
- {
- return self(_seq, _index - n);
- }
-
- difference_type operator - (const self& ri) const
- {
- return _index - ri._index;
- }
-
- bool operator < (const self& ri) const
- {
- return _index < ri._index;
- }
-
- reference
- operator[](difference_type n) const
- {
- return reference(_seq, _index + n);
- }
-
- private:
- PyObject* _seq;
- difference_type _index;
- };
-
- // STL container wrapper around a Python sequence
- template <class T>
- struct SwigPySequence_Cont
- {
- typedef SwigPySequence_Ref<T> reference;
- typedef const SwigPySequence_Ref<T> const_reference;
- typedef T value_type;
- typedef T* pointer;
- typedef Py_ssize_t difference_type;
- typedef size_t size_type;
- typedef const pointer const_pointer;
- typedef SwigPySequence_InputIterator<T, reference> iterator;
- typedef SwigPySequence_InputIterator<T, const_reference> const_iterator;
-
- SwigPySequence_Cont(PyObject* seq) : _seq(0)
- {
- if (!PySequence_Check(seq)) {
- throw std::invalid_argument("a sequence is expected");
- }
- _seq = seq;
- Py_INCREF(_seq);
- }
-
- ~SwigPySequence_Cont()
- {
- Py_XDECREF(_seq);
- }
-
- size_type size() const
- {
- return static_cast<size_type>(PySequence_Size(_seq));
- }
-
- bool empty() const
- {
- return size() == 0;
- }
-
- iterator begin()
- {
- return iterator(_seq, 0);
- }
-
- const_iterator begin() const
- {
- return const_iterator(_seq, 0);
- }
-
- iterator end()
- {
- return iterator(_seq, size());
- }
-
- const_iterator end() const
- {
- return const_iterator(_seq, size());
- }
-
- reference operator[](difference_type n)
- {
- return reference(_seq, n);
- }
-
- const_reference operator[](difference_type n) const
- {
- return const_reference(_seq, n);
- }
-
- bool check() const
- {
- Py_ssize_t s = size();
- for (Py_ssize_t i = 0; i < s; ++i) {
- swig::SwigVar_PyObject item = PySequence_GetItem(_seq, i);
- if (!swig::check<value_type>(item))
- return false;
- }
- return true;
- }
-
- private:
- PyObject* _seq;
- };
-
-}
-}
-
%define %swig_sequence_iterator(Sequence...)
%swig_sequence_iterator_with_making_function(swig::make_output_iterator,Sequence...)
%enddef
@@ -704,12 +471,12 @@ namespace swig
class const_iterator;
class const_reverse_iterator;
- %typemap(out,noblock=1,fragment="SwigPySequence_Cont")
+ %typemap(out,noblock=1,fragment="SwigPyIterator_T")
iterator, reverse_iterator, const_iterator, const_reverse_iterator {
$result = SWIG_NewPointerObj(Make_output_iterator(%static_cast($1,const $type &)),
swig::SwigPyIterator::descriptor(),SWIG_POINTER_OWN);
}
- %typemap(out,noblock=1,fragment="SwigPySequence_Cont")
+ %typemap(out,noblock=1,fragment="SwigPyIterator_T")
std::pair<iterator, iterator>, std::pair<const_iterator, const_iterator> {
$result = PyTuple_New(2);
PyTuple_SetItem($result,0,SWIG_NewPointerObj(Make_output_iterator(%static_cast($1,const $type &).first),
@@ -718,7 +485,7 @@ namespace swig
swig::SwigPyIterator::descriptor(),SWIG_POINTER_OWN));
}
- %fragment("SwigPyPairBoolOutputIterator","header",fragment=SWIG_From_frag(bool),fragment="SwigPySequence_Cont") {}
+ %fragment("SwigPyPairBoolOutputIterator","header",fragment=SWIG_From_frag(bool),fragment="SwigPyIterator_T") {}
%typemap(out,noblock=1,fragment="SwigPyPairBoolOutputIterator")
std::pair<iterator, bool>, std::pair<const_iterator, bool> {
@@ -728,7 +495,7 @@ namespace swig
PyTuple_SetItem($result,1,SWIG_From(bool)(%static_cast($1,const $type &).second));
}
- %typemap(in,noblock=1,fragment="SwigPySequence_Cont")
+ %typemap(in,noblock=1,fragment="SwigPyIterator_T")
iterator(swig::SwigPyIterator *iter = 0, int res),
reverse_iterator(swig::SwigPyIterator *iter = 0, int res),
const_iterator(swig::SwigPyIterator *iter = 0, int res),
@@ -746,14 +513,14 @@ namespace swig
}
}
- %typecheck(%checkcode(ITERATOR),noblock=1,fragment="SwigPySequence_Cont")
+ %typecheck(%checkcode(ITERATOR),noblock=1,fragment="SwigPyIterator_T")
iterator, reverse_iterator, const_iterator, const_reverse_iterator {
swig::SwigPyIterator *iter = 0;
int res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::SwigPyIterator::descriptor(), 0);
$1 = (SWIG_IsOK(res) && iter && (dynamic_cast<swig::SwigPyIterator_T<$type > *>(iter) != 0));
}
- %fragment("SwigPySequence_Cont");
+ %fragment("SwigPyIterator_T");
%newobject iterator(PyObject **PYTHON_SELF);
%extend {
@@ -999,26 +766,50 @@ namespace swig
%fragment("StdSequenceTraits","header",
fragment="StdTraits",
- fragment="SwigPySequence_Cont")
+ fragment="SwigPySequence_Base")
{
namespace swig {
- template <class SwigPySeq, class Seq>
- inline void
- assign(const SwigPySeq& swigpyseq, Seq* seq) {
- // seq->assign(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 <class Seq, class T = typename Seq::value_type >
+ struct IteratorProtocol {
+ static void assign(PyObject *obj, Seq *seq) {
+ SwigVar_PyObject iter = PyObject_GetIter(obj);
+ if (iter) {
+ SwigVar_PyObject item = PyIter_Next(iter);
+ while (item) {
+ seq->insert(seq->end(), swig::as<T>(item));
+ item = PyIter_Next(iter);
+ }
+ }
}
- }
+
+ static bool check(PyObject *obj) {
+ int ret = false;
+ SwigVar_PyObject iter = PyObject_GetIter(obj);
+ if (iter) {
+ SwigVar_PyObject item = PyIter_Next(iter);
+ ret = true;
+ while (item) {
+ ret = swig::check<T>(item);
+ item = ret ? PyIter_Next(iter) : 0;
+ }
+ }
+ return ret;
+ }
+ };
template <class Seq, class T = typename Seq::value_type >
struct traits_asptr_stdseq {
typedef Seq sequence;
typedef T value_type;
+ static bool is_iterable(PyObject *obj) {
+ SwigVar_PyObject iter = PyObject_GetIter(obj);
+ PyErr_Clear();
+ return iter != 0;
+ }
+
static int asptr(PyObject *obj, sequence **seq) {
+ int ret = SWIG_ERROR;
if (obj == Py_None || SWIG_Python_GetSwigThis(obj)) {
sequence *p;
swig_type_info *descriptor = swig::type_info<sequence>();
@@ -1026,27 +817,25 @@ namespace swig {
if (seq) *seq = p;
return SWIG_OLDOBJ;
}
- } else if (PySequence_Check(obj)) {
+ } else if (is_iterable(obj)) {
try {
- SwigPySequence_Cont<value_type> swigpyseq(obj);
if (seq) {
- sequence *pseq = new sequence();
- assign(swigpyseq, pseq);
- *seq = pseq;
- return SWIG_NEWOBJ;
+ *seq = new sequence();
+ IteratorProtocol<Seq, T>::assign(obj, *seq);
+ if (!PyErr_Occurred())
+ return SWIG_NEWOBJ;
} else {
- return swigpyseq.check() ? SWIG_OK : SWIG_ERROR;
+ return IteratorProtocol<Seq, T>::check(obj) ? SWIG_OK : SWIG_ERROR;
}
} catch (std::exception& e) {
- if (seq) {
- if (!PyErr_Occurred()) {
- PyErr_SetString(PyExc_TypeError, e.what());
- }
- }
- return SWIG_ERROR;
+ if (seq && !PyErr_Occurred())
+ PyErr_SetString(PyExc_TypeError, e.what());
}
+ if (seq)
+ delete *seq;
+ return SWIG_ERROR;
}
- return SWIG_ERROR;
+ return ret;
}
};
diff --git a/Lib/python/pyname_compat.i b/Lib/python/pyname_compat.i
index a9630dbe7..789b28443 100644
--- a/Lib/python/pyname_compat.i
+++ b/Lib/python/pyname_compat.i
@@ -25,7 +25,6 @@
*/
%fragment("PySequence_Base", "header", fragment="SwigPySequence_Base") {}
-%fragment("PySequence_Cont", "header", fragment="SwigPySequence_Cont") {}
%fragment("PySwigIterator_T", "header", fragment="SwigPyIterator_T") {}
%fragment("PyPairBoolOutputIterator", "header", fragment="SwigPyPairBoolOutputIterator") {}
%fragment("PySwigIterator", "header", fragment="SwigPyIterator") {}
@@ -38,11 +37,6 @@
#define PyObject_ptr SwigPtr_PyObject
#define PyObject_var SwigVar_PyObject
#define PyOper SwigPyOper
-#define PySeq SwigPySeq
-#define PySequence_ArrowProxy SwigPySequence_ArrowProxy
-#define PySequence_Cont SwigPySequence_Cont
-#define PySequence_InputIterator SwigPySequence_InputIterator
-#define PySequence_Ref SwigPySequence_Ref
#define PySwigClientData SwigPyClientData
#define PySwigClientData_Del SwigPyClientData_Del
#define PySwigClientData_New SwigPyClientData_New
@@ -79,7 +73,6 @@
#define PySwigPacked_repr SwigPyPacked_repr
#define PySwigPacked_str SwigPyPacked_str
#define PySwigPacked_type SwigPyPacked_type
-#define pyseq swigpyseq
#define pyswigobject_type swigpyobject_type
#define pyswigpacked_type swigpypacked_type
%}
diff --git a/Lib/python/std_array.i b/Lib/python/std_array.i
index a3de3125b..561f00fc7 100644
--- a/Lib/python/std_array.i
+++ b/Lib/python/std_array.i
@@ -19,15 +19,43 @@
}
};
- template <class SwigPySeq, class T, size_t N>
- inline void
- assign(const SwigPySeq& swigpyseq, std::array<T, N>* seq) {
- if (swigpyseq.size() < seq->size())
- throw std::invalid_argument("std::array cannot be expanded in size");
- else if (swigpyseq.size() > seq->size())
- throw std::invalid_argument("std::array cannot be reduced in size");
- std::copy(swigpyseq.begin(), swigpyseq.end(), seq->begin());
- }
+ template <class T, size_t N>
+ struct IteratorProtocol<std::array<T, N>, T> {
+
+ static void assign(PyObject *obj, std::array<T, N> *seq) {
+ SwigVar_PyObject iter = PyObject_GetIter(obj);
+ if (iter) {
+ SwigVar_PyObject item = PyIter_Next(iter);
+ size_t count = 0;
+ typename std::array<T, N>::iterator array_iter = seq->begin();
+ while (item && (count < N)) {
+ ++count;
+ *array_iter++ = swig::as<T>(item);
+ item = PyIter_Next(iter);
+ }
+ if (count != N || item)
+ throw std::invalid_argument("std::array size does not match source container size");
+ }
+ }
+
+ static bool check(PyObject *obj) {
+ int ret = false;
+ SwigVar_PyObject iter = PyObject_GetIter(obj);
+ if (iter) {
+ SwigVar_PyObject item = PyIter_Next(iter);
+ size_t count = 0;
+ ret = true;
+ while (item && (count < N)) {
+ ++count;
+ ret = swig::check<T>(item);
+ item = ret ? PyIter_Next(iter) : 0;
+ }
+ if (count != N || item)
+ ret = false;
+ }
+ return ret;
+ }
+ };
template <class T, size_t N>
inline void
diff --git a/Lib/python/std_carray.i b/Lib/python/std_carray.i
deleted file mode 100644
index 680d67115..000000000
--- a/Lib/python/std_carray.i
+++ /dev/null
@@ -1,54 +0,0 @@
-%include <pycontainer.swg>
-
-
-%fragment("StdCarrayTraits","header",fragment="StdSequenceTraits")
-{
-namespace swig {
- template <class T, size_t S>
- struct traits_asptr<std::carray<T, S> > {
- static int asptr(PyObject *obj, std::carray<T, S> **array) {
- return traits_asptr_stdseq<std::carray<T, S> >::asptr(obj, array);
- }
- };
-}
-}
-
-%warnfilter(SWIGWARN_IGNORE_OPERATOR_INDEX) std::carray::operator[];
-
-%extend std::carray {
- %fragment(SWIG_Traits_frag(std::carray<_Type, _Size >), "header",
- fragment="SwigPyIterator_T",
- fragment=SWIG_Traits_frag(_Type),
- fragment="StdCarrayTraits") {
- namespace swig {
- template <> struct traits<std::carray<_Type, _Size > > {
- typedef pointer_category category;
- static const char* type_name() {
- return "std::carray<" #_Type "," #_Size " >";
- }
- };
- }
- }
-
- %typemaps_asptr(SWIG_TYPECHECK_VECTOR, swig::asptr,
- SWIG_Traits_frag(std::carray<_Type, _Size >),
- std::carray<_Type, _Size >);
-
- %typemap(out,noblock=1) iterator, const_iterator {
- $result = SWIG_NewPointerObj(swig::make_output_iterator((const $type &)$1),
- swig::SwigPyIterator::descriptor(),SWIG_POINTER_OWN);
- }
-
- inline size_t __len__() const { return self->size(); }
-
- inline const _Type& __getitem__(size_t i) const { return (*self)[i]; }
-
- inline void __setitem__(size_t i, const _Type& v) { (*self)[i] = v; }
-
-
- swig::SwigPyIterator* __iter__(PyObject **PYTHON_SELF) {
- return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
- }
-}
-
-%include <std/std_carray.swg>
diff --git a/Lib/python/std_map.i b/Lib/python/std_map.i
index e0b7d69dc..ef6eb7f20 100644
--- a/Lib/python/std_map.i
+++ b/Lib/python/std_map.i
@@ -77,16 +77,6 @@
%fragment("StdMapTraits","header",fragment="StdMapCommonTraits")
{
namespace swig {
- template <class SwigPySeq, class K, class T, class Compare, class Alloc >
- inline void
- assign(const SwigPySeq& swigpyseq, std::map<K,T,Compare,Alloc > *map) {
- typedef typename std::map<K,T,Compare,Alloc >::value_type value_type;
- typename SwigPySeq::const_iterator it = swigpyseq.begin();
- for (;it != swigpyseq.end(); ++it) {
- map->insert(value_type(it->first, it->second));
- }
- }
-
template <class K, class T, class Compare, class Alloc>
struct traits_asptr<std::map<K,T,Compare,Alloc > > {
typedef std::map<K,T,Compare,Alloc > map_type;
diff --git a/Lib/python/std_multimap.i b/Lib/python/std_multimap.i
index bbffb6bcd..75b4d7fcf 100644
--- a/Lib/python/std_multimap.i
+++ b/Lib/python/std_multimap.i
@@ -6,16 +6,6 @@
%fragment("StdMultimapTraits","header",fragment="StdMapCommonTraits")
{
namespace swig {
- template <class SwigPySeq, class K, class T >
- inline void
- assign(const SwigPySeq& swigpyseq, std::multimap<K,T > *multimap) {
- typedef typename std::multimap<K,T>::value_type value_type;
- typename SwigPySeq::const_iterator it = swigpyseq.begin();
- for (;it != swigpyseq.end(); ++it) {
- multimap->insert(value_type(it->first, it->second));
- }
- }
-
template <class K, class T>
struct traits_asptr<std::multimap<K,T> > {
typedef std::multimap<K,T> multimap_type;
diff --git a/Lib/python/std_multiset.i b/Lib/python/std_multiset.i
index ac430334c..b79f64e5a 100644
--- a/Lib/python/std_multiset.i
+++ b/Lib/python/std_multiset.i
@@ -7,17 +7,6 @@
%fragment("StdMultisetTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
- template <class SwigPySeq, class T>
- inline void
- assign(const SwigPySeq& swigpyseq, std::multiset<T>* 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 <class T>
struct traits_asptr<std::multiset<T> > {
static int asptr(PyObject *obj, std::multiset<T> **m) {
diff --git a/Lib/python/std_set.i b/Lib/python/std_set.i
index 0ef011998..3f80daff6 100644
--- a/Lib/python/std_set.i
+++ b/Lib/python/std_set.i
@@ -5,17 +5,6 @@
%fragment("StdSetTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
- template <class SwigPySeq, class T>
- inline void
- assign(const SwigPySeq& swigpyseq, std::set<T>* 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 <class T>
struct traits_asptr<std::set<T> > {
static int asptr(PyObject *obj, std::set<T> **s) {
diff --git a/Lib/python/std_unordered_map.i b/Lib/python/std_unordered_map.i
index 784be4c8f..200ec2c5d 100644
--- a/Lib/python/std_unordered_map.i
+++ b/Lib/python/std_unordered_map.i
@@ -56,16 +56,6 @@
%fragment("StdUnorderedMapTraits","header",fragment="StdMapCommonTraits",fragment="StdUnorderedMapForwardIteratorTraits")
{
namespace swig {
- template <class SwigPySeq, class K, class T, class Hash, class Compare, class Alloc>
- inline void
- assign(const SwigPySeq& swigpyseq, std::unordered_map<K,T,Hash,Compare,Alloc> *unordered_map) {
- typedef typename std::unordered_map<K,T,Hash,Compare,Alloc>::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 <class K, class T, class Hash, class Compare, class Alloc>
struct traits_reserve<std::unordered_map<K,T,Hash,Compare,Alloc> > {
static void reserve(std::unordered_map<K,T,Hash,Compare,Alloc> &seq, typename std::unordered_map<K,T,Hash,Compare,Alloc>::size_type n) {
diff --git a/Lib/python/std_unordered_multimap.i b/Lib/python/std_unordered_multimap.i
index bc095ea48..816ec0933 100644
--- a/Lib/python/std_unordered_multimap.i
+++ b/Lib/python/std_unordered_multimap.i
@@ -6,16 +6,6 @@
%fragment("StdUnorderedMultimapTraits","header",fragment="StdMapCommonTraits",fragment="StdUnorderedMapForwardIteratorTraits")
{
namespace swig {
- template <class SwigPySeq, class K, class T, class Hash, class Compare, class Alloc>
- inline void
- assign(const SwigPySeq& swigpyseq, std::unordered_multimap<K,T,Hash,Compare,Alloc> *unordered_multimap) {
- typedef typename std::unordered_multimap<K,T,Hash,Compare,Alloc>::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 <class K, class T, class Hash, class Compare, class Alloc>
struct traits_reserve<std::unordered_multimap<K,T,Hash,Compare,Alloc> > {
static void reserve(std::unordered_multimap<K,T,Hash,Compare,Alloc> &seq, typename std::unordered_multimap<K,T,Hash,Compare,Alloc>::size_type n) {
diff --git a/Lib/python/std_unordered_multiset.i b/Lib/python/std_unordered_multiset.i
index b0f3f096b..0542247b2 100644
--- a/Lib/python/std_unordered_multiset.i
+++ b/Lib/python/std_unordered_multiset.i
@@ -7,17 +7,6 @@
%fragment("StdUnorderedMultisetTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
- template <class SwigPySeq, class Key, class Hash, class Compare, class Alloc>
- inline void
- assign(const SwigPySeq& swigpyseq, std::unordered_multiset<Key,Hash,Compare,Alloc>* 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 <class Key, class Hash, class Compare, class Alloc>
struct traits_reserve<std::unordered_multiset<Key,Hash,Compare,Alloc> > {
static void reserve(std::unordered_multiset<Key,Hash,Compare,Alloc> &seq, typename std::unordered_multiset<Key,Hash,Compare,Alloc>::size_type n) {
diff --git a/Lib/python/std_unordered_set.i b/Lib/python/std_unordered_set.i
index 79fca6c2f..fd866b14a 100644
--- a/Lib/python/std_unordered_set.i
+++ b/Lib/python/std_unordered_set.i
@@ -5,17 +5,6 @@
%fragment("StdUnorderedSetTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
- template <class SwigPySeq, class Key, class Hash, class Compare, class Alloc>
- inline void
- assign(const SwigPySeq& swigpyseq, std::unordered_set<Key,Hash,Compare,Alloc>* 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 <class Key, class Hash, class Compare, class Alloc>
struct traits_reserve<std::unordered_set<Key,Hash,Compare,Alloc> > {
static void reserve(std::unordered_set<Key,Hash,Compare,Alloc> &seq, typename std::unordered_set<Key,Hash,Compare,Alloc>::size_type n) {
diff --git a/Lib/std/std_carray.swg b/Lib/std/std_carray.swg
deleted file mode 100644
index de2a07627..000000000
--- a/Lib/std/std_carray.swg
+++ /dev/null
@@ -1,64 +0,0 @@
-%{
-#include <algorithm>
-%}
-
-//
-// std::carray - is really an extension to the 'std' namespace.
-//
-// A simple fix C array wrapper, more or less as presented in
-//
-// "The C++ Standarf Library", by Nicolai M. Josuttis
-//
-// which is also derived from the example in
-//
-// "The C++ Programming Language", by Bjarne Stroustup.
-//
-
-%inline %{
-namespace std {
- template <class _Type, size_t _Size>
- class carray
- {
- public:
- typedef _Type value_type;
- typedef size_t size_type;
-
- typedef _Type * iterator;
- typedef const _Type * const_iterator;
-
- carray() { }
-
- carray(const carray& other) {
- std::copy(other.v, other.v + size(), v);
- }
-
- template <class _Iterator>
- carray(_Iterator first, _Iterator last) {
- assign(first, last);
- }
-
- iterator begin() { return v; }
- iterator end() { return v + _Size; }
-
- const_iterator begin() const { return v; }
- const_iterator end() const { return v + _Size; }
-
- _Type& operator[](size_t i) { return v[i]; }
- const _Type& operator[](size_t i) const { return v[i]; }
-
- static size_t size() { return _Size; }
-
- template <class _Iterator>
- void assign(_Iterator first, _Iterator last) {
- if (std::distance(first,last) == size()) {
- std::copy(first, last, v);
- } else {
- throw std::length_error("bad range length");
- }
- }
-
- private:
- _Type v[_Size];
- };
-}
-%}