Skip to content

Commit 42c0863

Browse files
Add a helper function for str(metadatum)
1 parent 23a511a commit 42c0863

10 files changed

Lines changed: 58 additions & 11 deletions

File tree

src/interface/metadatum.i

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,19 @@ EXTEND_KEY(Exiv2::Key);
5757
DEPRECATE_FUNCTION(Exiv2::Metadatum::copy, true)
5858
DEPRECATE_FUNCTION(Exiv2::Metadatum::write, true)
5959

60+
%fragment("metadatum_str", "header") {
61+
static std::string metadatum_str(Exiv2::Metadatum* datum) {
62+
return datum->key() + ": " + datum->print();
63+
};
64+
}
65+
6066
// Extend base type
6167
%feature("python:slot", "tp_str", functype="reprfunc")
6268
Exiv2::Metadatum::__str__;
6369
%extend Exiv2::Metadatum {
70+
%fragment("metadatum_str");
6471
std::string __str__() {
65-
return $self->key() + ": " + $self->print();
72+
return metadatum_str(self);
6673
}
6774
}
6875

src/interface/shared/metadatum_wrappers.i

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class datum_type##_reference;
3232
%}
3333
%enddef // DECLARE_METADATUM_WRAPPERS
3434

35-
3635
// Macro to wrap metadatum iterators and pointers
3736
%define METADATUM_WRAPPERS(container_type, datum_type)
3837

@@ -50,6 +49,7 @@ POINTER_STORE(container_type, datum_type)
5049
%ignore datum_type##_pointer::operator*;
5150
%ignore datum_type##_pointer::size;
5251
%ignore datum_type##_pointer::_invalidate;
52+
%fragment("metadatum_str");
5353
%inline %{
5454
class datum_type##_pointer {
5555
protected:
@@ -71,7 +71,7 @@ public:
7171
Exiv2::datum_type* ptr = **this;
7272
if (!ptr)
7373
return name + "<data end>";
74-
return name + "<" + ptr->key() + ": " + ptr->print() + ">";
74+
return name + "<" + metadatum_str(ptr) + ">";
7575
}
7676
// Provide size() C++ method for buffer size check
7777
size_t size() {

src/swig-0_27_7/exif_wrap.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4375,6 +4375,11 @@ static void _set_python_exception() {
43754375
#endif
43764376

43774377

4378+
static std::string metadatum_str(Exiv2::Metadatum* datum) {
4379+
return datum->key() + ": " + datum->print();
4380+
};
4381+
4382+
43784383
class Exifdatum_pointer {
43794384
protected:
43804385
bool invalidated;
@@ -4395,7 +4400,7 @@ class Exifdatum_pointer {
43954400
Exiv2::Exifdatum* ptr = **this;
43964401
if (!ptr)
43974402
return name + "<data end>";
4398-
return name + "<" + ptr->key() + ": " + ptr->print() + ">";
4403+
return name + "<" + metadatum_str(ptr) + ">";
43994404
}
44004405
// Provide size() C++ method for buffer size check
44014406
size_t size() {

src/swig-0_27_7/iptc_wrap.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4368,6 +4368,11 @@ static void _set_python_exception() {
43684368
};
43694369

43704370

4371+
static std::string metadatum_str(Exiv2::Metadatum* datum) {
4372+
return datum->key() + ": " + datum->print();
4373+
};
4374+
4375+
43714376
class Iptcdatum_pointer {
43724377
protected:
43734378
bool invalidated;
@@ -4388,7 +4393,7 @@ class Iptcdatum_pointer {
43884393
Exiv2::Iptcdatum* ptr = **this;
43894394
if (!ptr)
43904395
return name + "<data end>";
4391-
return name + "<" + ptr->key() + ": " + ptr->print() + ">";
4396+
return name + "<" + metadatum_str(ptr) + ">";
43924397
}
43934398
// Provide size() C++ method for buffer size check
43944399
size_t size() {

src/swig-0_27_7/metadatum_wrap.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4378,6 +4378,11 @@ SWIG_From_unsigned_SS_short (unsigned short value)
43784378
}
43794379

43804380

4381+
static std::string metadatum_str(Exiv2::Metadatum* datum) {
4382+
return datum->key() + ": " + datum->print();
4383+
};
4384+
4385+
43814386
/* Return string from Python obj. NOTE: obj must remain in scope in order
43824387
to use the returned cptr (but only when alloc is set to SWIG_OLDOBJ) */
43834388
SWIGINTERN int
@@ -5273,7 +5278,7 @@ static int private_store_del(PyObject* py_self, const char* name) {
52735278
};
52745279

52755280
SWIGINTERN std::string Exiv2_Metadatum___str__(Exiv2::Metadatum *self){
5276-
return self->key() + ": " + self->print();
5281+
return metadatum_str(self);
52775282
}
52785283
#ifdef __cplusplus
52795284
extern "C" {

src/swig-0_27_7/xmp_wrap.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4370,6 +4370,11 @@ static void _set_python_exception() {
43704370
};
43714371

43724372

4373+
static std::string metadatum_str(Exiv2::Metadatum* datum) {
4374+
return datum->key() + ": " + datum->print();
4375+
};
4376+
4377+
43734378
class Xmpdatum_pointer {
43744379
protected:
43754380
bool invalidated;
@@ -4390,7 +4395,7 @@ class Xmpdatum_pointer {
43904395
Exiv2::Xmpdatum* ptr = **this;
43914396
if (!ptr)
43924397
return name + "<data end>";
4393-
return name + "<" + ptr->key() + ": " + ptr->print() + ">";
4398+
return name + "<" + metadatum_str(ptr) + ">";
43944399
}
43954400
// Provide size() C++ method for buffer size check
43964401
size_t size() {

src/swig-0_28_5/exif_wrap.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4375,6 +4375,11 @@ static void _set_python_exception() {
43754375
#endif
43764376

43774377

4378+
static std::string metadatum_str(Exiv2::Metadatum* datum) {
4379+
return datum->key() + ": " + datum->print();
4380+
};
4381+
4382+
43784383
class Exifdatum_pointer {
43794384
protected:
43804385
bool invalidated;
@@ -4395,7 +4400,7 @@ class Exifdatum_pointer {
43954400
Exiv2::Exifdatum* ptr = **this;
43964401
if (!ptr)
43974402
return name + "<data end>";
4398-
return name + "<" + ptr->key() + ": " + ptr->print() + ">";
4403+
return name + "<" + metadatum_str(ptr) + ">";
43994404
}
44004405
// Provide size() C++ method for buffer size check
44014406
size_t size() {

src/swig-0_28_5/iptc_wrap.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4368,6 +4368,11 @@ static void _set_python_exception() {
43684368
};
43694369

43704370

4371+
static std::string metadatum_str(Exiv2::Metadatum* datum) {
4372+
return datum->key() + ": " + datum->print();
4373+
};
4374+
4375+
43714376
class Iptcdatum_pointer {
43724377
protected:
43734378
bool invalidated;
@@ -4388,7 +4393,7 @@ class Iptcdatum_pointer {
43884393
Exiv2::Iptcdatum* ptr = **this;
43894394
if (!ptr)
43904395
return name + "<data end>";
4391-
return name + "<" + ptr->key() + ": " + ptr->print() + ">";
4396+
return name + "<" + metadatum_str(ptr) + ">";
43924397
}
43934398
// Provide size() C++ method for buffer size check
43944399
size_t size() {

src/swig-0_28_5/metadatum_wrap.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4378,6 +4378,11 @@ SWIG_From_unsigned_SS_short (unsigned short value)
43784378
}
43794379

43804380

4381+
static std::string metadatum_str(Exiv2::Metadatum* datum) {
4382+
return datum->key() + ": " + datum->print();
4383+
};
4384+
4385+
43814386
/* Return string from Python obj. NOTE: obj must remain in scope in order
43824387
to use the returned cptr (but only when alloc is set to SWIG_OLDOBJ) */
43834388
SWIGINTERN int
@@ -5435,7 +5440,7 @@ static int private_store_del(PyObject* py_self, const char* name) {
54355440
};
54365441

54375442
SWIGINTERN std::string Exiv2_Metadatum___str__(Exiv2::Metadatum *self){
5438-
return self->key() + ": " + self->print();
5443+
return metadatum_str(self);
54395444
}
54405445
#ifdef __cplusplus
54415446
extern "C" {

src/swig-0_28_5/xmp_wrap.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4370,6 +4370,11 @@ static void _set_python_exception() {
43704370
};
43714371

43724372

4373+
static std::string metadatum_str(Exiv2::Metadatum* datum) {
4374+
return datum->key() + ": " + datum->print();
4375+
};
4376+
4377+
43734378
class Xmpdatum_pointer {
43744379
protected:
43754380
bool invalidated;
@@ -4390,7 +4395,7 @@ class Xmpdatum_pointer {
43904395
Exiv2::Xmpdatum* ptr = **this;
43914396
if (!ptr)
43924397
return name + "<data end>";
4393-
return name + "<" + ptr->key() + ": " + ptr->print() + ">";
4398+
return name + "<" + metadatum_str(ptr) + ">";
43944399
}
43954400
// Provide size() C++ method for buffer size check
43964401
size_t size() {

0 commit comments

Comments
 (0)