clean PyItem and use it in OutputIterator
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7789 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
45439174b4
commit
ca60dcebc6
1 changed files with 51 additions and 52 deletions
|
|
@ -33,6 +33,54 @@ namespace swig {
|
||||||
%apply PyObject * const& {PyItem const&};
|
%apply PyObject * const& {PyItem const&};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
%{
|
||||||
|
namespace swig {
|
||||||
|
class PyItem {
|
||||||
|
PyObject *_obj;
|
||||||
|
public:
|
||||||
|
PyItem(const PyItem& item) : _obj(item._obj)
|
||||||
|
{
|
||||||
|
Py_XINCREF(_obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
PyItem(PyObject *obj = 0) :_obj(obj)
|
||||||
|
{
|
||||||
|
Py_XINCREF(_obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
PyItem & operator=(PyObject *obj) {
|
||||||
|
Py_XINCREF(obj);
|
||||||
|
Py_XDECREF(_obj);
|
||||||
|
_obj = obj;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyItem & operator=(const PyItem& item) {
|
||||||
|
this->operator=(static_cast<PyObject *>(item));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
~PyItem()
|
||||||
|
{
|
||||||
|
Py_XDECREF(_obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
operator PyObject *() const
|
||||||
|
{
|
||||||
|
return _obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyObject *operator->() const
|
||||||
|
{
|
||||||
|
return _obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%fragment(SWIG_Traits_frag(swig::PyItem),"header",fragment="StdTraits") {
|
%fragment(SWIG_Traits_frag(swig::PyItem),"header",fragment="StdTraits") {
|
||||||
namespace swig {
|
namespace swig {
|
||||||
template <> struct traits<PyItem > {
|
template <> struct traits<PyItem > {
|
||||||
|
|
@ -49,7 +97,7 @@ namespace swig {
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct traits_check<PyItem, value_category> {
|
struct traits_check<PyItem, value_category> {
|
||||||
static bool check(PyObject *obj) {
|
static bool check(PyObject *) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -64,10 +112,6 @@ namespace swig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%fragment(SWIG_Traits_frag(PyItem),"header")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
%fragment("PySequence_Base","header")
|
%fragment("PySequence_Base","header")
|
||||||
{
|
{
|
||||||
|
|
@ -102,48 +146,6 @@ namespace swig {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class PyItem {
|
|
||||||
PyObject *_obj;
|
|
||||||
public:
|
|
||||||
PyItem(const PyItem& item) : _obj(item._obj)
|
|
||||||
{
|
|
||||||
Py_XINCREF(_obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyItem(PyObject *obj = 0) :_obj(obj)
|
|
||||||
{
|
|
||||||
Py_XINCREF(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyItem & operator=(PyObject *obj) {
|
|
||||||
Py_XINCREF(obj);
|
|
||||||
Py_XDECREF(_obj);
|
|
||||||
_obj = obj;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
PyItem & operator=(const PyItem& item) {
|
|
||||||
this->operator=(static_cast<PyObject *>(item));
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
~PyItem()
|
|
||||||
{
|
|
||||||
Py_XDECREF(_obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
operator PyObject *() const
|
|
||||||
{
|
|
||||||
return _obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *operator->() const
|
|
||||||
{
|
|
||||||
return _obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
|
@ -281,18 +283,15 @@ namespace swig {
|
||||||
struct PySequence_OutputIterator
|
struct PySequence_OutputIterator
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
PyObject *_seq;
|
PyItem _seq;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PySequence_OutputIterator(PyObject *seq) : _seq(seq)
|
PySequence_OutputIterator(PyObject *seq) : _seq(seq)
|
||||||
{
|
{
|
||||||
if (_seq) Py_INCREF(_seq);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~PySequence_OutputIterator() {
|
virtual ~PySequence_OutputIterator() {}
|
||||||
if (_seq) Py_DECREF(_seq);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual PyObject *value() const throw (stop_iteration) = 0;
|
virtual PyObject *value() const throw (stop_iteration) = 0;
|
||||||
virtual PySequence_OutputIterator *incr(size_t n = 1) throw (stop_iteration) = 0;
|
virtual PySequence_OutputIterator *incr(size_t n = 1) throw (stop_iteration) = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue