@@ -36,6 +36,9 @@ class datum_type##_reference;
3636// Macro to wrap metadatum iterators and pointers
3737%define METADATUM_WRAPPERS (container_type, datum_type)
3838
39+ // Keep a reference to any object that returns a reference to a datum.
40+ KEEP_REFERENCE(Exiv2::datum_type&)
41+
3942// Invalidate pointers when data is deleted
4043POINTER_STORE(container_type, datum_type)
4144
@@ -158,6 +161,31 @@ public:
158161 }
159162};
160163%}
164+
165+ // Metadata reference wrapper
166+ %ignore datum_type##_reference::##datum_type##_reference;
167+ %ignore datum_type##_reference::operator *;
168+ %feature(" docstring" ) datum_type##_reference "
169+ Python wrapper for an :class:`" #datum_type " ` reference. It has most of
170+ the methods of :class:`" #datum_type " ` allowing easy access to the
171+ data it points to."
172+ %inline %{
173+ class datum_type ##_reference: public datum_type##_pointer {
174+ private:
175+ Exiv2::datum_type* ptr;
176+ public:
177+ datum_type##_reference(Exiv2::datum_type* ptr): ptr(ptr) {
178+ name = " pointer" ;
179+ }
180+ Exiv2::datum_type* operator *() const {
181+ if (invalidated)
182+ throw std::runtime_error (" datum_type reference is invalid" );
183+ return ptr;
184+ }
185+ };
186+ %}
187+
188+ // typemaps
161189%typemap(in) Exiv2::container_type::iterator
162190 (container_type##_iterator *argp=NULL ) %{
163191 {
@@ -178,6 +206,15 @@ public:
178206 it = argp->_ptr ();
179207 $1 = ⁢
180208}
209+ %typemap(in) const Exiv2::datum_type& {
210+ datum_type##_pointer* tmp = NULL ;
211+ if (SWIG_IsOK (SWIG_ConvertPtr (
212+ $input, (void **)&tmp, $descriptor (datum_type##_pointer*), 0 )))
213+ $1 = **tmp;
214+ else {
215+ $typemap (in, Exiv2::datum_type&)
216+ }
217+ }
181218%typemap(out) Exiv2::container_type::iterator {
182219 $result = SWIG_NewPointerObj (
183220 SWIG_as_voidptr (new container_type##_iterator ($1 , arg1->end ())),
@@ -189,40 +226,6 @@ public:
189226 }
190227#endif // SWIG_VERSION
191228}
192-
193- // Metadata reference wrapper
194- %ignore datum_type##_reference::##datum_type##_reference;
195- %ignore datum_type##_reference::operator *;
196- %feature(" docstring" ) datum_type##_reference "
197- Python wrapper for an :class:`" #datum_type " ` reference. It has most of
198- the methods of :class:`" #datum_type " ` allowing easy access to the
199- data it points to."
200- // Keep a reference to the data being referred to
201- KEEP_REFERENCE (Exiv2::datum_type&)
202- %inline %{
203- class datum_type ##_reference: public datum_type##_pointer {
204- private:
205- Exiv2::datum_type* ptr;
206- public:
207- datum_type##_reference(Exiv2::datum_type* ptr): ptr(ptr) {
208- name = " pointer" ;
209- }
210- Exiv2::datum_type* operator *() const {
211- if (invalidated)
212- throw std::runtime_error (" datum_type reference is invalid" );
213- return ptr;
214- }
215- };
216- %}
217- %typemap(in) const Exiv2::datum_type& {
218- datum_type##_reference* tmp = NULL ;
219- if (SWIG_IsOK (SWIG_ConvertPtr (
220- $input, (void **)&tmp, $descriptor (datum_type##_reference*), 0 )))
221- $1 = **tmp;
222- else {
223- $typemap (in, Exiv2::datum_type&)
224- }
225- }
226229%typemap(out) Exiv2::datum_type& {
227230 $result = SWIG_NewPointerObj (
228231 SWIG_as_voidptr (new datum_type##_reference ($1 )),
@@ -235,4 +238,41 @@ public:
235238#endif // SWIG_VERSION
236239}
237240
241+ // Deprecate some methods since 2025-08-25
242+ DEPRECATE_FUNCTION (Exiv2::datum_type::copy, true )
243+ DEPRECATE_FUNCTION(Exiv2::datum_type::write, true )
244+ // Ignore overloaded default parameter version
245+ %ignore Exiv2::datum_type::write(std::ostream &) const ;
246+
247+ // Extend datum type
248+ %extend Exiv2::datum_type {
249+ bool operator ==(const Exiv2::datum_type &other) const {
250+ return &other == self;
251+ }
252+ bool operator !=(const Exiv2::datum_type &other) const {
253+ return &other != self;
254+ }
255+ // Extend Metadatum to allow getting value as a specific type.
256+ Exiv2::Value::SMART_PTR getValue (Exiv2::TypeId as_type) {
257+ // deprecated since 2023-12-07
258+ PyErr_WarnEx (PyExc_DeprecationWarning, " Requested type ignored." , 1 );
259+ return $self->getValue ();
260+ }
261+ const Exiv2::Value& value (Exiv2::TypeId as_type) {
262+ // deprecated since 2023-12-07
263+ PyErr_WarnEx (PyExc_DeprecationWarning, " Requested type ignored." , 1 );
264+ return $self->value ();
265+ }
266+ // Old _print method for compatibility
267+ std::string _print (const Exiv2::ExifData* pMetadata) const {
268+ // deprecated since 2024-01-29
269+ PyErr_WarnEx (PyExc_DeprecationWarning,
270+ " '_print' has been replaced by 'print'" , 1 );
271+ return $self->print (pMetadata);
272+ }
273+ // toString parameter does not default to 0, so bypass default typemap
274+ std::string toString () const { return self->toString (); }
275+ std::string toString (BUFLEN_T i) const { return self->toString (i); }
276+ }
277+
238278%enddef // METADATUM_WRAPPERS
0 commit comments