Project

General

Profile

Patch #967 » 0002-xmp-convert-metadata-store-from-std-vector-to-std-mu.patch

Michael Pratt, 05 Jul 2014 19:14

View differences:

src/properties.cpp
2300 2300
        return *this;
2301 2301
    }
2302 2302

  
2303
    bool XmpKey::operator<(const XmpKey& b) const
2304
    {
2305
        if (this->groupName() != b.groupName()) {
2306
            return this->groupName() < b.groupName();
2307
        }
2308

  
2309
        return this->tagName() < b.tagName();
2310
    }
2311

  
2303 2312
    XmpKey::AutoPtr XmpKey::clone() const
2304 2313
    {
2305 2314
        return AutoPtr(clone_());
src/properties.hpp
265 265
        //@{
266 266
        //! Assignment operator.
267 267
        XmpKey& operator=(const XmpKey& rhs);
268
        //! Comparison operator.
269
        bool operator<(const XmpKey& b) const;
268 270
        //@}
269 271

  
270 272
        //! @name Accessors
src/xmp.cpp
52 52
// *****************************************************************************
53 53
// local declarations
54 54
namespace {
55
    //! Unary predicate that matches an Xmpdatum by key
56
    class FindXmpdatum {
57
    public:
58
        //! Constructor, initializes the object with key
59
        FindXmpdatum(const Exiv2::XmpKey& key)
60
            : key_(key.key()) {}
61
        /*!
62
          @brief Returns true if prefix and property of the argument
63
                 Xmpdatum are equal to that of the object.
64
        */
65
        bool operator()(const Exiv2::Xmpdatum& xmpdatum) const
66
            { return key_ == xmpdatum.key(); }
67

  
68
    private:
69
        std::string key_;
70

  
71
    }; // class FindXmpdatum
72 55

  
73 56
#ifdef EXV_HAVE_XMP_TOOLKIT
74 57
    //! Convert XMP Toolkit struct option bit to Value::XmpStruct
......
181 164
        delete p_;
182 165
    }
183 166

  
167
    const XmpKey& Xmpdatum::xmpKey() const
168
    {
169
        if (p_->key_.get() == 0) throw Error(8);
170
        return *p_->key_;
171
    }
172

  
184 173
    std::string Xmpdatum::key() const
185 174
    {
186 175
        return p_->key_.get() == 0 ? "" : p_->key_->key();
......
315 304

  
316 305
    Xmpdatum& XmpData::operator[](const std::string& key)
317 306
    {
318
        XmpKey xmpKey(key);
319
        iterator pos = findKey(xmpKey);
320
        if (pos == end()) {
321
            add(Xmpdatum(xmpKey));
322
            pos = findKey(xmpKey);
307
        XmpKey k = XmpKey(key);
308
        XmpMetadata::iterator it = xmpMetadata_.find(k);
309
        if (it != xmpMetadata_.end()) {
310
            return it->second;
323 311
        }
324
        return *pos;
312

  
313
        add(Xmpdatum(k));
314
        return (*this)[key];
325 315
    }
326 316

  
327 317
    int XmpData::add(const XmpKey& key, const Value* value)
......
331 321

  
332 322
    int XmpData::add(const Xmpdatum& xmpDatum)
333 323
    {
334
        xmpMetadata_.push_back(xmpDatum);
324
        xmpMetadata_.insert(std::make_pair(xmpDatum.xmpKey(), xmpDatum));
335 325
        return 0;
336 326
    }
337 327

  
338 328
    XmpData::const_iterator XmpData::findKey(const XmpKey& key) const
339 329
    {
340
        return std::find_if(xmpMetadata_.begin(), xmpMetadata_.end(),
341
                            FindXmpdatum(key));
330
        return xmpMetadata_.find(key);
342 331
    }
343 332

  
344 333
    XmpData::iterator XmpData::findKey(const XmpKey& key)
345 334
    {
346
        return std::find_if(xmpMetadata_.begin(), xmpMetadata_.end(),
347
                            FindXmpdatum(key));
335
        return xmpMetadata_.find(key);
348 336
    }
349 337

  
350 338
    void XmpData::clear()
......
354 342

  
355 343
    void XmpData::sortByKey()
356 344
    {
357
        std::sort(xmpMetadata_.begin(), xmpMetadata_.end(), cmpMetadataByKey);
345
        return;  // multimap is kept sorted by key
358 346
    }
359 347

  
360 348
    XmpData::const_iterator XmpData::begin() const
......
389 377

  
390 378
    XmpData::iterator XmpData::erase(XmpData::iterator pos)
391 379
    {
392
        return xmpMetadata_.erase(pos);
380
        XmpData::iterator next = pos;
381
        next++;
382
        xmpMetadata_.erase(pos.it);
383
        return next;
393 384
    }
394 385

  
395 386
    bool XmpParser::initialized_ = false;
src/xmp.hpp
132 132
                 contain multiple metadata with the same key.
133 133
         */
134 134
        std::string key() const;
135
        const XmpKey& xmpKey() const;
135 136
        const char* familyName() const;
136 137
        //! Return the (preferred) schema namespace prefix.
137 138
        std::string groupName() const;
......
164 165
    }; // class Xmpdatum
165 166

  
166 167
    //! Container type to hold all metadata
167
    typedef std::vector<Xmpdatum> XmpMetadata;
168
    typedef std::multimap<XmpKey, Xmpdatum> XmpMetadata;
168 169

  
169 170
    /*!
170 171
      @brief A container for XMP data. This is a top-level class of
......
179 180
    class EXIV2API XmpData {
180 181
    public:
181 182
        //! XmpMetadata iterator type
182
        typedef XmpMetadata::iterator iterator;
183
        typedef map_value_iterator<XmpMetadata, XmpMetadata::iterator> iterator;
183 184
        //! XmpMetadata const iterator type
184
        typedef XmpMetadata::const_iterator const_iterator;
185
        typedef map_value_iterator<XmpMetadata, XmpMetadata::const_iterator, const typename XmpMetadata::const_iterator::value_type::second_type> const_iterator;
185 186

  
186 187
        //! @name Manipulators
187 188
        //@{
......
215 216
        iterator erase(iterator pos);
216 217
        //! Delete all Xmpdatum instances resulting in an empty container.
217 218
        void clear();
218
        //! Sort metadata by key
219
        /*!
220
          @deprecated Xmp metadata is always kept sorted by key.
221
                This method is a no-op.
222
         */
219 223
        void sortByKey();
220 224
        //! Begin of the metadata
221 225
        iterator begin();
222
- 
(4-4/7)