tag/Handler: convert to class with virtual methods

This commit is contained in:
Max Kellermann
2018-07-05 19:07:05 +02:00
parent 09d4176210
commit 3d3a1232b1
49 changed files with 414 additions and 496 deletions

View File

@@ -36,21 +36,20 @@ class TagFileScan {
const Path path_fs;
const char *const suffix;
const TagHandler &handler;
void *handler_ctx;
TagHandler &handler;
Mutex mutex;
InputStreamPtr is;
public:
TagFileScan(Path _path_fs, const char *_suffix,
const TagHandler &_handler, void *_handler_ctx) noexcept
TagHandler &_handler) noexcept
:path_fs(_path_fs), suffix(_suffix),
handler(_handler), handler_ctx(_handler_ctx) ,
handler(_handler),
is(nullptr) {}
bool ScanFile(const DecoderPlugin &plugin) noexcept {
return plugin.ScanFile(path_fs, handler, handler_ctx);
return plugin.ScanFile(path_fs, handler);
}
bool ScanStream(const DecoderPlugin &plugin) noexcept {
@@ -72,7 +71,7 @@ public:
}
/* now try the stream_tag() method */
return plugin.ScanStream(*is, handler, handler_ctx);
return plugin.ScanStream(*is, handler);
}
bool Scan(const DecoderPlugin &plugin) noexcept {
@@ -82,8 +81,7 @@ public:
};
bool
tag_file_scan(Path path_fs,
const TagHandler &handler, void *handler_ctx) noexcept
tag_file_scan(Path path_fs, TagHandler &handler) noexcept
{
assert(!path_fs.IsNull());
@@ -95,7 +93,7 @@ tag_file_scan(Path path_fs,
const auto suffix_utf8 = Path::FromFS(suffix).ToUTF8();
TagFileScan tfs(path_fs, suffix_utf8.c_str(), handler, handler_ctx);
TagFileScan tfs(path_fs, suffix_utf8.c_str(), handler);
return decoder_plugins_try([&](const DecoderPlugin &plugin){
return tfs.Scan(plugin);
});
@@ -104,11 +102,13 @@ tag_file_scan(Path path_fs,
bool
tag_file_scan(Path path, TagBuilder &builder) noexcept
{
if (!tag_file_scan(path, full_tag_handler, &builder))
FullTagHandler h(builder);
if (!tag_file_scan(path, h))
return false;
if (builder.empty())
ScanGenericTags(path, full_tag_handler, &builder);
ScanGenericTags(path, h);
return true;
}