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

◆ open()

bool MayaFlux::IO::XmlWriter::open ( const std::string & filepath,
const Kakshya::CompositeLayout & layout )
overridevirtual

Start a document using xml_composite_layout().

Implements MayaFlux::IO::CompositeWriter.

Definition at line 90 of file XmlWriter.cpp.

92{
93 if (m_open) {
94 m_last_error = "Close the current XML document before opening another";
95 return false;
96 }
97
98 m_last_error.clear();
99 if (!can_write(filepath)) {
100 m_last_error = "Expected an .xml output path";
101 return false;
102 }
103
104 if (!layout.same_structure(xml_composite_layout())) {
105 m_last_error = "XML output requires xml_composite_layout()";
106 return false;
107 }
108
109 m_xml = std::make_unique<Impl>();
110 m_content_started.clear();
111 m_ancestors.clear();
112 m_filepath = resolve_write_path(filepath);
113
114 std::ofstream output(m_filepath, std::ios::binary | std::ios::trunc);
115 if (!output) {
116 m_last_error = "Cannot open XML output";
117 return false;
118 }
119
120 output.close();
121 if (!output) {
122 m_last_error = "Cannot initialize XML output";
123 return false;
124 }
125
126 m_failed = false;
127 m_declaration_seen = false;
128 m_doctype_seen = false;
129 m_root_count = 0;
130 m_open = true;
131
132 return true;
133}
std::vector< bool > m_content_started
Definition XmlWriter.hpp:68
std::unique_ptr< Impl > m_xml
Definition XmlWriter.hpp:67
bool can_write(const std::string &filepath) const override
Accept paths with the .xml extension.
Definition XmlWriter.cpp:85
std::vector< uint64_t > m_ancestors
Definition XmlWriter.hpp:69
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.
Kakshya::CompositeLayout xml_composite_layout()
Composite row layout used by the XML reader and writer.
Definition XmlReader.cpp:13

References can_write(), m_ancestors, m_content_started, m_declaration_seen, m_doctype_seen, m_failed, m_filepath, m_last_error, m_open, m_root_count, m_xml, MayaFlux::IO::resolve_write_path(), MayaFlux::Kakshya::CompositeLayout::same_structure(), and MayaFlux::IO::xml_composite_layout().

Referenced by XmlWriter().

Here is the call graph for this function:
Here is the caller graph for this function: