67 PY_CLASS_METHOD_NAME(
Sequence, iter, methods::_iter_ );
68 PY_CLASS_METHOD_NAME(
Sequence, repr, methods::_repr_ );
69 LASS_EXECUTE_BEFORE_MAIN_EX( Sequence_executeBeforeMain,
76 Sequence::_lassPyClassDef.setSlot(Py_sq_inplace_concat, &
Sequence::inplaceConcat);
77 Sequence::_lassPyClassDef.setSlot(Py_sq_inplace_repeat, &
Sequence::inplaceRepeat);
80 Sequence::_lassPyClassDef.setSlot(Py_mp_ass_subscript, &
Sequence::assSubscript);
85 init(std::move(pimpl));
88 void Sequence::init(TPimpl&& pimpl)
90 LockGIL LASS_UNUSED(lock);
92 impl::fixObjectType(
this);
93 pimpl_ = std::move(pimpl);
96 const TSequencePtr Sequence::copy()
const
98 LockGIL LASS_UNUSED(lock);
99 Sequence::TPimpl pimpl = pimpl_->copy();
100 return TSequencePtr(
new Sequence(std::move(pimpl)));
102 void Sequence::clear()
104 LockGIL LASS_UNUSED(lock);
105 if (!pimpl_->clear())
110 void Sequence::reserve(Py_ssize_t n)
112 LockGIL LASS_UNUSED(lock);
113 if (!pimpl_->reserve(n))
118 void Sequence::append(
const TPyObjPtr& obj)
120 LockGIL LASS_UNUSED(lock);
121 if (!pimpl_->append(obj))
126 const TPyObjPtr Sequence::pop(Py_ssize_t i)
128 LockGIL LASS_UNUSED(lock);
138 LockGIL LASS_UNUSED(lock);
139 return pop(pimpl_->length() - 1);
142 const std::type_info& Sequence::type()
const
144 return pimpl_->type();
146 void* Sequence::raw(
bool writable)
const
148 return pimpl_->raw(writable);
151 std::string Sequence::repr()
const
153 LockGIL LASS_UNUSED(lock);
154 return pimpl_->repr();
159 LockGIL LASS_UNUSED(lock);
160 return pimpl_->asNative();
164 LockGIL LASS_UNUSED(lock);
168 Py_ssize_t Sequence::length(PyObject* self)
170 return static_cast<Sequence*
>(self)->pimpl_->length();
172 PyObject* Sequence::concat(PyObject* self, PyObject* other)
174 TSequencePtr result =
static_cast<Sequence*
>(self)->copy();
175 return inplaceConcat(result.get(), other);
177 PyObject* Sequence::repeat(PyObject* self, Py_ssize_t n)
179 TSequencePtr result =
static_cast<Sequence*
>(self)->copy();
180 return inplaceRepeat(result.get(), n);
182 PyObject* Sequence::item(PyObject* self, Py_ssize_t i)
184 return static_cast<Sequence*
>(self)->pimpl_->item(i);
186 int Sequence::assItem(PyObject* self, Py_ssize_t i, PyObject* obj)
188 return static_cast<Sequence*
>(self)->pimpl_->assItem(i, obj);
190 int Sequence::contains(PyObject* self, PyObject* obj)
192 return static_cast<Sequence*
>(self)->pimpl_->contains(obj);
194 PyObject* Sequence::inplaceConcat(PyObject* self, PyObject* other)
196 if (!
static_cast<Sequence*
>(self)->pimpl_->inplaceConcat(other))
203 PyObject* Sequence::inplaceRepeat(PyObject* self, Py_ssize_t n)
205 if (!
static_cast<Sequence*
>(self)->pimpl_->inplaceRepeat(n))
212 PyObject* Sequence::subscript(PyObject* self, PyObject* key)
214 PySequenceImplBase& pimpl = *
static_cast<Sequence*
>(self)->pimpl_;
215 if (PySlice_Check(key))
217 Py_ssize_t start, stop, step, slicelength;
218 if (PySlice_GetIndicesEx(key, pimpl.length(), &start, &stop, &step, &slicelength) != 0)
222 return pimpl.slice(start, stop, step);
225 if (pyGetSimpleObject(key, i) != 0)
233 return pimpl.item(i);
235 int Sequence::assSubscript( PyObject* self, PyObject* key, PyObject* value)
237 PySequenceImplBase& pimpl = *
static_cast<Sequence*
>(self)->pimpl_;
238 if (PySlice_Check(key))
240 Py_ssize_t start, stop, step, slicelength;
241 if (PySlice_GetIndicesEx(key, pimpl.length(), &start, &stop, &step, &slicelength) != 0)
245 return pimpl.assSlice(start, stop, step, value);
248 if (pyGetSimpleObject(key, i) != 0)
256 return pimpl.assItem(i, value);
Object for interfacing sequence-like objects with Python.
#define PY_DECLARE_CLASS(i_cppClass)
Declare a Python class with automatic name and no documentation.
#define PY_CLASS_METHOD_NAME(i_cppClass, i_cppMethod, s_methodName)
Export a C++ method to Python with custom name (no documentation).
#define PY_CLASS_METHOD(i_cppClass, i_cppMethod)
Export a C++ method to Python using the C++ method name (no documentation).
void fetchAndThrowPythonException(std::string loc)
Fetch the current Python exception and throw it as a C++ PythonException.
PyObjectPtr< PyObject >::Type TPyObjPtr
PyObjectPtr to a PyObject.
lass::util::SharedPtr< T, PyObjectStorage, PyObjectCounter > fromNakedToSharedPtrCast(PyObject *object)
fromNakedToSharedPtrCast.
Comprehensive C++ to Python binding library.
Library for Assembled Shared Sources.