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);
154 for(; valuesIterator != values.cend() && range.first != range.second; ++valuesIterator) {
155 if(!valuesIterator->isEmpty()) {
156 range.first->second.setValue(*valuesIterator);
160 for(; valuesIterator != values.cend(); ++valuesIterator) {
161 m_fields.insert(std::make_pair(
id, FieldType(
id, *valuesIterator)));
163 for(; range.first != range.second; ++range.first) {
164 range.first->second.setValue(
TagValue());
175 template <
class FieldType,
class Compare>
181 template <
class FieldType,
class Compare>
190 template <
class FieldType,
class Compare>
193 for (
auto range = m_fields.equal_range(
id); range.first != range.second; ++range.first) {
194 if(!range.first->second.value().isEmpty()) {
201 template <
class FieldType,
class Compare>
210 template <
class FieldType,
class Compare>
219 template <
class FieldType,
class Compare>
225 template <
class FieldType,
class Compare>
228 unsigned int count = 0;
229 for(
const auto &field : m_fields) {
230 if(!field.second.value().isEmpty()) {
237 template <
class FieldType,
class Compare>
240 static typename FieldType::identifierType def;
247 template <
class FieldType,
class Compare>
259 template <
class FieldType,
class Compare>
262 int fieldsInserted = 0;
263 for(
const auto &pair : from.
fields()) {
264 const FieldType &fromField = pair.second;
265 if(fromField.value().isEmpty())
267 bool fieldInserted =
false;
268 auto range =
fields().equal_range(fromField.id());
269 for(
auto i = range.first; i != range.second; ++i) {
270 FieldType &ownField = i->second;
271 if((fromField.isTypeInfoAssigned() && ownField.isTypeInfoAssigned()
272 && fromField.typeInfo() == ownField.typeInfo())
273 || (!fromField.isTypeInfoAssigned() && ! ownField.isTypeInfoAssigned())) {
274 if(overwrite || ownField.value().isEmpty()) {
275 ownField = fromField;
278 fieldInserted =
true;
283 fields().insert(std::make_pair(fromField.id(), fromField));
287 return fieldsInserted;
290 template <
class FieldType,
class Compare>
301 template <
class FieldType,
class Compare>
304 for(
auto &field :
fields()) {
305 field.second.value().convertDataEncodingForTag(
this);
311 #endif // FIELDBASEDTAG_H