diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2012-01-16 20:06:53 +0100 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2012-01-16 20:06:53 +0100 |
commit | 8991499cce204188a38ffe25f1251e5a1a0965c3 (patch) | |
tree | 57f6e322a1ba44221958bb12d8ca65e33a84fb52 | |
parent | ca653b9fdd7469bfcfd4be393342963f3522f0e2 (diff) | |
download | pyexiv2-8991499cce204188a38ffe25f1251e5a1a0965c3.tar.gz |
Simplify and optimize ExifTag::setParentImage(…) and XmpTag::setParentImage(…)
by re-setting the value of the datum to a copy of the existing datum’s value.
This also fixes setting the value of an XMP tag of type array to [''] (this issue was uncovered by Benjamin Henne, see http://dev.exiv2.org/boards/3/topics/1039 for details).
Unfortunately this can’t easily be transposed to IptcTag::setParentImage(…) due to implementation details.
-rw-r--r-- | src/exiv2wrapper.cpp | 47 |
1 files changed, 8 insertions, 39 deletions
diff --git a/src/exiv2wrapper.cpp b/src/exiv2wrapper.cpp index 332b78f..8e7c3d4 100644 --- a/src/exiv2wrapper.cpp +++ b/src/exiv2wrapper.cpp @@ -1,6 +1,6 @@ // ***************************************************************************** /* - * Copyright (C) 2006-2011 Olivier Tilloy <olivier@tilloy.net> + * Copyright (C) 2006-2012 Olivier Tilloy <olivier@tilloy.net> * * This file is part of the pyexiv2 distribution. * @@ -616,10 +616,10 @@ void ExifTag::setParentImage(Image& image) return; } _data = data; - std::string value = _datum->toString(); + Exiv2::Value::AutoPtr value = _datum->getValue(); delete _datum; _datum = &(*_data)[_key.key()]; - _datum->setValue(value); + _datum->setValue(value.get()); _byteOrder = image.getByteOrder(); } @@ -955,42 +955,11 @@ void XmpTag::setParentImage(Image& image) // anything (see https://bugs.launchpad.net/pyexiv2/+bug/622739). return; } - switch (Exiv2::XmpProperties::propertyType(_key)) - { - case Exiv2::xmpText: - { - const std::string value = getTextValue(); - delete _datum; - _from_datum = true; - _datum = &(*image.getXmpData())[_key.key()]; - setTextValue(value); - break; - } - case Exiv2::xmpAlt: - case Exiv2::xmpBag: - case Exiv2::xmpSeq: - { - const boost::python::list value = getArrayValue(); - delete _datum; - _from_datum = true; - _datum = &(*image.getXmpData())[_key.key()]; - setArrayValue(value); - break; - } - case Exiv2::langAlt: - { - const boost::python::dict value = getLangAltValue(); - delete _datum; - _from_datum = true; - _datum = &(*image.getXmpData())[_key.key()]; - setLangAltValue(value); - break; - } - default: - // Should not happen, this case is here for the sake - // of completeness and to avoid compiler warnings. - assert(0); - } + Exiv2::Value::AutoPtr value = _datum->getValue(); + delete _datum; + _from_datum = true; + _datum = &(*image.getXmpData())[_key.key()]; + _datum->setValue(value.get()); } const std::string XmpTag::getKey() |