ImFusion SDK 4.3
TemporaryFile Class Reference

#include <ImFusion/Core/Filesystem/TemporaryFile.h>

Temporary file which deletes itself upon going out of scope. More...

+ Inheritance diagram for TemporaryFile:

Detailed Description

Temporary file which deletes itself upon going out of scope.

Public Types

enum class  Policy { Create , CreateRecursive , DoNotCreate }
 TemporaryFile Construction Policy.
 

Public Member Functions

 TemporaryFile (const Path &path={}, Policy policy=Policy::CreateRecursive)
 Constructs a TemporaryFile with a given path and policy.
 
- Public Member Functions inherited from File
 File (const Path &path)
 Create a new File instance for the given path.
 
 File (const std::string &path)
 Create a new File instance for the given path.
 
 File (const char *path)
 Create a new File instance for the given path.
 
 operator Path () const
 Allow for implicit conversion to a Path.
 
const Pathpath () const
 Gets the path of the file.
 
std::string string () const
 Gets the path of the file as string.
 
Directory parentDirectory () const
 Returns the absolute path to the parent directory, convenience function for Directory(path().parentPath()).
 
Path parentPath () const
 Returns the absolute path to the parent directory, convenience function for path().parentPath().
 
std::string name () const
 Gets the name of the file including the extension.
 
bool exists () const
 Checks if the file exists and actually is a file.
 
bool isExecutable () const
 Checks if the file is executable (and exists).
 
ByteSize size () const
 Gets the size of the file in bytes.
 
time_t lastModified () const
 Gets the time of the last modification to the file.
 
bool copyTo (const Path &destination, Flags< CopyOptions > copyOptions=CopyOptions::None) const
 Copies this single file to destination using the provided copy options.
 
bool rename (const Path &newName)
 Renames the file, including extension.
 
bool remove () const
 Delete the file.
 
bool create () const
 Creates the file without any content.
 
bool createRecursive () const
 Create the file without any content including the parent directory if needed.
 
ByteBuffer readBinary () const
 Read the entire content of the file in a binary fashion and return it as buffer.
 
std::vector< std::stringreadText () const
 Read the entire content of the file in a text-based fashion and return it as vector of lines.
 
bool writeBinary (const ByteBufferView &data) const
 Write the given data to the file in a binary fashion.
 
bool writeText (const std::vector< std::string > &lines) const
 Write the given list of strings into the file in a text-based fashion inserting a newline character (\n) after each line.
 
bool appendBinary (const ByteBufferView &data) const
 Append the given data to the file in a binary fashion.
 
bool appendText (const std::vector< std::string > &lines) const
 Append the given list of strings into the file in a text-based fashion inserting a newline character (\n) after each line.
 
std::ifstream openForReading (std::ios_base::openmode openmode=std::ios_base::in) const
 Create an input file stream for reading from the file.
 
std::ofstream openForWriting (std::ios_base::openmode openmode=std::ios_base::out) const
 Create an output file stream for writing to the file.
 

Additional Inherited Members

- Protected Member Functions inherited from NotCopyable
 NotCopyable (NotCopyable &&) noexcept=default
 
NotCopyableoperator= (NotCopyable &&) noexcept=default
 
 NotCopyable (const NotCopyable &)=delete
 
NotCopyableoperator= (const NotCopyable &)=delete
 

Constructor & Destructor Documentation

◆ TemporaryFile()

TemporaryFile ( const Path & path = {},
Policy policy = Policy::CreateRecursive )
explicit

Constructs a TemporaryFile with a given path and policy.

Parameters
pathThe path where the temporary file will be created. Relative paths are considered relative to the current working directory.
  • If path is empty (default), a file with a randomized name is created in the system's temporary file directory.
  • If path represents a directory, a file with a randomized name is created in path.
  • If path represents a file, it will be used for the filename and path. The path can optionally include percent sign characters to specify replacement by a random hexadecimal digit. For example:
    TemporaryFile("/my/tempfile/directory%%/%%%%%.png");
    TemporaryFile(const Path &path={}, Policy policy=Policy::CreateRecursive)
    Constructs a TemporaryFile with a given path and policy.
policyThe policy of how the temporary file should be created.
  • Create: Create the file immediately upon construction. If path is not empty, and the parent directory of the given path doesn't exit, this will not create them.
  • CreateRecursive (default): Create the file and parent directories immediately upon construction.
  • DoNotCreate: Will not create the file on the filesystem. You can subsequently create the file manually by calling create().

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close