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
74904b9c
Commit
74904b9c
authored
Oct 21, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DecoderList: reimplement _for_each() with function object
parent
82059645
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
33 deletions
+54
-33
CommandLine.cxx
src/CommandLine.cxx
+8
-8
DecoderList.cxx
src/DecoderList.cxx
+6
-5
DecoderList.hxx
src/DecoderList.hxx
+28
-10
DecoderPrint.cxx
src/DecoderPrint.cxx
+12
-10
No files found.
src/CommandLine.cxx
View file @
74904b9c
...
...
@@ -75,16 +75,16 @@ static void version(void)
"
\n
"
"Decoders plugins:"
);
decoder_plugins_for_each
(
plugin
)
{
printf
(
" [%s]"
,
plugin
->
name
);
decoder_plugins_for_each
(
[](
const
DecoderPlugin
&
plugin
)
{
printf
(
" [%s]"
,
plugin
.
name
);
const
char
*
const
*
suffixes
=
plugin
->
suffixes
;
if
(
suffixes
!=
nullptr
)
for
(;
*
suffixes
!=
nullptr
;
++
suffixes
)
printf
(
" %s"
,
*
suffixes
);
const
char
*
const
*
suffixes
=
plugin
.
suffixes
;
if
(
suffixes
!=
nullptr
)
for
(;
*
suffixes
!=
nullptr
;
++
suffixes
)
printf
(
" %s"
,
*
suffixes
);
puts
(
""
);
}
puts
(
""
);
});
puts
(
"
\n
"
"Output plugins:"
);
...
...
src/DecoderList.cxx
View file @
74904b9c
...
...
@@ -180,9 +180,9 @@ decoder_plugin_from_mime_type(const char *mimeType, unsigned int next)
const
struct
DecoderPlugin
*
decoder_plugin_from_name
(
const
char
*
name
)
{
decoder_plugins_f
or_each_enabled
(
plugin
)
if
(
strcmp
(
plugin
->
name
,
name
)
==
0
)
return
plugin
;
decoder_plugins_f
ind
([
=
](
const
DecoderPlugin
&
plugin
){
return
strcmp
(
plugin
.
name
,
name
)
==
0
;
})
;
return
nullptr
;
}
...
...
@@ -233,6 +233,7 @@ void decoder_plugin_init_all(void)
void
decoder_plugin_deinit_all
(
void
)
{
decoder_plugins_for_each_enabled
(
plugin
)
plugin
->
Finish
();
decoder_plugins_for_each_enabled
([
=
](
const
DecoderPlugin
&
plugin
){
plugin
.
Finish
();
});
}
src/DecoderList.hxx
View file @
74904b9c
...
...
@@ -25,16 +25,6 @@ struct DecoderPlugin;
extern
const
struct
DecoderPlugin
*
const
decoder_plugins
[];
extern
bool
decoder_plugins_enabled
[];
#define decoder_plugins_for_each(plugin) \
for (const struct DecoderPlugin *plugin, \
*const*decoder_plugin_iterator = &decoder_plugins[0]; \
(plugin = *decoder_plugin_iterator) != nullptr; \
++decoder_plugin_iterator)
#define decoder_plugins_for_each_enabled(plugin) \
decoder_plugins_for_each(plugin) \
if (decoder_plugins_enabled[decoder_plugin_iterator - decoder_plugins])
/* interface for using plugins */
/**
...
...
@@ -60,4 +50,32 @@ void decoder_plugin_init_all(void);
/* this is where we "unload" all the "plugins" */
void
decoder_plugin_deinit_all
(
void
);
template
<
typename
F
>
static
inline
const
DecoderPlugin
*
decoder_plugins_find
(
F
f
)
{
for
(
unsigned
i
=
0
;
decoder_plugins
[
i
]
!=
nullptr
;
++
i
)
if
(
decoder_plugins_enabled
[
i
]
&&
f
(
*
decoder_plugins
[
i
]))
return
decoder_plugins
[
i
];
return
nullptr
;
}
template
<
typename
F
>
static
inline
void
decoder_plugins_for_each
(
F
f
)
{
for
(
auto
i
=
decoder_plugins
;
*
i
!=
nullptr
;
++
i
)
f
(
**
i
);
}
template
<
typename
F
>
static
inline
void
decoder_plugins_for_each_enabled
(
F
f
)
{
for
(
unsigned
i
=
0
;
decoder_plugins
[
i
]
!=
nullptr
;
++
i
)
if
(
decoder_plugins_enabled
[
i
])
f
(
*
decoder_plugins
[
i
]);
}
#endif
src/DecoderPrint.cxx
View file @
74904b9c
...
...
@@ -23,31 +23,33 @@
#include "DecoderPlugin.hxx"
#include "Client.hxx"
#include <functional>
#include <assert.h>
static
void
decoder_plugin_print
(
Client
&
client
,
const
struct
DecoderPlugin
*
plugin
)
const
DecoderPlugin
&
plugin
)
{
const
char
*
const
*
p
;
assert
(
plugin
!=
nullptr
);
assert
(
plugin
->
name
!=
nullptr
);
assert
(
plugin
.
name
!=
nullptr
);
client_printf
(
client
,
"plugin: %s
\n
"
,
plugin
->
name
);
client_printf
(
client
,
"plugin: %s
\n
"
,
plugin
.
name
);
if
(
plugin
->
suffixes
!=
nullptr
)
for
(
p
=
plugin
->
suffixes
;
*
p
!=
nullptr
;
++
p
)
if
(
plugin
.
suffixes
!=
nullptr
)
for
(
p
=
plugin
.
suffixes
;
*
p
!=
nullptr
;
++
p
)
client_printf
(
client
,
"suffix: %s
\n
"
,
*
p
);
if
(
plugin
->
mime_types
!=
nullptr
)
for
(
p
=
plugin
->
mime_types
;
*
p
!=
nullptr
;
++
p
)
if
(
plugin
.
mime_types
!=
nullptr
)
for
(
p
=
plugin
.
mime_types
;
*
p
!=
nullptr
;
++
p
)
client_printf
(
client
,
"mime_type: %s
\n
"
,
*
p
);
}
void
decoder_list_print
(
Client
&
client
)
{
decoder_plugins_for_each_enabled
(
plugin
)
decoder_plugin_print
(
client
,
plugin
);
using
namespace
std
::
placeholders
;
const
auto
f
=
std
::
bind
(
decoder_plugin_print
,
std
::
ref
(
client
),
_1
);
decoder_plugins_for_each_enabled
(
f
);
}
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