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
0a3ada4f
Commit
0a3ada4f
authored
Aug 02, 2012
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stats: convert to C++
parent
8bdf7917
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
27 deletions
+32
-27
Makefile.am
Makefile.am
+1
-1
Stats.cxx
src/Stats.cxx
+31
-26
No files found.
Makefile.am
View file @
0a3ada4f
...
...
@@ -338,7 +338,7 @@ src_mpd_SOURCES = \
src/resolver.c src/resolver.h
\
src/socket_util.c
\
src/state_file.c
\
src/
stats.c
\
src/
Stats.cxx
\
src/tag.c
\
src/tag_pool.c
\
src/tag_print.c
\
...
...
src/
stats.c
→
src/
Stats.cxx
View file @
0a3ada4f
...
...
@@ -18,15 +18,24 @@
*/
#include "config.h"
extern
"C"
{
#include "stats.h"
#include "database.h"
#include "db_
visitor
.h"
#include "db_
selection
.h"
#include "tag.h"
#include "song.h"
#include "client.h"
#include "player_control.h"
#include "strset.h"
#include "client_internal.h"
}
#include "DatabaseGlue.hxx"
#include "DatabasePlugin.hxx"
#include <functional>
#include <set>
struct
stats
stats
;
...
...
@@ -40,13 +49,17 @@ void stats_global_finish(void)
g_timer_destroy
(
stats
.
timer
);
}
struct
visit_data
{
struct
strset
*
artists
;
struct
strset
*
albums
;
struct
StringLess
{
gcc_pure
bool
operator
()(
const
char
*
a
,
const
char
*
b
)
const
{
return
strcmp
(
a
,
b
)
<
0
;
}
};
typedef
std
::
set
<
const
char
*
,
StringLess
>
StringSet
;
static
void
visit_tag
(
struct
visit_data
*
data
,
const
struct
tag
*
tag
)
visit_tag
(
StringSet
&
artists
,
StringSet
&
albums
,
const
struct
tag
*
tag
)
{
if
(
tag
->
time
>
0
)
stats
.
song_duration
+=
tag
->
time
;
...
...
@@ -56,11 +69,11 @@ visit_tag(struct visit_data *data, const struct tag *tag)
switch
(
item
->
type
)
{
case
TAG_ARTIST
:
strset_add
(
data
->
artists
,
item
->
value
);
artists
.
insert
(
item
->
value
);
break
;
case
TAG_ALBUM
:
strset_add
(
data
->
albums
,
item
->
value
);
albums
.
insert
(
item
->
value
);
break
;
default:
...
...
@@ -70,41 +83,33 @@ visit_tag(struct visit_data *data, const struct tag *tag)
}
static
bool
collect_stats_song
(
struct
song
*
song
,
void
*
_data
,
G_GNUC_UNUSED
GError
**
error_r
)
collect_stats_song
(
StringSet
&
artists
,
StringSet
&
albums
,
struct
song
*
song
)
{
struct
visit_data
*
data
=
_data
;
++
stats
.
song_count
;
if
(
song
->
tag
!=
NULL
)
visit_tag
(
data
,
song
->
tag
);
visit_tag
(
artists
,
albums
,
song
->
tag
);
return
true
;
}
static
const
struct
db_visitor
collect_stats_visitor
=
{
.
song
=
collect_stats_song
,
};
void
stats_update
(
void
)
{
struct
visit_data
data
;
stats
.
song_count
=
0
;
stats
.
song_duration
=
0
;
stats
.
artist_count
=
0
;
data
.
artists
=
strset_new
();
data
.
albums
=
strset_new
();
db_walk
(
""
,
&
collect_stats_visitor
,
&
data
,
NULL
);
struct
db_selection
selection
;
db_selection_init
(
&
selection
,
""
,
true
);
stats
.
artist_count
=
strset_size
(
data
.
artists
);
stats
.
album_count
=
strset_size
(
data
.
albums
);
StringSet
artists
,
albums
;
using
namespace
std
::
placeholders
;
const
auto
f
=
std
::
bind
(
collect_stats_song
,
std
::
ref
(
artists
),
std
::
ref
(
albums
),
_1
);
GetDatabase
()
->
Visit
(
&
selection
,
f
,
NULL
);
st
rset_free
(
data
.
artists
);
st
rset_free
(
data
.
albums
);
st
ats
.
artist_count
=
artists
.
size
(
);
st
ats
.
album_count
=
albums
.
size
(
);
}
int
stats_print
(
struct
client
*
client
)
...
...
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