mirror of
https://github.com/fmang/opustags.git
synced 2025-07-08 10:34:30 +02:00
Move TagsHandler to own file, make an interface
This commit is contained in:
@ -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) {
|
||||
|
@ -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 &);
|
||||
|
||||
}
|
||||
|
35
src/tags_handler.h
Normal file
35
src/tags_handler.h
Normal file
@ -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;
|
||||
};
|
||||
|
||||
}
|
Reference in New Issue
Block a user