MPD 0.20.6

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

Set.hxx
Go to the documentation of this file.
1 /*
2 * Copyright 2003-2017 The Music Player Daemon Project
3 * http://www.musicpd.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MPD_TAG_SET_HXX
21 #define MPD_TAG_SET_HXX
22
23 #include "Compiler.h"
24 #include "Tag.hxx"
25 #include "Mask.hxx"
26
27 #include <set>
28
29 #include <string.h>
30
34 struct TagLess {
35 gcc_pure
36 bool operator()(const Tag &a, const Tag &b) const {
37 if (a.num_items != b.num_items)
38 return a.num_items < b.num_items;
39
40 const unsigned n = a.num_items;
41 for (unsigned i = 0; i < n; ++i) {
42 const TagItem &ai = *a.items[i];
43 const TagItem &bi = *b.items[i];
44 if (ai.type != bi.type)
45 return unsigned(ai.type) < unsigned(bi.type);
46
47 const int cmp = strcmp(ai.value, bi.value);
48 if (cmp != 0)
49 return cmp < 0;
50 }
51
52 return false;
53 }
54 };
55
59 class TagSet : public std::set<Tag, TagLess> {
60 public:
61 void InsertUnique(const Tag &tag,
62 TagType type, tag_mask_t group_mask);
63
64 private:
65 void InsertUnique(const Tag &src, TagType type, const char *value,
66 tag_mask_t group_mask);
67
68 bool CheckUnique(TagType dest_type,
69 const Tag &tag, TagType src_type,
70 tag_mask_t group_mask);
71 };
72
73 #endif
TagLess::operator()
gcc_pure bool operator()(const Tag &a, const Tag &b) const
Definition: Set.hxx:36
Tag::items
TagItem ** items
an array of tag items
Definition: Tag.hxx:51
TagItem::type
TagType type
the type of this item
Definition: TagItem.hxx:32
Tag
The meta information about a song file.
Definition: Tag.hxx:34
Tag::num_items
unsigned short num_items
the total number of tag items in the items array
Definition: Tag.hxx:48
TagLess
Helper class for TagSet which compares two Tag objects.
Definition: Set.hxx:34
Tag.hxx
Compiler.h
TagType
TagType
Codes for the type of a tag item.
Definition: TagType.h:30
TagItem
One tag value.
Definition: TagItem.hxx:30
TagItem::value
char value[1]
the value of this tag; this is a variable length string
Definition: TagItem.hxx:37
tag_mask_t
uint_least32_t tag_mask_t
Definition: Mask.hxx:25
Mask.hxx
TagSet
A set of Tag objects.
Definition: Set.hxx:59
TagSet::InsertUnique
void InsertUnique(const Tag &tag, TagType type, tag_mask_t group_mask)
gcc_pure
#define gcc_pure
Definition: Compiler.h:116