diff options
author | Max Kellermann <max@musicpd.org> | 2017-12-30 18:00:40 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-06-22 23:11:52 +0200 |
commit | 54d295c247deb1f543d922eb838d3eff2f7a89ce (patch) | |
tree | 1f97982f7a1feb5e70a9ff4cc29d0c08e197cf0c /src/MusicChunkPtr.hxx | |
parent | e81b089612833b61c566b482640615e182949ac6 (diff) |
MusicChunkPtr: managed MusicChunk pointer
Make all uses of MusicChunk safe.
Diffstat (limited to 'src/MusicChunkPtr.hxx')
-rw-r--r-- | src/MusicChunkPtr.hxx | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/MusicChunkPtr.hxx b/src/MusicChunkPtr.hxx new file mode 100644 index 000000000..81c8ad30e --- /dev/null +++ b/src/MusicChunkPtr.hxx @@ -0,0 +1,42 @@ +/* + * Copyright 2003-2018 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_MUSIC_CHUNK_PTR_HXX +#define MPD_MUSIC_CHUNK_PTR_HXX + +#include "check.h" + +#include <memory> + +struct MusicChunk; +class MusicBuffer; + +class MusicChunkDeleter { + MusicBuffer *buffer; + +public: + MusicChunkDeleter() = default; + explicit MusicChunkDeleter(MusicBuffer &_buffer):buffer(&_buffer) {} + + void operator()(MusicChunk *chunk) noexcept; +}; + +using MusicChunkPtr = std::unique_ptr<MusicChunk, MusicChunkDeleter>; + +#endif |