Skip to content

Commit eb52ed7

Browse files
Add SQ_CONTAINS slot macro
1 parent c8fa02e commit eb52ed7

File tree

13 files changed

+291
-620
lines changed

13 files changed

+291
-620
lines changed

src/interface/shared/containers.i

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,8 @@ MP_ASS_SUBSCRIPT(Exiv2::base_class, PyObject*,
9797
if (pos == self->end())
9898
return PyErr_Format(PyExc_KeyError, "'%s'", key);
9999
self->erase(pos))
100-
%feature("python:slot", "sq_contains", functype="objobjproc")
101-
Exiv2::base_class::__contains__;
102-
%extend Exiv2::base_class {
103-
%fragment("get_type_id"{Exiv2::datum_type});
104-
bool __contains__(const std::string& key) {
105-
return $self->findKey(Exiv2::key_type(key)) != $self->end();
106-
}
107-
}
100+
SQ_CONTAINS(
101+
Exiv2::base_class, self->findKey(Exiv2::key_type(key)) != self->end())
108102

109103
%extend Exiv2::datum_type {
110104
%fragment("set_value_from_py"{Exiv2::datum_type});

src/interface/shared/slots.i

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,23 @@ static int __setitem__%mangle(type)_closure(
136136
%enddef // SQ_ASS_ITEM
137137

138138

139+
// Macro to add sq_contains slot and function
140+
%define SQ_CONTAINS(type, func)
141+
%fragment("__contains__"{type}, "header") {
142+
static int __contains__%mangle(type)(PyObject* py_self, PyObject* py_key) {
143+
type* self;
144+
SWIG_ConvertPtr(py_self, (void**)&self, $descriptor(type*), 0);
145+
const char* key = PyUnicode_AsUTF8(py_key);
146+
if (!key)
147+
return -1;
148+
return func ? 1 : 0;
149+
};
150+
}
151+
%fragment("__contains__"{type});
152+
%feature("python:sq_contains") type QUOTE(__contains__%mangle(type));
153+
%enddef // SQ_CONTAINS
154+
155+
139156
// Macro to add sq_length slot and function
140157
%define SQ_LENGTH(type, func)
141158
%fragment("__len__"{type}, "header") {

src/interface/value.i

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,16 +368,15 @@ MP_ASS_SUBSCRIPT(Exiv2::LangAltValue, std::string, self->value_[key] = value,
368368
return PyErr_Format(PyExc_KeyError, "'%s'", key);
369369
self->value_.erase(pos);
370370
})
371-
%feature("python:slot", "sq_contains", functype="objobjproc")
372-
Exiv2::LangAltValue::__contains__;
371+
SQ_CONTAINS(
372+
Exiv2::LangAltValue, self->value_.find(key) != self->value_.end())
373373
%feature("docstring") Exiv2::LangAltValue::keys
374374
"Get keys (i.e. languages) of the LangAltValue components."
375375
%feature("docstring") Exiv2::LangAltValue::values
376376
"Get values (i.e. text strings) of the LangAltValue components."
377377
%feature("docstring") Exiv2::LangAltValue::items
378378
"Get key, value pairs (i.e. language, text) of the LangAltValue
379379
components."
380-
%noexception Exiv2::LangAltValue::__contains__;
381380
%noexception Exiv2::LangAltValue::__iter__;
382381
%noexception Exiv2::LangAltValue::keys;
383382
%noexception Exiv2::LangAltValue::items;
@@ -416,9 +415,6 @@ components."
416415
Py_DECREF(keys);
417416
return result;
418417
}
419-
bool __contains__(const std::string& key) {
420-
return $self->value_.find(key) != $self->value_.end();
421-
}
422418
}
423419

424420
// Add Python slots to Exiv2::Value base class

src/swig-0_27_7/exif_wrap.cxx

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5425,6 +5425,16 @@ static int __setitem__Exiv2_ExifData_closure(
54255425
return 0;
54265426
};
54275427

5428+
5429+
static int __contains__Exiv2_ExifData(PyObject* py_self, PyObject* py_key) {
5430+
Exiv2::ExifData* self;
5431+
SWIG_ConvertPtr(py_self, (void**)&self, SWIGTYPE_p_Exiv2__ExifData, 0);
5432+
const char* key = PyUnicode_AsUTF8(py_key);
5433+
if (!key)
5434+
return -1;
5435+
return self->findKey(Exiv2::ExifKey(key)) != self->end() ? 1 : 0;
5436+
};
5437+
54285438
SWIGINTERN bool Exiv2_Exifdatum_operator_Se__Se_(Exiv2::Exifdatum const *self,Exiv2::Exifdatum const &other){
54295439
return &other == self;
54305440
}
@@ -5600,9 +5610,6 @@ SWIG_AsVal_unsigned_SS_short (PyObject * obj, unsigned short *val)
56005610
return res;
56015611
}
56025612

5603-
SWIGINTERN bool Exiv2_ExifData___contains__(Exiv2::ExifData *self,std::string const &key){
5604-
return self->findKey(Exiv2::ExifKey(key)) != self->end();
5605-
}
56065613
#ifdef __cplusplus
56075614
extern "C" {
56085615
#endif
@@ -9957,51 +9964,6 @@ SWIGINTERN PyObject *_wrap_ExifData_count(PyObject *self, PyObject *args) {
99579964
}
99589965

99599966

9960-
SWIGINTERN PyObject *_wrap_ExifData___contains__(PyObject *self, PyObject *args) {
9961-
PyObject *resultobj = 0;
9962-
Exiv2::ExifData *arg1 = (Exiv2::ExifData *) 0 ;
9963-
std::string *arg2 = 0 ;
9964-
void *argp1 = 0 ;
9965-
int res1 = 0 ;
9966-
int res2 = SWIG_OLDOBJ ;
9967-
PyObject * obj1 = 0 ;
9968-
bool result;
9969-
9970-
if (!PyArg_UnpackTuple(args, "ExifData___contains__", 1, 1, &obj1)) SWIG_fail;
9971-
res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_Exiv2__ExifData, 0 | 0 );
9972-
if (!SWIG_IsOK(res1)) {
9973-
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ExifData___contains__" "', argument " "1"" of type '" "Exiv2::ExifData *""'");
9974-
}
9975-
arg1 = reinterpret_cast< Exiv2::ExifData * >(argp1);
9976-
{
9977-
std::string *ptr = (std::string *)0;
9978-
res2 = SWIG_AsPtr_std_string(obj1, &ptr);
9979-
if (!SWIG_IsOK(res2)) {
9980-
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ExifData___contains__" "', argument " "2"" of type '" "std::string const &""'");
9981-
}
9982-
if (!ptr) {
9983-
SWIG_exception_fail(SWIG_NullReferenceError, "invalid null reference " "in method '" "ExifData___contains__" "', argument " "2"" of type '" "std::string const &""'");
9984-
}
9985-
arg2 = ptr;
9986-
}
9987-
{
9988-
try {
9989-
result = (bool)Exiv2_ExifData___contains__(arg1,(std::string const &)*arg2);
9990-
}
9991-
catch(std::exception const& e) {
9992-
_set_python_exception();
9993-
SWIG_fail;
9994-
}
9995-
}
9996-
resultobj = SWIG_From_bool(static_cast< bool >(result));
9997-
if (SWIG_IsNewObj(res2)) delete arg2;
9998-
return resultobj;
9999-
fail:
10000-
if (SWIG_IsNewObj(res2)) delete arg2;
10001-
return NULL;
10002-
}
10003-
10004-
100059967
SWIGINTERN int _wrap_new_ExifData(PyObject *self, PyObject *args, PyObject *kwargs) {
100069968
PyObject *resultobj = 0;
100079969
Exiv2::ExifData *result = 0 ;
@@ -10056,8 +10018,6 @@ SWIGPY_GETITERFUNC_CLOSURE(_wrap_ExifData_begin) /* defines _wrap_ExifData_begin
1005610018

1005710019
SWIGPY_LENFUNC_CLOSURE(_wrap_ExifData_count) /* defines _wrap_ExifData_count_lenfunc_closure */
1005810020

10059-
SWIGPY_OBJOBJPROC_CLOSURE(_wrap_ExifData___contains__) /* defines _wrap_ExifData___contains___objobjproc_closure */
10060-
1006110021
SWIGPY_DESTRUCTOR_CLOSURE(_wrap_delete_ExifData) /* defines _wrap_delete_ExifData_destructor_closure */
1006210022

1006310023
static PyMethodDef SwigMethods[] = {
@@ -12629,7 +12589,6 @@ SWIGINTERN PyMethodDef SwigPyBuiltin__Exiv2__ExifData_methods[] = {
1262912589
"" },
1263012590
{ "empty", _wrap_ExifData_empty, METH_VARARGS, "Return true if there is no Exif metadata" },
1263112591
{ "count", _wrap_ExifData_count, METH_VARARGS, "Get the number of metadata entries" },
12632-
{ "__contains__", _wrap_ExifData___contains__, METH_VARARGS, "" },
1263312592
{ NULL, NULL, 0, NULL } /* Sentinel */
1263412593
};
1263512594

@@ -12822,7 +12781,7 @@ static PyHeapTypeObject SwigPyBuiltin__Exiv2__ExifData_type = {
1282212781
#else
1282312782
(ssizessizeobjargproc) 0, /* sq_ass_slice */
1282412783
#endif
12825-
_wrap_ExifData___contains___objobjproc_closure, /* sq_contains */
12784+
__contains__Exiv2_ExifData, /* sq_contains */
1282612785
(binaryfunc) 0, /* sq_inplace_concat */
1282712786
(ssizeargfunc) 0, /* sq_inplace_repeat */
1282812787
},
@@ -12957,7 +12916,7 @@ static PyTypeObject *SwigPyBuiltin__Exiv2__ExifData_type_create(PyTypeObject *ty
1295712916
{ Py_sq_repeat, (void *)(ssizeargfunc) 0 },
1295812917
{ Py_sq_item, (void *)(ssizeargfunc) 0 },
1295912918
{ Py_sq_ass_item, (void *)(ssizeobjargproc) 0 },
12960-
{ Py_sq_contains, (void *)_wrap_ExifData___contains___objobjproc_closure },
12919+
{ Py_sq_contains, (void *)__contains__Exiv2_ExifData },
1296112920
{ Py_sq_inplace_concat, (void *)(binaryfunc) 0 },
1296212921
{ Py_sq_inplace_repeat, (void *)(ssizeargfunc) 0 },
1296312922
{ Py_tp_members, members },

src/swig-0_27_7/iptc_wrap.cxx

Lines changed: 12 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -5418,6 +5418,16 @@ static int __setitem__Exiv2_IptcData_closure(
54185418
return 0;
54195419
};
54205420

5421+
5422+
static int __contains__Exiv2_IptcData(PyObject* py_self, PyObject* py_key) {
5423+
Exiv2::IptcData* self;
5424+
SWIG_ConvertPtr(py_self, (void**)&self, SWIGTYPE_p_Exiv2__IptcData, 0);
5425+
const char* key = PyUnicode_AsUTF8(py_key);
5426+
if (!key)
5427+
return -1;
5428+
return self->findKey(Exiv2::IptcKey(key)) != self->end() ? 1 : 0;
5429+
};
5430+
54215431
SWIGINTERN bool Exiv2_Iptcdatum_operator_Se__Se_(Exiv2::Iptcdatum const *self,Exiv2::Iptcdatum const &other){
54225432
return &other == self;
54235433
}
@@ -5513,36 +5523,6 @@ SWIG_AsVal_unsigned_SS_short (PyObject * obj, unsigned short *val)
55135523
return res;
55145524
}
55155525

5516-
5517-
SWIGINTERN int
5518-
SWIG_AsPtr_std_string (PyObject * obj, std::string **val)
5519-
{
5520-
char* buf = 0 ; size_t size = 0; int alloc = SWIG_OLDOBJ;
5521-
if (SWIG_IsOK((SWIG_AsCharPtrAndSize(obj, &buf, &size, &alloc)))) {
5522-
if (buf) {
5523-
if (val) *val = new std::string(buf, size - 1);
5524-
if (alloc == SWIG_NEWOBJ) delete[] buf;
5525-
return SWIG_NEWOBJ;
5526-
} else {
5527-
if (val) *val = 0;
5528-
return SWIG_OLDOBJ;
5529-
}
5530-
} else {
5531-
PyErr_Clear();
5532-
static swig_type_info *descriptor = SWIG_TypeQuery("std::string" " *");
5533-
if (descriptor) {
5534-
std::string *vptr;
5535-
int res = SWIG_ConvertPtr(obj, (void**)&vptr, descriptor, 0);
5536-
if (SWIG_IsOK(res) && val) *val = vptr;
5537-
return res;
5538-
}
5539-
}
5540-
return SWIG_ERROR;
5541-
}
5542-
5543-
SWIGINTERN bool Exiv2_IptcData___contains__(Exiv2::IptcData *self,std::string const &key){
5544-
return self->findKey(Exiv2::IptcKey(key)) != self->end();
5545-
}
55465526
#ifdef __cplusplus
55475527
extern "C" {
55485528
#endif
@@ -9101,51 +9081,6 @@ SWIGINTERN PyObject *_wrap_IptcData_detectCharset(PyObject *self, PyObject *args
91019081
}
91029082

91039083

9104-
SWIGINTERN PyObject *_wrap_IptcData___contains__(PyObject *self, PyObject *args) {
9105-
PyObject *resultobj = 0;
9106-
Exiv2::IptcData *arg1 = (Exiv2::IptcData *) 0 ;
9107-
std::string *arg2 = 0 ;
9108-
void *argp1 = 0 ;
9109-
int res1 = 0 ;
9110-
int res2 = SWIG_OLDOBJ ;
9111-
PyObject * obj1 = 0 ;
9112-
bool result;
9113-
9114-
if (!PyArg_UnpackTuple(args, "IptcData___contains__", 1, 1, &obj1)) SWIG_fail;
9115-
res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_Exiv2__IptcData, 0 | 0 );
9116-
if (!SWIG_IsOK(res1)) {
9117-
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "IptcData___contains__" "', argument " "1"" of type '" "Exiv2::IptcData *""'");
9118-
}
9119-
arg1 = reinterpret_cast< Exiv2::IptcData * >(argp1);
9120-
{
9121-
std::string *ptr = (std::string *)0;
9122-
res2 = SWIG_AsPtr_std_string(obj1, &ptr);
9123-
if (!SWIG_IsOK(res2)) {
9124-
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "IptcData___contains__" "', argument " "2"" of type '" "std::string const &""'");
9125-
}
9126-
if (!ptr) {
9127-
SWIG_exception_fail(SWIG_NullReferenceError, "invalid null reference " "in method '" "IptcData___contains__" "', argument " "2"" of type '" "std::string const &""'");
9128-
}
9129-
arg2 = ptr;
9130-
}
9131-
{
9132-
try {
9133-
result = (bool)Exiv2_IptcData___contains__(arg1,(std::string const &)*arg2);
9134-
}
9135-
catch(std::exception const& e) {
9136-
_set_python_exception();
9137-
SWIG_fail;
9138-
}
9139-
}
9140-
resultobj = SWIG_From_bool(static_cast< bool >(result));
9141-
if (SWIG_IsNewObj(res2)) delete arg2;
9142-
return resultobj;
9143-
fail:
9144-
if (SWIG_IsNewObj(res2)) delete arg2;
9145-
return NULL;
9146-
}
9147-
9148-
91499084
SWIGINTERN int _wrap_new_IptcData(PyObject *self, PyObject *args, PyObject *kwargs) {
91509085
PyObject *resultobj = 0;
91519086
Exiv2::IptcData *result = 0 ;
@@ -9200,8 +9135,6 @@ SWIGPY_GETITERFUNC_CLOSURE(_wrap_IptcData_begin) /* defines _wrap_IptcData_begin
92009135

92019136
SWIGPY_LENFUNC_CLOSURE(_wrap_IptcData_count) /* defines _wrap_IptcData_count_lenfunc_closure */
92029137

9203-
SWIGPY_OBJOBJPROC_CLOSURE(_wrap_IptcData___contains__) /* defines _wrap_IptcData___contains___objobjproc_closure */
9204-
92059138
SWIGPY_DESTRUCTOR_CLOSURE(_wrap_delete_IptcData) /* defines _wrap_delete_IptcData_destructor_closure */
92069139

92079140
static PyMethodDef SwigMethods[] = {
@@ -10874,7 +10807,6 @@ SWIGINTERN PyMethodDef SwigPyBuiltin__Exiv2__IptcData_methods[] = {
1087410807
{ "count", _wrap_IptcData_count, METH_VARARGS, "Get the number of metadata entries" },
1087510808
{ "size", _wrap_IptcData_size, METH_VARARGS, "Return the exact size of all contained IPTC metadata" },
1087610809
{ "detectCharset", _wrap_IptcData_detectCharset, METH_VARARGS, "Return the metadata charset name or 0" },
10877-
{ "__contains__", _wrap_IptcData___contains__, METH_VARARGS, "" },
1087810810
{ NULL, NULL, 0, NULL } /* Sentinel */
1087910811
};
1088010812

@@ -11066,7 +10998,7 @@ static PyHeapTypeObject SwigPyBuiltin__Exiv2__IptcData_type = {
1106610998
#else
1106710999
(ssizessizeobjargproc) 0, /* sq_ass_slice */
1106811000
#endif
11069-
_wrap_IptcData___contains___objobjproc_closure, /* sq_contains */
11001+
__contains__Exiv2_IptcData, /* sq_contains */
1107011002
(binaryfunc) 0, /* sq_inplace_concat */
1107111003
(ssizeargfunc) 0, /* sq_inplace_repeat */
1107211004
},
@@ -11200,7 +11132,7 @@ static PyTypeObject *SwigPyBuiltin__Exiv2__IptcData_type_create(PyTypeObject *ty
1120011132
{ Py_sq_repeat, (void *)(ssizeargfunc) 0 },
1120111133
{ Py_sq_item, (void *)(ssizeargfunc) 0 },
1120211134
{ Py_sq_ass_item, (void *)(ssizeobjargproc) 0 },
11203-
{ Py_sq_contains, (void *)_wrap_IptcData___contains___objobjproc_closure },
11135+
{ Py_sq_contains, (void *)__contains__Exiv2_IptcData },
1120411136
{ Py_sq_inplace_concat, (void *)(binaryfunc) 0 },
1120511137
{ Py_sq_inplace_repeat, (void *)(ssizeargfunc) 0 },
1120611138
{ Py_tp_members, members },

0 commit comments

Comments
 (0)