ogg: Decoder and Encoder to use a reference rather than a pointer

This commit is contained in:
Frédéric Mangano
2016-03-01 15:01:24 +01:00
parent f469d76e62
commit f941464c61
3 changed files with 16 additions and 16 deletions

View File

@ -10,7 +10,7 @@ namespace opustags {
//
// Use:
// std::ifstream in("in.ogg");
// ogg::Decoder dec(&in);
// ogg::Decoder dec(in);
// TagsLister lister(options);
// list_tags(dec, lister);
//
@ -21,9 +21,9 @@ namespace opustags {
//
// Use:
// std::ifstream in("in.ogg");
// ogg::Decoder dec(&in);
// ogg::Decoder dec(in);
// std::ofstream out("out.ogg");
// std::Encoder enc(&out);
// std::Encoder enc(out);
// TagsEditor editor(options);
// edit_tags(dec, enc, editor);
//

View File

@ -136,10 +136,10 @@ void ogg::Stream::downgrade()
////////////////////////////////////////////////////////////////////////////////
// ogg::Decoder
ogg::Decoder::Decoder(std::istream *in)
ogg::Decoder::Decoder(std::istream &in)
: input(in)
{
input->exceptions(std::ifstream::badbit);
input.exceptions(std::ifstream::badbit);
ogg_sync_init(&sync);
}
@ -185,23 +185,23 @@ bool ogg::Decoder::page_out()
// Read data from the stream into the sync's buffer.
bool ogg::Decoder::buff()
{
if (input->eof())
if (input.eof())
return false;
char *buf = ogg_sync_buffer(&sync, 65536);
if (buf == nullptr)
throw std::runtime_error("ogg_sync_buffer failed");
input->read(buf, 65536);
ogg_sync_wrote(&sync, input->gcount());
input.read(buf, 65536);
ogg_sync_wrote(&sync, input.gcount());
return true;
}
////////////////////////////////////////////////////////////////////////////////
// ogg::Encoder
ogg::Encoder::Encoder(std::ostream *out)
ogg::Encoder::Encoder(std::ostream &out)
: output(out)
{
output->exceptions(std::ifstream::badbit);
output.exceptions(std::ifstream::badbit);
}
ogg::Stream& ogg::Encoder::get_stream(int streamno)
@ -245,8 +245,8 @@ void ogg::Encoder::flush_stream(ogg::Stream &out)
void ogg::Encoder::write_raw_page(const ogg_page &og)
{
output->write(reinterpret_cast<const char*>(og.header), og.header_len);
output->write(reinterpret_cast<const char*>(og.body), og.body_len);
output.write(reinterpret_cast<const char*>(og.header), og.header_len);
output.write(reinterpret_cast<const char*>(og.body), og.body_len);
}
void ogg::Encoder::write_tags(int streamno, const Tags &tags)

View File

@ -70,7 +70,7 @@ namespace ogg
struct Decoder
{
Decoder(std::istream*);
Decoder(std::istream&);
~Decoder();
// Read a page, dispatch it, and return the stream it belongs to.
@ -79,7 +79,7 @@ namespace ogg
// After the end of the file is reached, it returns NULL.
Stream *read_page();
std::istream *input;
std::istream &input;
ogg_sync_state sync;
ogg_page current_page;
@ -92,7 +92,7 @@ namespace ogg
struct Encoder
{
Encoder(std::ostream*);
Encoder(std::ostream&);
// Copy the input stream's current page.
void forward(Stream &in);
@ -104,7 +104,7 @@ namespace ogg
void write_tags(int streamno, const Tags&);
std::ostream *output;
std::ostream &output;
// We're gonna need some ogg_stream_state for adjusting the page
// numbers and splitting large packets as it's gotta be done.