diff --git a/src/actions.cc b/src/actions.cc index 9ca52a2..fa29759 100644 --- a/src/actions.cc +++ b/src/actions.cc @@ -2,7 +2,7 @@ using namespace opustags; -void opustags::list_tags(ogg::Decoder &dec, TagsHandler &handler) +void opustags::list_tags(ogg::Decoder &dec, ITagsHandler &handler) { ogg::Stream *s; while (!handler.done()) { @@ -24,7 +24,8 @@ void opustags::list_tags(ogg::Decoder &dec, TagsHandler &handler) } } -void opustags::edit_tags(ogg::Decoder &in, ogg::Encoder &out, TagsHandler &handler) +void opustags::edit_tags( + ogg::Decoder &in, ogg::Encoder &out, ITagsHandler &handler) { ogg::Stream *s; while (true) { diff --git a/src/actions.h b/src/actions.h index 68ef5de..9d0ee98 100644 --- a/src/actions.h +++ b/src/actions.h @@ -1,39 +1,10 @@ #pragma once -#include "tags.h" #include "ogg.h" +#include "tags_handler.h" namespace opustags { - // TagsHandler define various operations related to tags and stream in - // order to control the main loop. - // In its implementation, it is expected to receive an option structure. - struct TagsHandler - { - - // Irrelevant streams don't even need to be parsed, so we can save some - // effort with this method. - // Returns true if the stream should be parsed, false if it should be - // ignored (list) or copied identically (edit). - bool relevant(int streamno) { return false; } - - // The list method is called by list_tags every time it has - // successfully parsed an OpusTags header. - void list(int streamno, const Tags&) {} - - // Transform the tags at will. - // Returns true if the tags were indeed modified, false if they weren't. - // The latter case may be used for optimization. - bool edit(int streamno, Tags&) { return false; } - - // The work is done. - // When listing tags, once we've caught the streams we wanted, it's no - // use keeping reading the file for new streams. In that case, a true - // return value would abort any further processing. - bool done() { return false; } - - }; - // Decode a file and call the handler's list method every time a tags // header is read. // @@ -43,7 +14,7 @@ namespace opustags { // TagsLister lister(options); // list_tags(dec, lister); // - void list_tags(ogg::Decoder&, TagsHandler&); + void list_tags(ogg::Decoder&, ITagsHandler &); // Forward the input data to the output stream, transforming tags on-the-go // with the handler's edit method. @@ -56,6 +27,6 @@ namespace opustags { // TagsEditor editor(options); // edit_tags(dec, enc, editor); // - void edit_tags(ogg::Decoder &in, ogg::Encoder &out, TagsHandler&); + void edit_tags(ogg::Decoder &in, ogg::Encoder &out, ITagsHandler &); } diff --git a/src/tags_handler.h b/src/tags_handler.h new file mode 100644 index 0000000..712b25a --- /dev/null +++ b/src/tags_handler.h @@ -0,0 +1,35 @@ +#pragma once + +#include "tags.h" + +namespace opustags { + + // TagsHandler define various operations related to tags and stream in + // order to control the main loop. + // In its implementation, it is expected to receive an option structure. + class ITagsHandler + { + public: + // Irrelevant streams don't even need to be parsed, so we can save some + // effort with this method. + // Returns true if the stream should be parsed, false if it should be + // ignored (list) or copied identically (edit). + virtual bool relevant(const int streamno) = 0; + + // The list method is called by list_tags every time it has + // successfully parsed an OpusTags header. + virtual void list(const int streamno, const Tags &) = 0; + + // Transform the tags at will. + // Returns true if the tags were indeed modified, false if they weren't. + // The latter case may be used for optimization. + virtual bool edit(const int streamno, Tags &) = 0; + + // The work is done. + // When listing tags, once we've caught the streams we wanted, it's no + // use keeping reading the file for new streams. In that case, a true + // return value would abort any further processing. + virtual bool done() = 0; + }; + +}