tag/TagHandler: pass by reference

This commit is contained in:
Max Kellermann
2016-02-23 10:10:13 +01:00
parent 7623c1c5cb
commit 73307bf2e7
37 changed files with 100 additions and 104 deletions

View File

@@ -77,7 +77,7 @@ ForEachValue(const char *value, const char *end, C &&callback)
static bool
tag_ape_import_item(unsigned long flags,
const char *key, StringView value,
const TagHandler *handler, void *handler_ctx)
const TagHandler &handler, void *handler_ctx)
{
/* we only care about utf-8 text tags */
if ((flags & (0x3 << 1)) != 0)
@@ -86,10 +86,10 @@ tag_ape_import_item(unsigned long flags,
const auto begin = value.begin();
const auto end = value.end();
if (handler->pair != nullptr)
if (handler.pair != nullptr)
ForEachValue(begin, end, [handler, handler_ctx,
key](const char *_value) {
handler->pair(key, _value, handler_ctx);
handler.pair(key, _value, handler_ctx);
});
TagType type = tag_ape_name_parse(key);
@@ -107,7 +107,7 @@ tag_ape_import_item(unsigned long flags,
bool
tag_ape_scan2(InputStream &is,
const TagHandler *handler, void *handler_ctx)
const TagHandler &handler, void *handler_ctx)
{
bool recognized = false;
@@ -124,7 +124,7 @@ tag_ape_scan2(InputStream &is,
bool
tag_ape_scan2(Path path_fs,
const TagHandler *handler, void *handler_ctx)
const TagHandler &handler, void *handler_ctx)
{
bool recognized = false;

View File

@@ -35,7 +35,7 @@ extern const struct tag_table ape_tags[];
*/
bool
tag_ape_scan2(InputStream &is,
const TagHandler *handler, void *handler_ctx);
const TagHandler &handler, void *handler_ctx);
/**
* Scan the APE tags of a file.
@@ -44,6 +44,6 @@ tag_ape_scan2(InputStream &is,
*/
bool
tag_ape_scan2(Path path_fs,
const TagHandler *handler, void *handler_ctx);
const TagHandler &handler, void *handler_ctx);
#endif

View File

@@ -29,6 +29,6 @@
bool
ScanGenericTags(Path path, const TagHandler &handler, void *ctx)
{
return tag_ape_scan2(path, &handler, ctx) ||
tag_id3_scan(path, &handler, ctx);
return tag_ape_scan2(path, handler, ctx) ||
tag_id3_scan(path, handler, ctx);
}

View File

@@ -53,37 +53,33 @@ struct TagHandler {
};
static inline void
tag_handler_invoke_duration(const TagHandler *handler, void *ctx,
tag_handler_invoke_duration(const TagHandler &handler, void *ctx,
SongTime duration)
{
assert(handler != nullptr);
if (handler->duration != nullptr)
handler->duration(duration, ctx);
if (handler.duration != nullptr)
handler.duration(duration, ctx);
}
static inline void
tag_handler_invoke_tag(const TagHandler *handler, void *ctx,
tag_handler_invoke_tag(const TagHandler &handler, void *ctx,
TagType type, const char *value)
{
assert(handler != nullptr);
assert((unsigned)type < TAG_NUM_OF_ITEM_TYPES);
assert(value != nullptr);
if (handler->tag != nullptr)
handler->tag(type, value, ctx);
if (handler.tag != nullptr)
handler.tag(type, value, ctx);
}
static inline void
tag_handler_invoke_pair(const TagHandler *handler, void *ctx,
tag_handler_invoke_pair(const TagHandler &handler, void *ctx,
const char *name, const char *value)
{
assert(handler != nullptr);
assert(name != nullptr);
assert(value != nullptr);
if (handler->pair != nullptr)
handler->pair(name, value, ctx);
if (handler.pair != nullptr)
handler.pair(name, value, ctx);
}
/**

View File

@@ -97,7 +97,7 @@ import_id3_string(const id3_ucs4_t *ucs4)
static void
tag_id3_import_text_frame(const struct id3_frame *frame,
TagType type,
const TagHandler *handler, void *handler_ctx)
const TagHandler &handler, void *handler_ctx)
{
if (frame->nfields != 2)
return;
@@ -140,7 +140,7 @@ tag_id3_import_text_frame(const struct id3_frame *frame,
*/
static void
tag_id3_import_text(struct id3_tag *tag, const char *id, TagType type,
const TagHandler *handler, void *handler_ctx)
const TagHandler &handler, void *handler_ctx)
{
const struct id3_frame *frame;
for (unsigned i = 0;
@@ -160,7 +160,7 @@ tag_id3_import_text(struct id3_tag *tag, const char *id, TagType type,
*/
static void
tag_id3_import_comment_frame(const struct id3_frame *frame, TagType type,
const TagHandler *handler,
const TagHandler &handler,
void *handler_ctx)
{
if (frame->nfields != 4)
@@ -189,7 +189,7 @@ tag_id3_import_comment_frame(const struct id3_frame *frame, TagType type,
*/
static void
tag_id3_import_comment(struct id3_tag *tag, const char *id, TagType type,
const TagHandler *handler, void *handler_ctx)
const TagHandler &handler, void *handler_ctx)
{
const struct id3_frame *frame;
for (unsigned i = 0;
@@ -226,7 +226,7 @@ tag_id3_parse_txxx_name(const char *name)
*/
static void
tag_id3_import_musicbrainz(struct id3_tag *id3_tag,
const TagHandler *handler,
const TagHandler &handler,
void *handler_ctx)
{
for (unsigned i = 0;; ++i) {
@@ -262,7 +262,7 @@ tag_id3_import_musicbrainz(struct id3_tag *id3_tag,
*/
static void
tag_id3_import_ufid(struct id3_tag *id3_tag,
const TagHandler *handler, void *handler_ctx)
const TagHandler &handler, void *handler_ctx)
{
for (unsigned i = 0;; ++i) {
const id3_frame *frame = id3_tag_findframe(id3_tag, "UFID", i);
@@ -296,7 +296,7 @@ tag_id3_import_ufid(struct id3_tag *id3_tag,
void
scan_id3_tag(struct id3_tag *tag,
const TagHandler *handler, void *handler_ctx)
const TagHandler &handler, void *handler_ctx)
{
tag_id3_import_text(tag, ID3_FRAME_ARTIST, TAG_ARTIST,
handler, handler_ctx);
@@ -337,7 +337,7 @@ Tag *
tag_id3_import(struct id3_tag *tag)
{
TagBuilder tag_builder;
scan_id3_tag(tag, &add_tag_handler, &tag_builder);
scan_id3_tag(tag, add_tag_handler, &tag_builder);
return tag_builder.IsEmpty()
? nullptr
: tag_builder.CommitNew();
@@ -345,7 +345,7 @@ tag_id3_import(struct id3_tag *tag)
bool
tag_id3_scan(Path path_fs,
const TagHandler *handler, void *handler_ctx)
const TagHandler &handler, void *handler_ctx)
{
UniqueId3Tag tag;

View File

@@ -32,7 +32,7 @@ struct id3_tag;
bool
tag_id3_scan(Path path_fs,
const TagHandler *handler, void *handler_ctx);
const TagHandler &handler, void *handler_ctx);
Tag *
tag_id3_import(id3_tag *);
@@ -43,7 +43,7 @@ tag_id3_import(id3_tag *);
*/
void
scan_id3_tag(id3_tag *tag,
const TagHandler *handler, void *handler_ctx);
const TagHandler &handler, void *handler_ctx);
#else
@@ -51,7 +51,7 @@ scan_id3_tag(id3_tag *tag,
static inline bool
tag_id3_scan(gcc_unused Path path_fs,
gcc_unused const TagHandler *handler,
gcc_unused const TagHandler &handler,
gcc_unused void *handler_ctx)
{
return false;