43#ifndef LASS_GUARDIAN_OF_INCLUSION_UTIL_PYOBJECT_SPECIAL_METHODS_H
44#define LASS_GUARDIAN_OF_INCLUSION_UTIL_PYOBJECT_SPECIAL_METHODS_H
57 SpecialSlot(
const char* name,
int slot ) : name(name), slot(slot) {}
62 struct UnarySlot :
public SpecialSlot { UnarySlot(
const char* name,
int slot ) : SpecialSlot(name, slot) {} };
63 struct BinarySlot :
public SpecialSlot { BinarySlot(
const char* name,
int slot ) : SpecialSlot(name, slot) {} };
64 struct TernarySlot :
public SpecialSlot { TernarySlot(
const char* name,
int slot ) : SpecialSlot(name, slot) {} };
65 struct LenSlot :
public SpecialSlot { LenSlot(
const char* name,
int slot ) : SpecialSlot(name, slot) {} };
66 struct ComparatorSlot :
public SpecialSlot { ComparatorSlot(
const char* name,
int slot ) : SpecialSlot(name, slot) {} };
67 struct SsizeArgSlot :
public SpecialSlot { SsizeArgSlot(
const char* name,
int slot ) : SpecialSlot(name, slot) {} };
68 struct SsizeSsizeArgSlot :
public SpecialSlot { SsizeSsizeArgSlot(
const char* name,
int slot ) : SpecialSlot(name, slot) {} };
69 struct SsizeObjArgSlot :
public SpecialSlot { SsizeObjArgSlot(
const char* name,
int slot ) : SpecialSlot(name, slot) {} };
70 struct SsizeSsizeObjArgSlot :
public SpecialSlot { SsizeSsizeObjArgSlot(
const char* name,
int slot ) : SpecialSlot(name, slot) {} };
71 struct ObjObjSlot :
public SpecialSlot { ObjObjSlot(
const char* name,
int slot ) : SpecialSlot(name, slot) {} };
72 struct ObjObjArgSlot :
public SpecialSlot { ObjObjArgSlot(
const char* name,
int slot ) : SpecialSlot(name, slot) {} };
73 struct IterSlot :
public SpecialSlot { IterSlot(
const char* name,
int slot ) : SpecialSlot(name, slot) {} };
74 struct IterNextSlot :
public SpecialSlot { IterNextSlot(
const char* name,
int slot ) : SpecialSlot(name, slot) {} };
75 struct ArgKwSlot :
public SpecialSlot { ArgKwSlot(
const char* name,
int slot ) : SpecialSlot(name, slot) {} };
76 struct InquirySlot:
public SpecialSlot { InquirySlot(
const char* name,
int slot ) : SpecialSlot(name, slot) {} };
78 const int charPtrSlot = 1;
79 const int unarySlot = 2;
80 const int binarySlot = 3;
81 const int ternarySlot = 4;
82 const int lenSlot = 5;
83 const int comparatorSlot = 6;
84 const int ssizeArgSlot = 7;
85 const int ssizeSsizeArgSlot = 8;
86 const int ssizeObjArgSlot = 9;
87 const int ssizeSsizeObjArgSlot = 10;
88 const int objObjSlot = 11;
89 const int objObjArgSlot = 12;
90 const int iterSlot = 13;
91 const int iterNextSlot = 14;
92 const int argKwSlot = 15;
93 const int inquirySlot = 16;
96 template<
int value>
struct MetaInt {
volatile const char dummy[value]; };
98 struct IsSpecialSlotTester
100 static MetaInt<charPtrSlot> test(
char *);
101 static MetaInt<charPtrSlot> test(
const char *);
102 static MetaInt<unarySlot> test(
const UnarySlot&);
103 static MetaInt<binarySlot> test(
const BinarySlot&);
104 static MetaInt<ternarySlot> test(
const TernarySlot&);
105 static MetaInt<lenSlot> test(
const LenSlot&);
106 static MetaInt<comparatorSlot> test(
const ComparatorSlot&);
107 static MetaInt<ssizeArgSlot> test(
const SsizeArgSlot&);
108 static MetaInt<ssizeSsizeArgSlot> test(
const SsizeSsizeArgSlot&);
109 static MetaInt<ssizeObjArgSlot> test(
const SsizeObjArgSlot&);
110 static MetaInt<ssizeSsizeObjArgSlot> test(
const SsizeSsizeObjArgSlot&);
111 static MetaInt<objObjSlot> test(
const ObjObjSlot&);
112 static MetaInt<objObjArgSlot> test(
const ObjObjArgSlot&);
113 static MetaInt<iterSlot> test(
const IterSlot&);
114 static MetaInt<iterNextSlot> test(
const IterNextSlot&);
115 static MetaInt<argKwSlot> test(
const ArgKwSlot&);
116 static MetaInt<inquirySlot> test(
const InquirySlot&);
120 struct IsSpecialSlotTesterValue
123 template<>
struct IsSpecialSlotTesterValue<sizeof(MetaInt<charPtrSlot>)> {
typedef char* Type; };
124 template<>
struct IsSpecialSlotTesterValue<sizeof(MetaInt<unarySlot>)> {
typedef UnarySlot Type; };
125 template<>
struct IsSpecialSlotTesterValue<sizeof(MetaInt<binarySlot>)> {
typedef BinarySlot Type; };
126 template<>
struct IsSpecialSlotTesterValue<sizeof(MetaInt<ternarySlot>)> {
typedef TernarySlot Type; };
127 template<>
struct IsSpecialSlotTesterValue<sizeof(MetaInt<lenSlot>)> {
typedef LenSlot Type; };
128 template<>
struct IsSpecialSlotTesterValue<sizeof(MetaInt<comparatorSlot>)> {
typedef ComparatorSlot Type; };
129 template<>
struct IsSpecialSlotTesterValue<sizeof(MetaInt<ssizeArgSlot>)> {
typedef SsizeArgSlot Type; };
130 template<>
struct IsSpecialSlotTesterValue<sizeof(MetaInt<ssizeSsizeArgSlot>)> {
typedef SsizeSsizeArgSlot Type; };
131 template<>
struct IsSpecialSlotTesterValue<sizeof(MetaInt<ssizeObjArgSlot>)> {
typedef SsizeObjArgSlot Type; };
132 template<>
struct IsSpecialSlotTesterValue<sizeof(MetaInt<ssizeSsizeObjArgSlot>)> {
typedef SsizeSsizeObjArgSlot Type; };
133 template<>
struct IsSpecialSlotTesterValue<sizeof(MetaInt<objObjSlot>)> {
typedef ObjObjSlot Type; };
134 template<>
struct IsSpecialSlotTesterValue<sizeof(MetaInt<objObjArgSlot>)> {
typedef ObjObjArgSlot Type; };
135 template<>
struct IsSpecialSlotTesterValue<sizeof(MetaInt<iterSlot>)> {
typedef IterSlot Type; };
136 template<>
struct IsSpecialSlotTesterValue<sizeof(MetaInt<iterNextSlot>)> {
typedef IterNextSlot Type; };
137 template<>
struct IsSpecialSlotTesterValue<sizeof(MetaInt<argKwSlot>)> {
typedef ArgKwSlot Type; };
138 template<>
struct IsSpecialSlotTesterValue<sizeof(MetaInt<inquirySlot>)> {
typedef InquirySlot Type; };
140 #define SPECIAL_SLOT_TYPE( x ) lass::python::impl::IsSpecialSlotTesterValue<sizeof(lass::python::impl::IsSpecialSlotTester::test(x))>::Type
173 const lass::python::impl::ArgKwSlot
_call_(
"__call__", Py_tp_call);
174 const lass::python::impl::UnarySlot
_repr_(
"__repr__", Py_tp_repr);
175 const lass::python::impl::UnarySlot
_str_(
"__str__", Py_tp_str);
179 const lass::python::impl::UnarySlot
_neg_(
"__neg__", Py_nb_negative);
180 const lass::python::impl::UnarySlot
_pos_(
"__pos__", Py_nb_positive);
181 const lass::python::impl::UnarySlot
_abs_(
"__abs__", Py_nb_absolute);
182 const lass::python::impl::UnarySlot
_invert_(
"__invert__", Py_nb_invert);
183 const lass::python::impl::UnarySlot
_int_(
"__int__", Py_nb_int);
184 const lass::python::impl::UnarySlot
_long_(
"__long__", Py_nb_int);
185 const lass::python::impl::UnarySlot
_float_(
"__float__", Py_nb_float);
188 const lass::python::impl::BinarySlot
_add_(
"__add__", Py_nb_add);
189 const lass::python::impl::BinarySlot
_sub_(
"__sub__", Py_nb_subtract);
190 const lass::python::impl::BinarySlot
_mul_(
"__mul__", Py_nb_multiply);
191 const lass::python::impl::BinarySlot
_mod_(
"__mod__", Py_nb_remainder);
192 const lass::python::impl::BinarySlot
_lshift_(
"__lshift__", Py_nb_lshift);
193 const lass::python::impl::BinarySlot
_rshift_(
"__rshift__", Py_nb_rshift);
194 const lass::python::impl::BinarySlot
_and_(
"__and__", Py_nb_and);
195 const lass::python::impl::BinarySlot
_xor_(
"__xor__", Py_nb_xor);
196 const lass::python::impl::BinarySlot
_or_(
"__or__", Py_nb_or);
197 const lass::python::impl::BinarySlot
_iadd_(
"__iadd__", Py_nb_inplace_add);
198 const lass::python::impl::BinarySlot
_isub_(
"__isub__", Py_nb_inplace_subtract);
199 const lass::python::impl::BinarySlot
_imul_(
"__imul__", Py_nb_inplace_multiply);
200 const lass::python::impl::BinarySlot
_imod_(
"__imod__", Py_nb_inplace_remainder);
201 const lass::python::impl::BinarySlot
_ilshift_(
"__ilshift__", Py_nb_inplace_lshift);
202 const lass::python::impl::BinarySlot
_irshift_(
"__irshift__", Py_nb_inplace_rshift);
203 const lass::python::impl::BinarySlot
_iand_(
"__iand__", Py_nb_inplace_and);
204 const lass::python::impl::BinarySlot
_ixor_(
"__ixor__", Py_nb_inplace_xor);
205 const lass::python::impl::BinarySlot
_ior_(
"__ior__", Py_nb_inplace_or);
206 const lass::python::impl::BinarySlot
_truediv_(
"__truediv__", Py_nb_true_divide);
207 const lass::python::impl::BinarySlot
_itruediv_(
"__itruediv__", Py_nb_inplace_true_divide);
208 const lass::python::impl::BinarySlot
_floordiv_(
"__floordiv__", Py_nb_floor_divide);
209 const lass::python::impl::BinarySlot
_ifloordiv_(
"__ifloordiv__", Py_nb_inplace_floor_divide);
210 const lass::python::impl::BinarySlot
_matmul_(
"__matmul__", Py_nb_matrix_multiply);
211 const lass::python::impl::BinarySlot
_imatmul_(
"__imatmul__", Py_nb_inplace_matrix_multiply);
212 const lass::python::impl::InquirySlot
_bool_(
"__bool__", Py_nb_bool);
215 const lass::python::impl::TernarySlot
_pow_(
"__pow__", Py_nb_power);
216 const lass::python::impl::TernarySlot
_ipow_(
"__ipow__", Py_nb_inplace_power);
219 const lass::python::impl::ComparatorSlot
_lt_(
"__lt__", Py_LT);
220 const lass::python::impl::ComparatorSlot
_le_(
"__le__", Py_LE);
221 const lass::python::impl::ComparatorSlot
_eq_(
"__eq__", Py_EQ);
222 const lass::python::impl::ComparatorSlot
_ne_(
"__ne__", Py_NE);
223 const lass::python::impl::ComparatorSlot
_gt_(
"__gt__", Py_GT);
224 const lass::python::impl::ComparatorSlot
_ge_(
"__ge__", Py_GE);
229 const lass::python::impl::LenSlot
_len_(
"__seq_len__", Py_sq_length);
230 const lass::python::impl::SsizeArgSlot
_getitem_(
"__seq_getitem__", Py_sq_item);
231 const lass::python::impl::SsizeObjArgSlot
_setitem_(
"__seq_setitem__", Py_sq_ass_item);
235 const lass::python::impl::LenSlot
seq_len_(
"__seq_len__", Py_sq_length);
236 const lass::python::impl::BinarySlot
_concat_(
"__concat__", Py_sq_concat);
237 const lass::python::impl::SsizeArgSlot
_repeat_(
"__repeat__", Py_sq_repeat);
238 const lass::python::impl::SsizeArgSlot
seq_getitem_(
"__seq_getitem__", Py_sq_item);
239 const lass::python::impl::SsizeObjArgSlot
seq_setitem_(
"__seq_setitem__", Py_sq_ass_item);
240 const lass::python::impl::ObjObjSlot
_contains_(
"__contains__", Py_sq_contains);
241 const lass::python::impl::BinarySlot
_iconcat_(
"__iconcat__", Py_sq_inplace_concat);
242 const lass::python::impl::SsizeArgSlot
_irepeat_(
"__irepeat__", Py_sq_inplace_repeat);
245 const lass::python::impl::LenSlot
map_len_(
"__map_len__", Py_mp_length);
246 const lass::python::impl::BinarySlot
map_getitem_(
"__map_getitem__", Py_mp_subscript);
247 const lass::python::impl::ObjObjArgSlot
map_setitem_(
"__map_setitem__", Py_mp_ass_subscript);
251 const lass::python::impl::IterSlot
_iter_(
"__iter__", Py_tp_iter);
252 const lass::python::impl::IterNextSlot
next(
"__next__", Py_tp_iternext);
const lass::python::impl::BinarySlot _matmul_("__matmul__", Py_nb_matrix_multiply)
__matmul__ method (matrix multiplication)
const lass::python::impl::SsizeArgSlot _irepeat_("__irepeat__", Py_sq_inplace_repeat)
__irepeat__ method (in-place repetition)
const lass::python::impl::BinarySlot _iand_("__iand__", Py_nb_inplace_and)
__iand__ method (in-place bitwise and)
const lass::python::impl::BinarySlot _imul_("__imul__", Py_nb_inplace_multiply)
__imul__ method (in-place multiplication)
const lass::python::impl::SsizeObjArgSlot seq_setitem_("__seq_setitem__", Py_sq_ass_item)
__setitem__ method (set item by index)
const lass::python::impl::BinarySlot _lshift_("__lshift__", Py_nb_lshift)
__lshift__ method (left shift)
const lass::python::impl::UnarySlot _float_("__float__", Py_nb_float)
__float__ method (must return a float)
const lass::python::impl::IterSlot _iter_("__iter__", Py_tp_iter)
__iter__ method (iterator)
const lass::python::impl::ObjObjArgSlot map_delitem_
__delitem__ method (delete item by key, shares same slot as __setitem__)
const lass::python::impl::ComparatorSlot _lt_("__lt__", Py_LT)
__lt__ method (less than)
const lass::python::impl::BinarySlot _imod_("__imod__", Py_nb_inplace_remainder)
__imod__ method (in-place modulus)
const lass::python::impl::BinarySlot _iadd_("__iadd__", Py_nb_inplace_add)
__iadd__ method (in-place addition)
const lass::python::impl::UnarySlot _pos_("__pos__", Py_nb_positive)
__pos__ method (unary positive)
const lass::python::impl::BinarySlot _ixor_("__ixor__", Py_nb_inplace_xor)
__ixor__ method (in-place bitwise xor)
const lass::python::impl::ComparatorSlot _ne_("__ne__", Py_NE)
__ne__ method (not equal)
const lass::python::impl::ComparatorSlot _gt_("__gt__", Py_GT)
__gt__ method (greater than)
const lass::python::impl::SsizeObjArgSlot _setitem_("__seq_setitem__", Py_sq_ass_item)
__setitem__ method (set item by index)
const lass::python::impl::SsizeArgSlot _getitem_("__seq_getitem__", Py_sq_item)
__getitem__ method (get item by index)
const lass::python::impl::UnarySlot _repr_("__repr__", Py_tp_repr)
__repr__ method (must always return a string)
const lass::python::impl::BinarySlot _add_("__add__", Py_nb_add)
__add__ method (binary addition)
const lass::python::impl::BinarySlot _and_("__and__", Py_nb_and)
__and__ method (bitwise and)
const lass::python::impl::BinarySlot _ilshift_("__ilshift__", Py_nb_inplace_lshift)
__ilshift__ method (in-place left shift)
const lass::python::impl::IterNextSlot next("__next__", Py_tp_iternext)
__next__ method (iterator next)
const lass::python::impl::BinarySlot _iconcat_("__iconcat__", Py_sq_inplace_concat)
__iconcat__ method (in-place concatenation)
const lass::python::impl::InquirySlot _bool_("__bool__", Py_nb_bool)
__bool__ method (boolean conversion)
const lass::python::impl::TernarySlot _pow_("__pow__", Py_nb_power)
__pow__ method (exponentiation)
const lass::python::impl::BinarySlot _mul_("__mul__", Py_nb_multiply)
__mul__ method (binary multiplication)
const lass::python::impl::ArgKwSlot _call_("__call__", Py_tp_call)
__call__ method (callable semantics)
const lass::python::impl::BinarySlot _xor_("__xor__", Py_nb_xor)
__xor__ method (bitwise xor)
const lass::python::impl::ObjObjSlot _contains_("__contains__", Py_sq_contains)
__contains__ method (membership test)
const lass::python::impl::BinarySlot _truediv_("__truediv__", Py_nb_true_divide)
__truediv__ method (true division)
const lass::python::impl::ComparatorSlot _eq_("__eq__", Py_EQ)
__eq__ method (equal)
const lass::python::impl::BinarySlot _ior_("__ior__", Py_nb_inplace_or)
__ior__ method (in-place bitwise or)
const lass::python::impl::SsizeArgSlot seq_getitem_("__seq_getitem__", Py_sq_item)
__getitem__ method (get item by index)
const lass::python::impl::BinarySlot _irshift_("__irshift__", Py_nb_inplace_rshift)
__irshift__ method (in-place right shift)
const lass::python::impl::BinarySlot _mod_("__mod__", Py_nb_remainder)
__mod__ method (modulus)
const lass::python::impl::ObjObjArgSlot map_setitem_("__map_setitem__", Py_mp_ass_subscript)
__setitem__ method (set item by key)
const lass::python::impl::UnarySlot _long_("__long__", Py_nb_int)
alias for __int__ method
const lass::python::impl::LenSlot map_len_("__map_len__", Py_mp_length)
__len__ method (length of the mapping)
const lass::python::impl::BinarySlot _imatmul_("__imatmul__", Py_nb_inplace_matrix_multiply)
__imatmul__ method (in-place matrix multiplication)
const lass::python::impl::ComparatorSlot _ge_("__ge__", Py_GE)
__ge__ method (greater than or equal)
const lass::python::impl::BinarySlot _itruediv_("__itruediv__", Py_nb_inplace_true_divide)
__itruediv__ method (in-place true division)
const lass::python::impl::BinarySlot map_getitem_("__map_getitem__", Py_mp_subscript)
__getitem__ method (get item by key)
const lass::python::impl::BinarySlot _or_("__or__", Py_nb_or)
__or__ method (bitwise or)
const lass::python::impl::UnarySlot _abs_("__abs__", Py_nb_absolute)
__abs__ method (absolute value)
const lass::python::impl::ComparatorSlot _le_("__le__", Py_LE)
__le__ method (less than or equal)
const lass::python::impl::LenSlot seq_len_("__seq_len__", Py_sq_length)
__len__ method (length of the sequence)
const lass::python::impl::InquirySlot _nonzero_
alias for __bool__ method
const lass::python::impl::UnarySlot _neg_("__neg__", Py_nb_negative)
__neg__ method (unary negation)
const lass::python::impl::UnarySlot _invert_("__invert__", Py_nb_invert)
__invert__ method (bitwise inversion)
const lass::python::impl::UnarySlot _int_("__int__", Py_nb_int)
__int__ method (must return an integer)
const lass::python::impl::BinarySlot _sub_("__sub__", Py_nb_subtract)
__sub__ method (binary subtraction)
const lass::python::impl::LenSlot _len_("__seq_len__", Py_sq_length)
__len__ method (length of the sequence)
const lass::python::impl::BinarySlot _ifloordiv_("__ifloordiv__", Py_nb_inplace_floor_divide)
__ifloordiv__ method (in-place floor division)
const lass::python::impl::BinarySlot _concat_("__concat__", Py_sq_concat)
__concat__ method (concatenation)
const lass::python::impl::BinarySlot _rshift_("__rshift__", Py_nb_rshift)
__rshift__ method (right shift)
const lass::python::impl::BinarySlot _floordiv_("__floordiv__", Py_nb_floor_divide)
__floordiv__ method (floor division)
const lass::python::impl::BinarySlot _isub_("__isub__", Py_nb_inplace_subtract)
__isub__ method (in-place subtraction)
const lass::python::impl::UnarySlot _str_("__str__", Py_tp_str)
__str__ method (must always return a string)
const lass::python::impl::SsizeArgSlot _repeat_("__repeat__", Py_sq_repeat)
__repeat__ method (repetition)
const lass::python::impl::TernarySlot _ipow_("__ipow__", Py_nb_inplace_power)
__ipow__ method (in-place exponentiation)
Predefined constants for Python special methods (magic methods) that can be used as method names in c...
Comprehensive C++ to Python binding library.
Library for Assembled Shared Sources.