Chemical Data Processing Library C++ API - Version 1.4.0
Public Member Functions | List of all members
CDPL::Util::FileRemover Class Reference

RAII helper that deletes a file when the FileRemover instance goes out of scope (unless released beforehand). Useful for guaranteeing the cleanup of temporary files. More...

#include <FileRemover.hpp>

Public Member Functions

 FileRemover (const std::string &path)
 Constructs a FileRemover guarding the file at path. More...
 
 ~FileRemover ()
 Destructor. Removes the file at the currently held path unless release() has been called. More...
 
const std::string & getPath () const
 Returns the file-system path currently guarded by the FileRemover. More...
 
void reset (const std::string &new_path)
 Replaces the currently held path with new_path; the previously held file is removed immediately. More...
 
void release ()
 Releases the FileRemover from its current path so that the file will not be removed on destruction. More...
 
FileRemoveroperator= (FileRemover &rhs)
 Move-style assignment: takes over the path held by rhs and releases rhs. More...
 

Detailed Description

RAII helper that deletes a file when the FileRemover instance goes out of scope (unless released beforehand). Useful for guaranteeing the cleanup of temporary files.

Constructor & Destructor Documentation

◆ FileRemover()

CDPL::Util::FileRemover::FileRemover ( const std::string &  path)
inline

Constructs a FileRemover guarding the file at path.

Parameters
pathThe file-system path of the file to remove on destruction.

◆ ~FileRemover()

CDPL::Util::FileRemover::~FileRemover ( )

Destructor. Removes the file at the currently held path unless release() has been called.

Member Function Documentation

◆ getPath()

const std::string& CDPL::Util::FileRemover::getPath ( ) const

Returns the file-system path currently guarded by the FileRemover.

Returns
A const reference to the file-system path.

◆ reset()

void CDPL::Util::FileRemover::reset ( const std::string &  new_path)

Replaces the currently held path with new_path; the previously held file is removed immediately.

Parameters
new_pathThe new file-system path to guard.

◆ release()

void CDPL::Util::FileRemover::release ( )

Releases the FileRemover from its current path so that the file will not be removed on destruction.

◆ operator=()

FileRemover& CDPL::Util::FileRemover::operator= ( FileRemover rhs)

Move-style assignment: takes over the path held by rhs and releases rhs.

Parameters
rhsThe FileRemover to take over from.
Returns
A reference to itself.

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