Project

General

Profile

Patch: Sort iptc data by record number when encoding ยป iptc_sorted_records_patch.diff

Matthias Baas, 07 May 2011 09:16

View differences:

src/iptc.cpp (Arbeitskopie)
469 469
        return 0;
470 470
    } // IptcParser::decode
471 471

  
472
    /*!
473
      @brief Compare two iptc items by record. Return true if the record of
474
             lhs is less than that of rhs.
475

  
476
      This is a helper function for IptcParser::encode().
477
     */
478
    bool cmpIptcdataByRecord(const Iptcdatum& lhs, const Iptcdatum& rhs)
479
    {
480
        return lhs.record() < rhs.record();
481
    }
482

  
472 483
    DataBuf IptcParser::encode(const IptcData& iptcData)
473 484
    {
474 485
        DataBuf buf(iptcData.size());
475 486
        byte *pWrite = buf.pData_;
476 487

  
477
        IptcData::const_iterator iter = iptcData.begin();
478
        IptcData::const_iterator end = iptcData.end();
488
        // Copy the iptc data sets and sort them by record
489
        IptcMetadata sortedIptcData;
490
        std::copy(iptcData.begin(), iptcData.end(), std::back_inserter(sortedIptcData));
491
        std::sort(sortedIptcData.begin(), sortedIptcData.end(), cmpIptcdataByRecord);
492

  
493
        IptcData::const_iterator iter = sortedIptcData.begin();
494
        IptcData::const_iterator end = sortedIptcData.end();
479 495
        for ( ; iter != end; ++iter) {
480 496
            // marker, record Id, dataset num
481 497
            *pWrite++ = marker_;
    (1-1/1)