TemporaryFile.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2006 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/Util/genutil/TemporaryFile.h
10 
11 #ifndef __TemporaryFile_h
12 #define __TemporaryFile_h
13 
14 #include "Reference.h"
15 
16 #include <string>
17 #include <set>
18 
21 {
22 
23  public:
24 
26  static bool abort;
27 
29  TemporaryFile (const std::string& basename);
30 
32  ~TemporaryFile ();
33 
35  void close ();
36 
38  void unlink ();
39 
41  void remove ();
42 
44  int get_fd () const { return fd; }
45 
47  std::string get_filename () const { return filename; }
48 
50  void set_removed (bool flag = true) { unlinked = flag; }
51 
52  private:
53 
55  std::string filename;
56 
58  int fd;
59 
61  bool unlinked;
62 
64  static void install_signal_handler ();
65 
67  static bool signal_handler_installed;
68 
70  static void signal_handler (int);
71 
72 };
73 
74 #endif
75 
void set_removed(bool flag=true)
Set to true if the temporary file need not be removed.
Definition: TemporaryFile.h:55
A convenient exception handling class.
Definition: Error.h:54
std::string get_filename() const
Get the name of the temporary file.
Definition: TemporaryFile.h:52
int get_fd() const
Get the file descriptor of the temporary file.
Definition: TemporaryFile.h:49
void close()
Close the temporary file.
Definition: TemporaryFile.C:158
void remove()
Remove the temporary file (close and unlink)
Definition: TemporaryFile.C:170
Manages Reference::To references to the instance.
Definition: ReferenceAble.h:40
Opens a temporary file with a unique name and deletes it when finished.
Definition: TemporaryFile.h:20
static bool abort
Abort after processing any signals.
Definition: TemporaryFile.h:31
void unlink()
Unlink the temporary file.
Definition: TemporaryFile.C:176
~TemporaryFile()
Close and remove the temporary file.
Definition: TemporaryFile.C:143
TemporaryFile(const std::string &basename)
Construct a temporary file with the specified basename.
Definition: TemporaryFile.C:102

Generated using doxygen 1.8.17