CBMC
tempfile.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening
6 
7 \*******************************************************************/
8 
9 
10 #ifndef CPROVER_UTIL_TEMPFILE_H
11 #define CPROVER_UTIL_TEMPFILE_H
12 
13 #include <string>
14 
15 // Returns an unused file name for a writeable temporary file,
16 // and makes sure it exists.
17 std::string get_temporary_file(
18  const std::string &prefix,
19  const std::string &suffix);
20 
21 // The below deletes the temporary file upon destruction,
22 // cleaning up after you in case of exceptions.
24 {
25 public:
27  const std::string &prefix,
28  const std::string &suffix):
29  name(get_temporary_file(prefix, suffix))
30  {
31  }
32 
33  // Using the copy constructor would delete the file twice.
35 
37  {
38  name.swap(other.name);
39  }
40 
41  // get the name
42  std::string operator()() const
43  {
44  return name;
45  }
46 
47  // will delete the file
49 
50 protected:
51  std::string name;
52 };
53 
54 #endif // CPROVER_UTIL_TEMPFILE_H
temporary_filet(temporary_filet &&other)
Definition: tempfile.h:36
temporary_filet(const temporary_filet &)=delete
std::string name
Definition: tempfile.h:51
temporary_filet(const std::string &prefix, const std::string &suffix)
Definition: tempfile.h:26
std::string operator()() const
Definition: tempfile.h:42
std::string get_temporary_file(const std::string &prefix, const std::string &suffix)
Substitute for mkstemps (OpenBSD standard) for Windows, where it is unavailable.
Definition: tempfile.cpp:99