aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2007-03-13 22:22:31 +0100
committerOlivier Tilloy <olivier@tilloy.net>2007-03-13 22:22:31 +0100
commitb97d510a9dd3f7d220d8543a9087c554bf96d6ee (patch)
treeb4b92c8e9a8bc87020e68c8f5b05446d40ef4060
parent1b48deeb7952c27e8dba6c5b3c702efc5e582a65 (diff)
downloadpyexiv2-b97d510a9dd3f7d220d8543a9087c554bf96d6ee.tar.gz
Modified method Image::deleteIptcTag(...) to take into account the possibility for an IPTC tag to be repeatable.
-rw-r--r--src/libpyexiv2.cpp21
-rw-r--r--src/libpyexiv2.hpp8
2 files changed, 20 insertions, 9 deletions
diff --git a/src/libpyexiv2.cpp b/src/libpyexiv2.cpp
index 9ce4a9d..22c4063 100644
--- a/src/libpyexiv2.cpp
+++ b/src/libpyexiv2.cpp
@@ -281,18 +281,25 @@ namespace LibPyExiv2
throw Exiv2::Error(METADATA_NOT_READ);
}
- boost::python::tuple Image::deleteIptcTag(std::string key)
+ boost::python::tuple Image::deleteIptcTag(std::string key, unsigned int index=0)
{
- boost::python::tuple returnValue;
if(_dataRead)
{
+ boost::python::tuple returnValue;
+ unsigned int indexCounter = index;
Exiv2::IptcKey iptcKey = Exiv2::IptcKey(key);
- Exiv2::IptcMetadata::iterator i = _iptcData.findKey(iptcKey);
- if(i != _iptcData.end())
+ Exiv2::IptcMetadata::iterator dataIterator = _iptcData.findKey(iptcKey);
+ while ((indexCounter > 0) && (dataIterator != _iptcData.end()))
{
- Exiv2::Iptcdatum iptcDatum = _iptcData[key];
- returnValue = boost::python::make_tuple(iptcDatum.typeName(), iptcDatum.toString());
- _iptcData.erase(i);
+ 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
+ returnValue = boost::python::make_tuple(dataIterator->typeName(), dataIterator->toString());
+ _iptcData.erase(dataIterator);
return returnValue;
}
else
diff --git a/src/libpyexiv2.hpp b/src/libpyexiv2.hpp
index 514094a..f9cf19c 100644
--- a/src/libpyexiv2.hpp
+++ b/src/libpyexiv2.hpp
@@ -108,8 +108,12 @@ namespace LibPyExiv2
// Delete the required IPTC tag and return a tuple containing the
// type and previous value.
- // Throw an exception if the tag was not set.
- boost::python::tuple deleteIptcTag(std::string key);
+ // 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.
+ boost::python::tuple deleteIptcTag(std::string key, unsigned int index);
// Read and write access to the thumbnail embedded in the image.