aboutsummaryrefslogtreecommitdiffstats
path: root/src/exiv2wrapper.cpp
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2010-05-20 11:04:41 +0200
committerOlivier Tilloy <olivier@tilloy.net>2010-05-20 11:04:41 +0200
commit345251460bfd25e68eed67435eb035a46efa8006 (patch)
tree37dfaf034c9c0e973e4ab37bf2f1271644082cbc /src/exiv2wrapper.cpp
parente8573ba3172cb5c21bda75436156632a2c7c104d (diff)
downloadpyexiv2-345251460bfd25e68eed67435eb035a46efa8006.tar.gz
Moving around the code that writes IPTC tag values,
there is no need for it to be in its own static function now.
Diffstat (limited to 'src/exiv2wrapper.cpp')
-rw-r--r--src/exiv2wrapper.cpp96
1 files changed, 43 insertions, 53 deletions
diff --git a/src/exiv2wrapper.cpp b/src/exiv2wrapper.cpp
index 4ecbf48..83a5712 100644
--- a/src/exiv2wrapper.cpp
+++ b/src/exiv2wrapper.cpp
@@ -41,58 +41,6 @@
namespace exiv2wrapper
{
-// Static helper function to set the values of an IptcData for a given key
-static void set_iptc_tag_values(const std::string& key,
- Exiv2::IptcData* metadata,
- const boost::python::list& values)
-{
- Exiv2::IptcKey iptcKey = Exiv2::IptcKey(key);
- unsigned int index = 0;
- unsigned int max = boost::python::len(values);
- Exiv2::IptcMetadata::iterator iterator = metadata->findKey(iptcKey);
- while (index < max)
- {
- std::string value = boost::python::extract<std::string>(values[index++]);
- if (iterator != metadata->end())
- {
- // Override an existing value
- iterator->setValue(value);
- // Jump to the next datum matching the key
- ++iterator;
- while ((iterator != metadata->end()) && (iterator->key() != key))
- {
- ++iterator;
- }
- }
- else
- {
- // Append a new value
- Exiv2::Iptcdatum datum(iptcKey);
- datum.setValue(value);
- int state = metadata->add(datum);
- if (state == 6)
- {
- throw Exiv2::Error(NON_REPEATABLE);
- }
- // Reset iterator that has been invalidated by appending a datum
- iterator = metadata->end();
- }
- }
- // Erase the remaining values if any
- while (iterator != metadata->end())
- {
- if (iterator->key() == key)
- {
- iterator = metadata->erase(iterator);
- }
- else
- {
- ++iterator;
- }
- }
-}
-
-
void Image::_instantiate_image()
{
// If an exception is thrown, it has to be done outside of the
@@ -676,7 +624,49 @@ void IptcTag::setRawValues(const boost::python::list& values)
throw Exiv2::Error(NON_REPEATABLE);
}
- set_iptc_tag_values(_key.key(), _data, values);
+ unsigned int index = 0;
+ unsigned int max = boost::python::len(values);
+ Exiv2::IptcMetadata::iterator iterator = _data->findKey(_key);
+ while (index < max)
+ {
+ std::string value = boost::python::extract<std::string>(values[index++]);
+ if (iterator != _data->end())
+ {
+ // Override an existing value
+ iterator->setValue(value);
+ // Jump to the next datum matching the key
+ ++iterator;
+ while ((iterator != _data->end()) && (iterator->key() != _key.key()))
+ {
+ ++iterator;
+ }
+ }
+ else
+ {
+ // Append a new value
+ Exiv2::Iptcdatum datum(_key);
+ datum.setValue(value);
+ int state = _data->add(datum);
+ if (state == 6)
+ {
+ throw Exiv2::Error(NON_REPEATABLE);
+ }
+ // Reset iterator that has been invalidated by appending a datum
+ iterator = _data->end();
+ }
+ }
+ // Erase the remaining values if any
+ while (iterator != _data->end())
+ {
+ if (iterator->key() == _key.key())
+ {
+ iterator = _data->erase(iterator);
+ }
+ else
+ {
+ ++iterator;
+ }
+ }
}
void IptcTag::setParentImage(Image& image)