digiKam
metaengine_mergehelper.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2006-09-15
7  * Description : Exiv2 library interface.
8  * Internal merge helper.
9  *
10  * Copyright (C) 2006-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  * Copyright (C) 2006-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
12  *
13  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General
15  * Public License as published by the Free Software Foundation;
16  * either version 2, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * ============================================================ */
25 
26 #ifndef DIGIKAM_META_ENGINE_MERGE_HELPER_H
27 #define DIGIKAM_META_ENGINE_MERGE_HELPER_H
28 
29 #include "metaengine_p.h"
30 
31 namespace Digikam
32 {
33 
34 template <class Data, class Key, class KeyString, class KeyStringList = QList<KeyString> >
35 
36 class Q_DECL_HIDDEN MetaEngineMergeHelper
37 {
38 public:
39 
40  KeyStringList keys;
41 
42 public:
43 
44  MetaEngineMergeHelper& operator<<(const KeyString& key)
45  {
46  keys << key;
47 
48  return *this;
49  }
50 
55  void mergeAll(const Data& src, Data& dest)
56  {
57  for (typename Data::const_iterator it = src.begin() ; it != src.end() ; ++it)
58  {
59  typename Data::iterator destIt = dest.findKey(Key(it->key()));
60 
61  if (destIt == dest.end())
62  {
63  dest.add(*it);
64  }
65  else
66  {
67  *destIt = *it;
68  }
69  }
70  }
71 
77  void mergeFields(const Data& src, Data& dest)
78  {
79  foreach (const KeyString& keyString, keys)
80  {
81  Key key(keyString.latin1());
82  typename Data::const_iterator it = src.findKey(key);
83 
84  if (it == src.end())
85  {
86  continue;
87  }
88 
89  typename Data::iterator destIt = dest.findKey(key);
90 
91  if (destIt == dest.end())
92  {
93  dest.add(*it);
94  }
95  else
96  {
97  *destIt = *it;
98  }
99  }
100  }
101 
109  void exclusiveMerge(const Data& src, Data& dest)
110  {
111  foreach (const KeyString& keyString, keys)
112  {
113  Key key(keyString.latin1());
114  typename Data::const_iterator it = src.findKey(key);
115  typename Data::iterator destIt = dest.findKey(key);
116 
117  if (destIt == dest.end())
118  {
119  if (it != src.end())
120  {
121  dest.add(*it);
122  }
123  }
124  else
125  {
126  if (it == src.end())
127  {
128  dest.erase(destIt);
129  }
130  else
131  {
132  *destIt = *it;
133  }
134  }
135  }
136  }
137 };
138 
139 class Q_DECL_HIDDEN ExifMetaEngineMergeHelper
140  : public MetaEngineMergeHelper<Exiv2::ExifData, Exiv2::ExifKey, QLatin1String>
141 {
142 };
143 
144 class Q_DECL_HIDDEN IptcMetaEngineMergeHelper
145  : public MetaEngineMergeHelper<Exiv2::IptcData, Exiv2::IptcKey, QLatin1String>
146 {
147 };
148 
149 #ifdef _XMP_SUPPORT_
150 
151 class Q_DECL_HIDDEN XmpMetaEngineMergeHelper
152  : public MetaEngineMergeHelper<Exiv2::XmpData, Exiv2::XmpKey, QLatin1String>
153 {
154 };
155 
156 #endif
157 
158 } // namespace Digikam
159 
160 #endif // DIGIKAM_META_ENGINE_MERGE_HELPER_H
Definition: metaengine_mergehelper.h:141
Definition: metaengine_mergehelper.h:146
Definition: metaengine_mergehelper.h:37
KeyStringList keys
Definition: metaengine_mergehelper.h:40
void exclusiveMerge(const Data &src, Data &dest)
Definition: metaengine_mergehelper.h:109
void mergeFields(const Data &src, Data &dest)
Definition: metaengine_mergehelper.h:77
MetaEngineMergeHelper & operator<<(const KeyString &key)
Definition: metaengine_mergehelper.h:44
void mergeAll(const Data &src, Data &dest)
Definition: metaengine_mergehelper.h:55
Definition: datefolderview.cpp:43