MPD: decoder/plugins/FlacStreamDecoder.hxx Source File

MPD 0.20.15

FlacStreamDecoder.hxx
Go to the documentation of this file.
1 /*
2 * Copyright 2003-2017 The Music Player Daemon Project
3 * http://www.musicpd.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MPD_FLAC_STREAM_DECODER
21 #define MPD_FLAC_STREAM_DECODER
22
23 #include "check.h"
24
25 #include <FLAC/stream_decoder.h>
26
27 #include <utility>
28 #include <stdexcept>
29
30 #include <assert.h>
31
35 class FlacStreamDecoder {
36 FLAC__StreamDecoder *decoder;
37
38 public:
39 FlacStreamDecoder()
40 :decoder(FLAC__stream_decoder_new()) {
41 if (decoder == nullptr)
42 throw std::runtime_error("FLAC__stream_decoder_new() failed");
43 }
44
45 FlacStreamDecoder(FlacStreamDecoder &&src)
46 :decoder(src.decoder) {
47 src.decoder = nullptr;
48 }
49
50 ~FlacStreamDecoder() {
51 if (decoder != nullptr)
52 FLAC__stream_decoder_delete(decoder);
53 }
54
55 FlacStreamDecoder &operator=(FlacStreamDecoder &&src) {
56 std::swap(decoder, src.decoder);
57 return *this;
58 }
59
60 operator bool() const {
61 return decoder != nullptr;
62 }
63
64 FLAC__StreamDecoder *get() {
65 assert(decoder != nullptr);
66
67 return decoder;
68 }
69 };
70
71 #endif
check.h
FlacStreamDecoder
OO wrapper for a FLAC__StreamDecoder.
Definition: FlacStreamDecoder.hxx:35
FlacStreamDecoder::~FlacStreamDecoder
~FlacStreamDecoder()
Definition: FlacStreamDecoder.hxx:50
FlacStreamDecoder::operator=
FlacStreamDecoder & operator=(FlacStreamDecoder &&src)
Definition: FlacStreamDecoder.hxx:55
FlacStreamDecoder::FlacStreamDecoder
FlacStreamDecoder(FlacStreamDecoder &&src)
Definition: FlacStreamDecoder.hxx:45
FlacStreamDecoder::FlacStreamDecoder
FlacStreamDecoder()
Definition: FlacStreamDecoder.hxx:39