MCPcopy Create free account
hub / github.com/chokkan/crfsuite / SwigPyIterator

Class SwigPyIterator

swig/python/export_wrap.cpp:3587–3698  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3585 };
3586
3587 struct SwigPyIterator {
3588 private:
3589 SwigPtr_PyObject _seq;
3590
3591 protected:
3592 SwigPyIterator(PyObject *seq) : _seq(seq)
3593 {
3594 }
3595
3596 public:
3597 virtual ~SwigPyIterator() {}
3598
3599 // Access iterator method, required by Python
3600 virtual PyObject *value() const = 0;
3601
3602 // Forward iterator method, required by Python
3603 virtual SwigPyIterator *incr(size_t n = 1) = 0;
3604
3605 // Backward iterator method, very common in C++, but not required in Python
3606 virtual SwigPyIterator *decr(size_t /*n*/ = 1)
3607 {
3608 throw stop_iteration();
3609 }
3610
3611 // Random access iterator methods, but not required in Python
3612 virtual ptrdiff_t distance(const SwigPyIterator &/*x*/) const
3613 {
3614 throw std::invalid_argument("operation not supported");
3615 }
3616
3617 virtual bool equal (const SwigPyIterator &/*x*/) const
3618 {
3619 throw std::invalid_argument("operation not supported");
3620 }
3621
3622 // C++ common/needed methods
3623 virtual SwigPyIterator *copy() const = 0;
3624
3625 PyObject *next()
3626 {
3627 SWIG_PYTHON_THREAD_BEGIN_BLOCK; // disable threads
3628 PyObject *obj = value();
3629 incr();
3630 SWIG_PYTHON_THREAD_END_BLOCK; // re-enable threads
3631 return obj;
3632 }
3633
3634 /* Make an alias for Python 3.x */
3635 PyObject *__next__()
3636 {
3637 return next();
3638 }
3639
3640 PyObject *previous()
3641 {
3642 SWIG_PYTHON_THREAD_BEGIN_BLOCK; // disable threads
3643 decr();
3644 PyObject *obj = value();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected