RADLib
RADical C++ application framework
RADCore::RADTemporaryFile Class Reference

RAII temporary file with optional auto-remove. More...

#include <RADCore.h>

Public Member Functions

 RADTemporaryFile (std::string prefix="radlib")
 Creates a temporary file with prefix. More...
 
 ~RADTemporaryFile ()
 Closes and removes the file when autoRemove is enabled. More...
 
 RADTemporaryFile (const RADTemporaryFile &)=delete
 Temporary files own a file descriptor and cannot be copied. More...
 
RADTemporaryFileoperator= (const RADTemporaryFile &)=delete
 Temporary files own a file descriptor and cannot be copied. More...
 
 RADTemporaryFile (RADTemporaryFile &&other) noexcept
 Moves ownership from other. More...
 
RADTemporaryFileoperator= (RADTemporaryFile &&other) noexcept
 Moves ownership from other. More...
 
bool isValid () const
 Returns true when file creation succeeded. More...
 
const std::string & fileName () const
 Returns the temporary file path. More...
 
int fd () const
 Returns the native file descriptor. More...
 
void setAutoRemove (bool enabled)
 Enables or disables removal on destruction. More...
 
bool autoRemove () const
 Returns true when destruction removes the file. More...
 
bool remove ()
 Removes the temporary file immediately. More...
 

Detailed Description

RAII temporary file with optional auto-remove.

Constructor & Destructor Documentation

◆ RADTemporaryFile() [1/3]

RADCore::RADTemporaryFile::RADTemporaryFile ( std::string  prefix = "radlib")
explicit

Creates a temporary file with prefix.

◆ ~RADTemporaryFile()

RADCore::RADTemporaryFile::~RADTemporaryFile ( )

Closes and removes the file when autoRemove is enabled.

◆ RADTemporaryFile() [2/3]

RADCore::RADTemporaryFile::RADTemporaryFile ( const RADTemporaryFile )
delete

Temporary files own a file descriptor and cannot be copied.

◆ RADTemporaryFile() [3/3]

RADCore::RADTemporaryFile::RADTemporaryFile ( RADTemporaryFile &&  other)
noexcept

Moves ownership from other.

Member Function Documentation

◆ autoRemove()

bool RADCore::RADTemporaryFile::autoRemove ( ) const

Returns true when destruction removes the file.

◆ fd()

int RADCore::RADTemporaryFile::fd ( ) const

Returns the native file descriptor.

◆ fileName()

const std::string& RADCore::RADTemporaryFile::fileName ( ) const

Returns the temporary file path.

◆ isValid()

bool RADCore::RADTemporaryFile::isValid ( ) const

Returns true when file creation succeeded.

◆ operator=() [1/2]

RADTemporaryFile& RADCore::RADTemporaryFile::operator= ( const RADTemporaryFile )
delete

Temporary files own a file descriptor and cannot be copied.

◆ operator=() [2/2]

RADTemporaryFile& RADCore::RADTemporaryFile::operator= ( RADTemporaryFile &&  other)
noexcept

Moves ownership from other.

◆ remove()

bool RADCore::RADTemporaryFile::remove ( )

Removes the temporary file immediately.

◆ setAutoRemove()

void RADCore::RADTemporaryFile::setAutoRemove ( bool  enabled)

Enables or disables removal on destruction.


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