~osomon/pyexiv2/pyexiv2-0.3

« back to all changes in this revision

Viewing changes to src/exiv2wrapper.cpp

  • Committer: Olivier Tilloy
  • Date: 2009-04-21 07:23:46 UTC
  • Revision ID: olivier@tilloy.net-20090421072346-87rqxmkmk6xpykb6
Unlike IPTC tags, XMP tags are not repeatable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
344
344
 
345
345
boost::python::tuple Image::getXmpTag(std::string key)
346
346
{
347
 
    if(_dataRead)
348
 
    {
349
 
        Exiv2::XmpKey xmpKey = Exiv2::XmpKey(key);
350
 
        boost::python::list values;
351
 
        unsigned int occurences = 0;
352
 
        for (Exiv2::XmpMetadata::iterator i = _xmpData.begin();
353
 
             i != _xmpData.end();
354
 
             ++i)
355
 
        {
356
 
            if (i->key() == key)
 
347
    if(!_dataRead)
 
348
    {
 
349
        throw Exiv2::Error(METADATA_NOT_READ);
 
350
    }
 
351
 
 
352
    Exiv2::XmpKey xmpKey = Exiv2::XmpKey(key);
 
353
 
 
354
    if(_xmpData.findKey(xmpKey) == _xmpData.end())
 
355
    {
 
356
        throw Exiv2::Error(KEY_NOT_FOUND, key);
 
357
    }
 
358
 
 
359
    Exiv2::Xmpdatum xmpDatum = _xmpData[key];
 
360
    std::string sTagName = xmpKey.tagName();
 
361
    std::string sTagLabel = xmpKey.tagLabel();
 
362
    std::string sTagDesc(Exiv2::XmpProperties::propertyDesc(xmpKey));
 
363
    std::string sTagType(Exiv2::XmpProperties::propertyInfo(xmpKey)->xmpValueType_);
 
364
    std::string sTagValue = xmpDatum.toString();
 
365
    return boost::python::make_tuple(key, sTagName, sTagLabel, sTagDesc, sTagType, sTagValue);
 
366
}
 
367
 
 
368
/*void Image::setXmpTagValues(std::string key, boost::python::tuple values)
 
369
{
 
370
    if (!_dataRead)
 
371
    {
 
372
        throw Exiv2::Error(METADATA_NOT_READ);
 
373
    }
 
374
 
 
375
    Exiv2::XmpKey xmpKey = Exiv2::XmpKey(key);
 
376
    unsigned int index = 0;
 
377
    unsigned int max = len(values);
 
378
    Exiv2::XmpMetadata::iterator dataIterator = _xmpData.findKey(xmpKey);
 
379
    while (index < max)
 
380
    {
 
381
        std::string value = boost::python::extract<std::string>(values[index++]);
 
382
        if (dataIterator != _xmpData.end())
 
383
        {
 
384
            // Override an existing value
 
385
            dataIterator->setValue(value);
 
386
            dataIterator = std::find_if(++dataIterator, _xmpData.end(),
 
387
                Exiv2::FindMetadatumById::FindMetadatumById(xmpKey.tag(),
 
388
                                                            xmpKey.record()));
 
389
        }
 
390
        else
 
391
        {
 
392
            // Append a new value
 
393
            Exiv2::Iptcdatum iptcDatum(iptcKey);
 
394
            iptcDatum.setValue(value);
 
395
            int state = _iptcData.add(iptcDatum);
 
396
            if (state == 6)
357
397
            {
358
 
                values.append(i->toString());
359
 
                ++occurences;
 
398
                throw Exiv2::Error(NON_REPEATABLE);
360
399
            }
361
400
        }
362
 
        if (occurences > 0)
363
 
        {
364
 
            std::string sTagName = xmpKey.tagName();
365
 
            std::string sTagLabel = xmpKey.tagLabel();
366
 
            std::string sTagDesc(Exiv2::XmpProperties::propertyDesc(xmpKey));
367
 
            std::string sTagType(Exiv2::XmpProperties::propertyInfo(xmpKey)->xmpValueType_);
368
 
            return boost::python::make_tuple(key, sTagName, sTagLabel, sTagDesc, sTagType, values);
369
 
        }
370
 
        else
371
 
        {
372
 
            throw Exiv2::Error(KEY_NOT_FOUND, key);
373
 
        }
374
401
    }
375
 
    else
 
402
    // Erase the remaining values if any
 
403
    while (dataIterator != _iptcData.end())
376
404
    {
377
 
        throw Exiv2::Error(METADATA_NOT_READ);
 
405
        _iptcData.erase(dataIterator);
 
406
        dataIterator = std::find_if(dataIterator, _iptcData.end(),
 
407
                Exiv2::FindMetadatumById::FindMetadatumById(iptcKey.tag(),
 
408
                                                            iptcKey.record()));
378
409
    }
379
 
}
 
410
}*/
380
411
 
381
412
/*
382
413
boost::python::tuple Image::getThumbnailData()