bes  Updated for version 3.20.6
bes::TempFile Class Reference

Get a new temporary file. More...

#include <TempFile.h>

Collaboration diagram for bes::TempFile:
Collaboration graph

Public Member Functions

int get_fd () const
 
std::string get_name () const
 
 TempFile (const std::string &path_template=default_tmp_file_template, bool keep_temps=false)
 Get a new temporary file. More...
 
 ~TempFile ()
 Free the temporary file. More...
 

Static Public Member Functions

static void sigpipe_handler (int signal)
 

Friends

class TemporaryFileTest
 

Detailed Description

Get a new temporary file.

Get a new temporary file that will be closed and deleted when the instance is deleted (i.e., goes out of scope). The intent of this class is to build temporary files that will be closed/deleted regardless of how the caller exits - regularly or via an exception.

Definition at line 46 of file TempFile.h.

Constructor & Destructor Documentation

◆ TempFile()

bes::TempFile::TempFile ( const std::string &  path_template = default_tmp_file_template,
bool  keep_temps = false 
)

Get a new temporary file.

Get a new temporary file using the given template. The template must give the fully qualified path for the temporary file and must end in one or more Xs (but six are usually used) with no characters following.

Note
If you pass in a bad template, behavior of this class is undefined.
Parameters
path_templateTemplate passed to mkstemp() to build the temporary file pathname.
keep_tempsKeep the temporary files.

Definition at line 82 of file TempFile.cc.

◆ ~TempFile()

bes::TempFile::~TempFile ( )

Free the temporary file.

Close the open descriptor and delete (unlink) the file name.

Definition at line 121 of file TempFile.cc.

Member Function Documentation

◆ get_fd()

int bes::TempFile::get_fd ( ) const
inline
Returns
The temporary file's file descriptor

Definition at line 67 of file TempFile.h.

◆ get_name()

std::string bes::TempFile::get_name ( ) const
inline
Returns
The temporary file's name

Definition at line 70 of file TempFile.h.

◆ sigpipe_handler()

void bes::TempFile::sigpipe_handler ( int  sig)
static

We need to make sure that all of the open temporary files get cleaned up if bad things happen. So far, SIGPIPE is the only bad thing we know about at least with respect to the TempFile class.

Definition at line 54 of file TempFile.cc.


The documentation for this class was generated from the following files: