resonance 1.0.1
Loading...
Searching...
No Matches
tuple.h
Go to the documentation of this file.
1#pragma once
2
3#include "script/cxx/config.h"
5#include "script/cxx/object.h"
7
8namespace Py {
9
31class Tuple : public SeqBase<Object> {
32public:
44 explicit Tuple(PyObject *pyob) : SeqBase<Object>(pyob) {
45 validate();
46 }
47
59 explicit Tuple(int nSize);
60
70 explicit Tuple(const Object &ob);
71
84 virtual void setItem(int i, const Object &value) {
85 Py_XINCREF(value.mPtr);
86 if (PyTuple_SetItem(mPtr, i, value.mPtr) == -1) {
87 throw Exception();
88 }
89 }
90
99 virtual bool accepts(PyObject *pyob) const {
100 return pyob != nullptr && PyTuple_Check(pyob);
101 }
102};
103
104} // namespace Py
Root of the PyCXX exception hierarchy.
Definition exception.h:19
Reference-counted handle on any Python object, and the root of the PyCXX object hierarchy.
Definition object.h:42
void validate()
Enforce this type's accepts() test on the stored reference.
Definition object.h:237
PyObject * mPtr
Wrapped reference, null only between release() and the next assignment.
Definition object.h:191
SeqBase()
Definition seqbase.h:47
Tuple(const Object &ob)
Take another handle's reference as a tuple.
virtual void setItem(int i, const Object &value)
Write one element.
Definition tuple.h:84
Tuple(int nSize)
Create a tuple of a given length.
Tuple(PyObject *pyob)
Take a borrowed reference to an existing tuple.
Definition tuple.h:44
virtual bool accepts(PyObject *pyob) const
Accept only a tuple.
Definition tuple.h:99
Configuration header of the PyCXX binding layer.
C++ wrappers for the embedded Python interpreter's objects, types, and extension modules.
Definition attributeerror.h:7