|
| | TempFile (const std::string &file_name, const std::string &file_ext="") |
| | Creates a temp file using file_name and file_ext. More...
|
| |
| | ~TempFile () |
| |
| | TempFile (const TempFile &)=delete |
| |
| | TempFile (TempFile &&)=delete |
| |
| TempFile & | operator= (const TempFile &)=delete |
| |
| TempFile & | operator= (TempFile &&)=delete |
| |
| void | retain (bool should_retain) |
| | If set to true, we will retain the file after the instance is destroyed. More...
|
| |
| bool | retain () const |
| | Returns true if the file will be retained after the instance is destroyed, false otherwise (default) More...
|
| |
| bool | open (std::ios_base::openmode mode=std::ios::out|std::ios::trunc) |
| | Opens the temporary file for writing. More...
|
| |
| void | close () |
| | Closes the temporary file if it is open. More...
|
| |
| template<typename StringType > |
| void | write (StringType &&content, std::ios::openmode mode=std::ios::out|std::ios::trunc, bool preserve_file_state=true) |
| |
| bool | is_open () const |
| | Checks if the temporary file is currently open. More...
|
| |
| const std::string & | getPath () const |
| | Returns the path to the temporary file. More...
|
| |
| std::string | getFileContents () const |
| | Loads the contents of the file into a string and returns it. More...
|
| |
| template<typename T > |
| TempFile & | operator<< (const T &data) |
| | Overload the << operator to write data to the file (for general types) More...
|
| |
| TempFile & | operator<< (std::ostream &(*manip)(std::ostream &)) |
| | Overload the << operator to support manipulators (e.g., std::endl) More...
|
| |
/brief Utility class for managing temporary files.
The TempFile class provides a convenient way to create and manage temporary files. It ensures that the file is deleted upon destruction, unless the user calls retain(true) The class is non-copyable to prevent accidental duplication of file handles.
- Note
- The path to the temp file is likely different from the supplied file_name
template<typename StringType >
| void axom::utilities::filesystem::TempFile::write |
( |
StringType && |
content, |
|
|
std::ios::openmode |
mode = std::ios::out | std::ios::trunc, |
|
|
bool |
preserve_file_state = true |
|
) |
| |
|
inline |
Writes contents to the file
Opens the file if it is not already open using mode and optionally closes the file
- Parameters
-
| content | A string to write to the file |
| mode | The ios mode to open the file |
| preserve_file_state | Controls whether the file should be closed if we had to open it If false, the file will be left open. If true, it will be left in its initial state |
References close(), is_open(), and open().