Open a file for writing.
- Parameters
-
| filepath | Path to the file |
| options | Write options (append, create, truncate, etc.) |
- Returns
- true if successful
Implements MayaFlux::IO::FileWriter.
Definition at line 26 of file TextFileWriter.cpp.
27{
29
32 }
33
36
37 std::ios_base::openmode mode = std::ios_base::out;
38
40 mode |= std::ios_base::app;
41 }
42
44 mode |= std::ios_base::trunc;
45 }
46
47 try {
48 std::filesystem::path path(filepath);
49 if (auto parent = path.parent_path(); !parent.empty()) {
50 std::filesystem::create_directories(parent);
51 }
52 } catch (const std::filesystem::filesystem_error& e) {
53 m_last_error = std::string(
"Failed to create directories: ") + e.what();
54 return false;
55 }
56
57 m_file.open(filepath, mode);
58
61 return false;
62 }
63
66
68 try {
70 } catch (...) {
72 }
73 }
74
75 return true;
76}
FileWriteOptions m_options
void close() override
Close the currently open file.
@ TRUNCATE
Truncate existing file.
@ APPEND
Append to existing file.
References MayaFlux::IO::APPEND, close(), m_bytes_written, m_file, m_filepath, m_is_open, m_last_error, m_mutex, m_options, MayaFlux::IO::NONE, and MayaFlux::IO::TRUNCATE.