MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ open()

bool MayaFlux::IO::TextFileWriter::open ( const std::string &  filepath,
FileWriteOptions  options 
)
overridevirtual

Open a file for writing.

Parameters
filepathPath to the file
optionsWrite options (append, create, truncate, etc.)
Returns
true if successful

Implements MayaFlux::IO::FileWriter.

Definition at line 26 of file TextFileWriter.cpp.

27{
28 std::lock_guard lock(m_mutex);
29
30 if (m_is_open) {
31 close();
32 }
33
35 m_options = options;
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(m_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(m_filepath, mode);
58
59 if (!m_file.is_open()) {
60 m_last_error = "Failed to open file: " + m_filepath;
61 return false;
62 }
63
64 m_is_open = true;
66
68 try {
69 m_bytes_written = std::filesystem::file_size(m_filepath);
70 } catch (...) {
72 }
73 }
74
75 return true;
76}
std::vector< uint32_t > parent
uint32_t mode
void close() override
Close the currently open file.
@ TRUNCATE
Truncate existing file.
@ APPEND
Append to existing file.
std::string resolve_write_path(const std::string &filepath, std::string_view default_directory=Config::OUT_DIR)
Resolve a writable path against the configured output directory.

References MayaFlux::IO::APPEND, close(), m_bytes_written, m_file, m_filepath, m_is_open, m_last_error, m_mutex, m_options, mode, MayaFlux::IO::NONE, parent, MayaFlux::IO::resolve_write_path(), and MayaFlux::IO::TRUNCATE.

+ Here is the call graph for this function: