aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2009-04-14 09:36:26 +0200
committerOlivier Tilloy <olivier@tilloy.net>2009-04-14 09:36:26 +0200
commit8ee4a60dcfd299331ba30992fc324aeeeba694ab (patch)
tree4325eab89f03ee7f87b9418a5cbe3c5f629cffbf
parentc455d8b72459c7e5c106389054b61d332f19ba60 (diff)
downloadpyexiv2-8ee4a60dcfd299331ba30992fc324aeeeba694ab.tar.gz
Really delete all repetitions of an IPTC tag.
-rw-r--r--src/exiv2wrapper.cpp41
-rw-r--r--src/exiv2wrapper.hpp10
-rw-r--r--src/exiv2wrapper_python.cpp4
3 files changed, 24 insertions, 31 deletions
diff --git a/src/exiv2wrapper.cpp b/src/exiv2wrapper.cpp
index d29c332..18eff7d 100644
--- a/src/exiv2wrapper.cpp
+++ b/src/exiv2wrapper.cpp
@@ -299,30 +299,29 @@ void Image::setIptcTagValues(std::string key, boost::python::tuple values)
}
}
-/*void Image::deleteIptcTag(std::string key, unsigned int index=0)
+void Image::deleteIptcTag(std::string key)
{
- if(_dataRead)
+ if (!_dataRead)
{
- unsigned int indexCounter = index;
- Exiv2::IptcKey iptcKey = Exiv2::IptcKey(key);
- Exiv2::IptcMetadata::iterator dataIterator = _iptcData.findKey(iptcKey);
- while ((indexCounter > 0) && (dataIterator != _iptcData.end()))
- {
- dataIterator = std::find_if(++dataIterator, _iptcData.end(),
- Exiv2::FindMetadatumById::FindMetadatumById(iptcKey.tag(), iptcKey.record()));
- --indexCounter;
- }
- if (dataIterator != _iptcData.end())
- {
- // The tag at given index already exists, delete it
- _iptcData.erase(dataIterator);
- }
- else
- throw Exiv2::Error(KEY_NOT_FOUND, key);
- }
- else
throw Exiv2::Error(METADATA_NOT_READ);
-}*/
+ }
+
+ Exiv2::IptcKey iptcKey = Exiv2::IptcKey(key);
+ Exiv2::IptcMetadata::iterator dataIterator = _iptcData.findKey(iptcKey);
+
+ if (dataIterator == _iptcData.end())
+ {
+ throw Exiv2::Error(KEY_NOT_FOUND, key);
+ }
+
+ while (dataIterator != _iptcData.end())
+ {
+ _iptcData.erase(dataIterator);
+ dataIterator = std::find_if(++dataIterator, _iptcData.end(),
+ Exiv2::FindMetadatumById::FindMetadatumById(iptcKey.tag(),
+ iptcKey.record()));
+ }
+}
boost::python::list Image::xmpKeys()
{
diff --git a/src/exiv2wrapper.hpp b/src/exiv2wrapper.hpp
index 3bc5314..3dfd850 100644
--- a/src/exiv2wrapper.hpp
+++ b/src/exiv2wrapper.hpp
@@ -104,13 +104,9 @@ public:
//void setIptcTag(std::string key, std::string value, unsigned int index);
void setIptcTagValues(std::string key, boost::python::tuple values);
- // Delete the required IPTC tag.
- // If the key references a repeatable tag, the parameter index (starting
- // from 0 like a list index) is used to determine which of the
- // repetitions is to be deleted.
- // Throw an exception if the tag was not set or if the index is greater
- // than the highest existing one.
- //void deleteIptcTag(std::string key, unsigned int index);
+ // Delete (all the repetitions of) the required IPTC tag.
+ // Throw an exception if the tag was not set.
+ void deleteIptcTag(std::string key);
boost::python::list xmpKeys();
diff --git a/src/exiv2wrapper_python.cpp b/src/exiv2wrapper_python.cpp
index 238e39b..2be9843 100644
--- a/src/exiv2wrapper_python.cpp
+++ b/src/exiv2wrapper_python.cpp
@@ -45,8 +45,6 @@ BOOST_PYTHON_MODULE(libexiv2python)
register_exception_translator<Exiv2::Error>(&translateExiv2Error);
- // Exported method names prefixed by "_Image__" are going to be "private"
- // and are not meant to be used directly
class_<Image>("Image", init<std::string>())
.def("readMetadata", &Image::readMetadata)
@@ -60,7 +58,7 @@ BOOST_PYTHON_MODULE(libexiv2python)
.def("iptcKeys", &Image::iptcKeys)
.def("getIptcTag", &Image::getIptcTag)
.def("setIptcTagValues", &Image::setIptcTagValues)
-// .def("deleteIptcTag", &Image::deleteIptcTag)
+ .def("deleteIptcTag", &Image::deleteIptcTag)
.def("xmpKeys", &Image::xmpKeys)
.def("getXmpTag", &Image::getXmpTag)