#ifndef UTILS_TEMPFILE_H #define UTILS_TEMPFILE_H #include #include struct temp_file_t /* Provides a scoped temporary file. File's filename is obtained from tmpnam or as a constructor parameter. The file is deleted by the destructor. Clients use the public `stream' member to write to the file. the `close_and_move' function close the file and moves it to the new filename, useful for programmes that want to ensure that a generated file is either created correctly or not created at all.*/ { temp_file_t(); explicit temp_file_t( const std::string& filename); ~temp_file_t(); std::ofstream stream; std::string filename; void close_and_move( const std::string& newfilename); private: void open( const std::string& newfilename); void close(); }; #endif