1 #ifndef AUDIOGRAPHER_TMP_FILE_H
2 #define AUDIOGRAPHER_TMP_FILE_H
7 #include "sndfile_writer.h"
8 #include "sndfile_reader.h"
10 namespace AudioGrapher
13 /// A temporary file deleted after this class is destructed
14 template<typename T = DefaultSampleType>
15 class TmpFile : public SndfileWriter<T>, public SndfileReader<T>
19 /// \a filename_template must match the requirements for mkstemp, i.e. end in "XXXXXX"
20 TmpFile (char * filename_template, int format, ChannelCount channels, framecnt_t samplerate)
21 : SndfileHandle (mkstemp(filename_template), true, SndfileBase::ReadWrite, format, channels, samplerate)
22 , filename (filename_template)
25 TmpFile (int format, ChannelCount channels, framecnt_t samplerate)
26 : SndfileHandle (fileno (tmpfile()), true, SndfileBase::ReadWrite, format, channels, samplerate)
29 TmpFile (TmpFile const & other) : SndfileHandle (other) {}
30 using SndfileHandle::operator=;
34 if (!filename.empty()) {
35 std::remove(filename.c_str());
45 #endif // AUDIOGRAPHER_TMP_FILE_H