Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
41a7203c
Commit
41a7203c
authored
Jul 12, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tag: add class const_iterator and methods begin(), end()
Enables using range-based "for".
parent
543a58bb
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
89 additions
and
47 deletions
+89
-47
SongFilter.cxx
src/SongFilter.cxx
+4
-6
TagPrint.cxx
src/TagPrint.cxx
+2
-4
TagSave.cxx
src/TagSave.cxx
+2
-3
Count.cxx
src/db/Count.cxx
+1
-3
DatabasePrint.cxx
src/db/DatabasePrint.cxx
+1
-3
Helpers.cxx
src/db/Helpers.cxx
+1
-3
VorbisEncoderPlugin.cxx
src/encoder/plugins/VorbisEncoderPlugin.cxx
+1
-2
RoarOutputPlugin.cxx
src/output/plugins/RoarOutputPlugin.cxx
+7
-5
ShoutOutputPlugin.cxx
src/output/plugins/ShoutOutputPlugin.cxx
+4
-4
Set.cxx
src/tag/Set.cxx
+8
-9
Tag.cxx
src/tag/Tag.cxx
+3
-3
Tag.hxx
src/tag/Tag.hxx
+54
-0
test_translate_song.cxx
test/test_translate_song.cxx
+1
-2
No files found.
src/SongFilter.cxx
View file @
41a7203c
...
...
@@ -92,10 +92,10 @@ SongFilter::Item::Match(const Tag &_tag) const
bool
visited_types
[
TAG_NUM_OF_ITEM_TYPES
];
std
::
fill_n
(
visited_types
,
size_t
(
TAG_NUM_OF_ITEM_TYPES
),
false
);
for
(
unsigned
i
=
0
;
i
<
_tag
.
num_items
;
i
++
)
{
visited_types
[
_tag
.
items
[
i
]
->
type
]
=
true
;
for
(
const
auto
&
i
:
_tag
)
{
visited_types
[
i
.
type
]
=
true
;
if
(
Match
(
*
_tag
.
items
[
i
]
))
if
(
Match
(
i
))
return
true
;
}
...
...
@@ -112,12 +112,10 @@ SongFilter::Item::Match(const Tag &_tag) const
if
(
tag
==
TAG_ALBUM_ARTIST
&&
visited_types
[
TAG_ARTIST
])
{
/* if we're looking for "album artist", but
only "artist" exists, use that */
for
(
unsigned
i
=
0
;
i
<
_tag
.
num_items
;
i
++
)
{
const
TagItem
&
item
=
*
_tag
.
items
[
i
];
for
(
const
auto
&
item
:
_tag
)
if
(
item
.
type
==
TAG_ARTIST
&&
StringMatch
(
item
.
value
))
return
true
;
}
}
}
...
...
src/TagPrint.cxx
View file @
41a7203c
...
...
@@ -47,9 +47,7 @@ void tag_print(Client &client, const Tag &tag)
if
(
tag
.
time
>=
0
)
client_printf
(
client
,
SONG_TIME
"%i
\n
"
,
tag
.
time
);
for
(
unsigned
i
=
0
;
i
<
tag
.
num_items
;
i
++
)
{
for
(
const
auto
&
i
:
tag
)
client_printf
(
client
,
"%s: %s
\n
"
,
tag_item_names
[
tag
.
items
[
i
]
->
type
],
tag
.
items
[
i
]
->
value
);
}
tag_item_names
[
i
.
type
],
i
.
value
);
}
src/TagSave.cxx
View file @
41a7203c
...
...
@@ -32,8 +32,7 @@ tag_save(FILE *file, const Tag &tag)
if
(
tag
.
has_playlist
)
fprintf
(
file
,
"Playlist: yes
\n
"
);
for
(
unsigned
i
=
0
;
i
<
tag
.
num_items
;
i
++
)
for
(
const
auto
&
i
:
tag
)
fprintf
(
file
,
"%s: %s
\n
"
,
tag_item_names
[
tag
.
items
[
i
]
->
type
],
tag
.
items
[
i
]
->
value
);
tag_item_names
[
i
.
type
],
i
.
value
);
}
src/db/Count.cxx
View file @
41a7203c
...
...
@@ -73,9 +73,7 @@ static bool
CollectGroupCounts
(
TagCountMap
&
map
,
TagType
group
,
const
Tag
&
tag
)
{
bool
found
=
false
;
for
(
unsigned
i
=
0
;
i
<
tag
.
num_items
;
++
i
)
{
const
TagItem
&
item
=
*
tag
.
items
[
i
];
for
(
const
auto
&
item
:
tag
)
{
if
(
item
.
type
==
group
)
{
auto
r
=
map
.
insert
(
std
::
make_pair
(
item
.
value
,
SearchStats
()));
...
...
src/db/DatabasePrint.cxx
View file @
41a7203c
...
...
@@ -184,12 +184,10 @@ PrintUniqueTag(Client &client, TagType tag_type,
assert
(
value
!=
nullptr
);
client_printf
(
client
,
"%s: %s
\n
"
,
tag_item_names
[
tag_type
],
value
);
for
(
unsigned
i
=
0
,
n
=
tag
.
num_items
;
i
<
n
;
i
++
)
{
const
TagItem
&
item
=
*
tag
.
items
[
i
];
for
(
const
auto
&
item
:
tag
)
if
(
item
.
type
!=
tag_type
)
client_printf
(
client
,
"%s: %s
\n
"
,
tag_item_names
[
item
.
type
],
item
.
value
);
}
return
true
;
}
...
...
src/db/Helpers.cxx
View file @
41a7203c
...
...
@@ -43,9 +43,7 @@ StatsVisitTag(DatabaseStats &stats, StringSet &artists, StringSet &albums,
if
(
tag
.
time
>
0
)
stats
.
total_duration
+=
tag
.
time
;
for
(
unsigned
i
=
0
;
i
<
tag
.
num_items
;
++
i
)
{
const
TagItem
&
item
=
*
tag
.
items
[
i
];
for
(
const
auto
&
item
:
tag
)
{
switch
(
item
.
type
)
{
case
TAG_ARTIST
:
#if defined(__clang__) || GCC_CHECK_VERSION(4,8)
...
...
src/encoder/plugins/VorbisEncoderPlugin.cxx
View file @
41a7203c
...
...
@@ -272,8 +272,7 @@ vorbis_encoder_pre_tag(Encoder *_encoder, gcc_unused Error &error)
static
void
copy_tag_to_vorbis_comment
(
vorbis_comment
*
vc
,
const
Tag
*
tag
)
{
for
(
unsigned
i
=
0
;
i
<
tag
->
num_items
;
i
++
)
{
const
TagItem
&
item
=
*
tag
->
items
[
i
];
for
(
const
auto
&
item
:
*
tag
)
{
char
*
name
=
g_ascii_strup
(
tag_item_names
[
item
.
type
],
-
1
);
vorbis_comment_add_tag
(
vc
,
name
,
item
.
value
);
g_free
(
name
);
...
...
src/output/plugins/RoarOutputPlugin.cxx
View file @
41a7203c
...
...
@@ -374,20 +374,22 @@ RoarOutput::SendTag(const Tag &tag)
vals
[
0
].
key
=
const_cast
<
char
*>
(
"LENGTH"
);
vals
[
0
].
value
=
timebuf
;
for
(
unsigned
i
=
0
;
i
<
tag
.
num_items
&&
cnt
<
32
;
i
++
)
{
for
(
const
auto
&
item
:
tag
)
{
if
(
cnt
>=
32
)
break
;
bool
is_uuid
=
false
;
const
char
*
key
=
roar_tag_convert
(
tag
.
items
[
i
]
->
type
,
const
char
*
key
=
roar_tag_convert
(
item
.
type
,
&
is_uuid
);
if
(
key
!=
nullptr
)
{
vals
[
cnt
].
key
=
const_cast
<
char
*>
(
key
);
if
(
is_uuid
)
{
snprintf
(
uuid_buf
[
cnt
],
sizeof
(
uuid_buf
[
0
]),
"{UUID}%s"
,
tag
.
items
[
i
]
->
value
);
item
.
value
);
vals
[
cnt
].
value
=
uuid_buf
[
cnt
];
}
else
{
vals
[
cnt
].
value
=
tag
.
items
[
i
]
->
value
;
vals
[
cnt
].
value
=
const_cast
<
char
*>
(
item
.
value
)
;
}
cnt
++
;
...
...
src/output/plugins/ShoutOutputPlugin.cxx
View file @
41a7203c
...
...
@@ -470,13 +470,13 @@ shout_tag_to_metadata(const Tag *tag, char *dest, size_t size)
artist
[
0
]
=
0
;
title
[
0
]
=
0
;
for
(
unsigned
i
=
0
;
i
<
tag
->
num_items
;
i
++
)
{
switch
(
tag
->
items
[
i
]
->
type
)
{
for
(
const
auto
&
item
:
*
tag
)
{
switch
(
item
.
type
)
{
case
TAG_ARTIST
:
strncpy
(
artist
,
tag
->
items
[
i
]
->
value
,
size
);
strncpy
(
artist
,
item
.
value
,
size
);
break
;
case
TAG_TITLE
:
strncpy
(
title
,
tag
->
items
[
i
]
->
value
,
size
);
strncpy
(
title
,
item
.
value
,
size
);
break
;
default
:
...
...
src/tag/Set.cxx
View file @
41a7203c
...
...
@@ -30,10 +30,10 @@ CopyTagItem(TagBuilder &dest, TagType dest_type,
const
Tag
&
src
,
TagType
src_type
)
{
bool
found
=
false
;
const
unsigned
n
=
src
.
num_items
;
for
(
unsigned
i
=
0
;
i
<
n
;
++
i
)
{
if
(
src
.
items
[
i
]
->
type
==
src_type
)
{
dest
.
AddItem
(
dest_type
,
src
.
items
[
i
]
->
value
);
for
(
const
auto
&
item
:
src
)
{
if
(
item
.
type
==
src_type
)
{
dest
.
AddItem
(
dest_type
,
item
.
value
);
found
=
true
;
}
}
...
...
@@ -87,11 +87,10 @@ TagSet::CheckUnique(TagType dest_type,
uint32_t
group_mask
)
{
bool
found
=
false
;
for
(
unsigned
i
=
0
;
i
<
tag
.
num_items
;
++
i
)
{
if
(
tag
.
items
[
i
]
->
type
==
src_type
)
{
InsertUnique
(
tag
,
dest_type
,
tag
.
items
[
i
]
->
value
,
group_mask
);
for
(
const
auto
&
item
:
tag
)
{
if
(
item
.
type
==
src_type
)
{
InsertUnique
(
tag
,
dest_type
,
item
.
value
,
group_mask
);
found
=
true
;
}
}
...
...
src/tag/Tag.cxx
View file @
41a7203c
...
...
@@ -118,9 +118,9 @@ Tag::GetValue(TagType type) const
{
assert
(
type
<
TAG_NUM_OF_ITEM_TYPES
);
for
(
unsigned
i
=
0
;
i
<
num_items
;
i
++
)
if
(
item
s
[
i
]
->
type
==
type
)
return
item
s
[
i
]
->
value
;
for
(
const
auto
&
item
:
*
this
)
if
(
item
.
type
==
type
)
return
item
.
value
;
return
nullptr
;
}
...
...
src/tag/Tag.hxx
View file @
41a7203c
...
...
@@ -25,6 +25,7 @@
#include "Compiler.h"
#include <algorithm>
#include <iterator>
#include <stddef.h>
...
...
@@ -136,6 +137,59 @@ struct Tag {
*/
gcc_pure
bool
HasType
(
TagType
type
)
const
;
class
const_iterator
{
friend
struct
Tag
;
const
TagItem
*
const
*
cursor
;
constexpr
const_iterator
(
const
TagItem
*
const
*
_cursor
)
:
cursor
(
_cursor
)
{}
public
:
constexpr
const
TagItem
&
operator
*
()
const
{
return
**
cursor
;
}
constexpr
const
TagItem
*
operator
->
()
const
{
return
*
cursor
;
}
const_iterator
&
operator
++
()
{
++
cursor
;
return
*
this
;
}
const_iterator
operator
++
(
int
)
{
auto
result
=
cursor
++
;
return
const_iterator
{
result
};
}
const_iterator
&
operator
--
()
{
--
cursor
;
return
*
this
;
}
const_iterator
operator
--
(
int
)
{
auto
result
=
cursor
--
;
return
const_iterator
{
result
};
}
constexpr
bool
operator
==
(
const_iterator
other
)
const
{
return
cursor
==
other
.
cursor
;
}
constexpr
bool
operator
!=
(
const_iterator
other
)
const
{
return
cursor
!=
other
.
cursor
;
}
};
const_iterator
begin
()
const
{
return
const_iterator
{
items
};
}
const_iterator
end
()
const
{
return
const_iterator
{
items
+
num_items
};
}
};
/**
...
...
test/test_translate_song.cxx
View file @
41a7203c
...
...
@@ -160,8 +160,7 @@ ToString(const Tag &tag)
std
::
string
result
=
buffer
;
for
(
unsigned
i
=
0
,
n
=
tag
.
num_items
;
i
!=
n
;
++
i
)
{
const
TagItem
&
item
=
*
tag
.
items
[
i
];
for
(
const
auto
&
item
:
tag
)
{
result
.
push_back
(
'|'
);
result
.
append
(
tag_item_names
[
item
.
type
]);
result
.
push_back
(
'='
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment