#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/feature-white238-inlet_variant_containers/src/axom/core/utilities/FileUtilities.hpp>
|
| | 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
◆ TempFile() [1/3]
| axom::utilities::filesystem::TempFile::TempFile |
( |
const std::string & |
file_name, |
|
|
const std::string & |
file_ext = "" |
|
) |
| |
|
explicit |
Creates a temp file using file_name and file_ext.
- Parameters
-
| file_name | The name of the temporary file to create without extension |
| file_ext | An optional extension for the temp file |
- Note
- When creating the temp file, the name will likely be changed. You can get the actual file name using the getPath() function after the file is created.
◆ ~TempFile()
| axom::utilities::filesystem::TempFile::~TempFile |
( |
| ) |
|
◆ TempFile() [2/3]
| axom::utilities::filesystem::TempFile::TempFile |
( |
const TempFile & |
| ) |
|
|
delete |
◆ TempFile() [3/3]
| axom::utilities::filesystem::TempFile::TempFile |
( |
TempFile && |
| ) |
|
|
delete |
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ retain() [1/2]
| void axom::utilities::filesystem::TempFile::retain |
( |
bool |
should_retain | ) |
|
|
inline |
If set to true, we will retain the file after the instance is destroyed.
◆ retain() [2/2]
| bool axom::utilities::filesystem::TempFile::retain |
( |
| ) |
const |
|
inline |
Returns true if the file will be retained after the instance is destroyed, false otherwise (default)
◆ open()
| bool axom::utilities::filesystem::TempFile::open |
( |
std::ios_base::openmode |
mode = std::ios::out | std::ios::trunc | ) |
|
|
inline |
Opens the temporary file for writing.
- Parameters
-
| mode | ios flags for opening the file (not used if file is already open) |
- Returns
- true if the file was successfully opened, false otherwise.
◆ close()
| void axom::utilities::filesystem::TempFile::close |
( |
| ) |
|
|
inline |
Closes the temporary file if it is open.
◆ write()
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().
◆ is_open()
| bool axom::utilities::filesystem::TempFile::is_open |
( |
| ) |
const |
|
inline |
Checks if the temporary file is currently open.
- Returns
- true if the file is open, false otherwise.
◆ getPath()
| const std::string& axom::utilities::filesystem::TempFile::getPath |
( |
| ) |
const |
|
inline |
Returns the path to the temporary file.
◆ getFileContents()
| std::string axom::utilities::filesystem::TempFile::getFileContents |
( |
| ) |
const |
Loads the contents of the file into a string and returns it.
◆ operator<<() [1/2]
template<typename T >
| TempFile& axom::utilities::filesystem::TempFile::operator<< |
( |
const T & |
data | ) |
|
|
inline |
Overload the << operator to write data to the file (for general types)
◆ operator<<() [2/2]
| TempFile& axom::utilities::filesystem::TempFile::operator<< |
( |
std::ostream &(*)(std::ostream &) |
manip | ) |
|
|
inline |
Overload the << operator to support manipulators (e.g., std::endl)
The documentation for this class was generated from the following file:
- /home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/feature-white238-inlet_variant_containers/src/axom/core/utilities/FileUtilities.hpp