1 #ifndef AUDIOGRAPHER_TMP_FILE_H
2 #define AUDIOGRAPHER_TMP_FILE_H
8 #include <glib/gstdio.h>
10 #include "sndfile_writer.h"
11 #include "sndfile_reader.h"
13 namespace AudioGrapher
16 /// A temporary file deleted after this class is destructed
17 template<typename T = DefaultSampleType>
18 class TmpFile : public SndfileWriter<T>, public SndfileReader<T>
22 /// \a filename_template must match the requirements for mkstemp, i.e. end in "XXXXXX"
23 TmpFile (char * filename_template, int format, ChannelCount channels, framecnt_t samplerate)
24 : SndfileHandle (g_mkstemp(filename_template), true, SndfileBase::ReadWrite, format, channels, samplerate)
25 , filename (filename_template)
28 TmpFile (int format, ChannelCount channels, framecnt_t samplerate)
29 : SndfileHandle (fileno (tmpfile()), true, SndfileBase::ReadWrite, format, channels, samplerate)
32 TmpFile (TmpFile const & other) : SndfileHandle (other) {}
33 using SndfileHandle::operator=;
37 if (!filename.empty()) {
38 std::remove(filename.c_str());
48 #endif // AUDIOGRAPHER_TMP_FILE_H