1 #ifndef FIELDBASEDTAG_H 2 #define FIELDBASEDTAG_H 24 template <
class FieldType,
class Compare = std::less<
typename FieldType::
identifierType> >
30 virtual const TagValue &
value(
const typename FieldType::identifierType &
id)
const;
32 std::vector<const TagValue *>
values(
const typename FieldType::identifierType &
id)
const;
34 virtual bool setValue(
const typename FieldType::identifierType &
id,
const TagValue &value);
36 bool setValues(
const typename FieldType::identifierType &
id,
const std::vector<TagValue> &values);
39 virtual bool hasField(
const typename FieldType::identifierType &
id)
const;
41 const std::multimap<typename FieldType::identifierType, FieldType, Compare> &
fields()
const;
42 std::multimap<typename FieldType::identifierType, FieldType, Compare> &
fields();
55 std::multimap<typename FieldType::identifierType, FieldType, Compare> m_fields;
75 template <
class FieldType,
class Compare>
83 template <
class FieldType,
class Compare>
86 auto i = m_fields.find(
id);
90 template <
class FieldType,
class Compare>
100 template <
class FieldType,
class Compare>
103 auto range = m_fields.equal_range(
id);
104 std::vector<const TagValue *>
values;
105 for(
auto i = range.first; i != range.second; ++i) {
106 if(!i->second.value().isEmpty()) {
107 values.push_back(&i->second.value());
113 template <
class FieldType,
class Compare>
119 template <
class FieldType,
class Compare>
129 template <
class FieldType,
class Compare>
132 auto i = m_fields.find(
id);
133 if(i != m_fields.end()) {
134 i->second.setValue(value);
136 m_fields.insert(std::make_pair(
id, FieldType(
id, value)));
149 template <
class FieldType,
class Compare>
152 auto valuesIterator = values.cbegin();
153 auto range = m_fields.equal_range(
id);
155 for(; valuesIterator != values.cend() && range.first != range.second; ++valuesIterator) {
157 if(!valuesIterator->isEmpty()) {
158 range.first->second.setValue(*valuesIterator);
163 for(; valuesIterator != values.cend(); ++valuesIterator) {
164 m_fields.insert(std::make_pair(
id, FieldType(
id, *valuesIterator)));
167 for(; range.first != range.second; ++range.first) {
168 range.first->second.setValue(
TagValue());
179 template <
class FieldType,
class Compare>
185 template <
class FieldType,
class Compare>
194 template <
class FieldType,
class Compare>
197 for (
auto range = m_fields.equal_range(
id); range.first != range.second; ++range.first) {
198 if(!range.first->second.value().isEmpty()) {
205 template <
class FieldType,
class Compare>
214 template <
class FieldType,
class Compare>
223 template <
class FieldType,
class Compare>
229 template <
class FieldType,
class Compare>
232 unsigned int count = 0;
233 for(
const auto &field : m_fields) {
234 if(!field.second.value().isEmpty()) {
241 template <
class FieldType,
class Compare>
244 static typename FieldType::identifierType def;
251 template <
class FieldType,
class Compare>
263 template <
class FieldType,
class Compare>
266 int fieldsInserted = 0;
267 for(
const auto &pair : from.
fields()) {
268 const FieldType &fromField = pair.second;
269 if(fromField.value().isEmpty())
271 bool fieldInserted =
false;
272 auto range =
fields().equal_range(fromField.id());
273 for(
auto i = range.first; i != range.second; ++i) {
274 FieldType &ownField = i->second;
275 if((fromField.isTypeInfoAssigned() && ownField.isTypeInfoAssigned()
276 && fromField.typeInfo() == ownField.typeInfo())
277 || (!fromField.isTypeInfoAssigned() && ! ownField.isTypeInfoAssigned())) {
278 if(overwrite || ownField.value().isEmpty()) {
279 ownField = fromField;
282 fieldInserted =
true;
287 fields().insert(std::make_pair(fromField.id(), fromField));
291 return fieldsInserted;
294 template <
class FieldType,
class Compare>
305 template <
class FieldType,
class Compare>
308 for(
auto &field :
fields()) {
309 field.second.value().convertDataEncodingForTag(
this);
315 #endif // FIELDBASEDTAG_H