specify TagsHandler::end_of_stream

This commit is contained in:
Frédéric Mangano 2016-03-03 09:48:52 +01:00 committed by Frédéric Mangano
parent 32c5e2b0a6
commit a78906a8d4
2 changed files with 14 additions and 2 deletions

View File

@ -7,8 +7,10 @@ void opustags::list_tags(ogg::Decoder &dec, ITagsHandler &handler)
std::shared_ptr<ogg::Stream> s;
while (!handler.done()) {
s = dec.read_page();
if (s == nullptr)
if (s == nullptr) {
handler.end_of_stream();
break; // end of stream
}
switch (s->state) {
case ogg::HEADER_READY:
if (!handler.relevant(s->stream.serialno))
@ -28,7 +30,7 @@ void opustags::edit_tags(
ogg::Decoder &in, ogg::Encoder &out, ITagsHandler &handler)
{
std::shared_ptr<ogg::Stream> s;
while (true) {
for (;;) {
s = in.read_page();
if (s == nullptr)
break; // end of stream
@ -60,4 +62,5 @@ void opustags::edit_tags(
;
}
}
handler.end_of_stream();
}

View File

@ -30,6 +30,15 @@ namespace opustags {
// use keeping reading the file for new streams. In that case, a true
// return value would abort any further processing.
virtual bool done() = 0;
// Signals the end of the stream.
// If after this function is called, done() returns false, it's an
// error. However, it would be better to raise the error inside
// end_of_stream().
// For example, if you expect to find the stream #1 and reach the
// end-of-stream before finding it, better tell the user that you
// didn't do what he expected.
virtual void end_of_stream() {}
};
}