36#include "denigma/io/random_access_reader.h"
112 [[nodiscard]] std::span<const Diagnostic>
diagnostics() const noexcept
114 return m_diagnostics;
124 explicit operator bool() const noexcept
138 m_hasError = m_hasError || diagnostic.
severity == MessageSeverity::Error;
139 m_diagnostics.push_back(std::move(diagnostic));
143 std::vector<Diagnostic> m_diagnostics;
150template <
typename OptionsT>
156 if (
const auto* options =
dynamic_cast<const OptionsT*
>(request.
options)) {
159 assert(
false &&
"incompatible conversion options");
160 throw std::invalid_argument(std::string(converterName) +
" received incompatible conversion options.");
177 std::ostream& output,
195 std::ostream& output,
200using MultiOutputCallback = std::function<void(std::string_view suggestedName, std::span<const std::byte> data)>;
244 void add(std::unique_ptr<IConverter> converter)
247 throw std::invalid_argument(
"converter cannot be null");
249 m_converters.emplace_back(std::move(converter));
253 void add(std::unique_ptr<IMultiOutputConverter> converter)
256 throw std::invalid_argument(
"converter cannot be null");
258 m_multiOutputConverters.emplace_back(std::move(converter));
262 void add(std::unique_ptr<IReaderConverter> converter)
265 throw std::invalid_argument(
"converter cannot be null");
267 m_readerConverters.emplace_back(std::move(converter));
271 void add(std::unique_ptr<IReaderMultiOutputConverter> converter)
274 throw std::invalid_argument(
"converter cannot be null");
276 m_readerMultiOutputConverters.emplace_back(std::move(converter));
282 for (
const auto& converter : m_converters) {
283 if (converter->sourceFormat() == sourceFormat && converter->targetFormat() == targetFormat) {
284 return converter.get();
293 for (
const auto& converter : m_multiOutputConverters) {
294 if (converter->sourceFormat() == sourceFormat && converter->targetFormat() == targetFormat) {
295 return converter.get();
304 for (
const auto& converter : m_readerConverters) {
305 if (converter->sourceFormat() == sourceFormat && converter->targetFormat() == targetFormat) {
306 return converter.get();
315 for (
const auto& converter : m_readerMultiOutputConverters) {
316 if (converter->sourceFormat() == sourceFormat && converter->targetFormat() == targetFormat) {
317 return converter.get();
324 std::vector<std::unique_ptr<IConverter>> m_converters;
325 std::vector<std::unique_ptr<IMultiOutputConverter>> m_multiOutputConverters;
326 std::vector<std::unique_ptr<IReaderConverter>> m_readerConverters;
327 std::vector<std::unique_ptr<IReaderMultiOutputConverter>> m_readerMultiOutputConverters;
Result metadata returned after a conversion completes.
Definition conversion.h:109
void addDiagnostic(MessageSeverity severity, std::string message)
Adds a diagnostic and updates the error state if needed.
Definition conversion.h:130
bool hasError() const noexcept
Returns true when at least one diagnostic has severity Error.
Definition conversion.h:118
void addDiagnostic(Diagnostic diagnostic)
Adds a diagnostic and updates the error state if needed.
Definition conversion.h:136
std::span< const Diagnostic > diagnostics() const noexcept
Returns the diagnostics collected during conversion.
Definition conversion.h:112
Lightweight registry for locating converters by source and target format.
Definition conversion.h:241
void add(std::unique_ptr< IReaderMultiOutputConverter > converter)
Adds a reader-backed multi-output converter to the registry.
Definition conversion.h:271
const IReaderConverter * findReader(FormatId sourceFormat, FormatId targetFormat) const
Returns the first registered reader-backed converter matching the requested formats,...
Definition conversion.h:302
const IReaderMultiOutputConverter * findReaderMultiOutput(FormatId sourceFormat, FormatId targetFormat) const
Returns the first registered reader-backed multi-output converter matching the requested formats,...
Definition conversion.h:313
const IMultiOutputConverter * findMultiOutput(FormatId sourceFormat, FormatId targetFormat) const
Returns the first registered multi-output converter matching the requested formats,...
Definition conversion.h:291
const IConverter * find(FormatId sourceFormat, FormatId targetFormat) const
Returns the first registered converter matching the requested formats, or nullptr.
Definition conversion.h:280
void add(std::unique_ptr< IMultiOutputConverter > converter)
Adds a multi-output converter to the registry.
Definition conversion.h:253
void add(std::unique_ptr< IConverter > converter)
Adds a converter to the registry.
Definition conversion.h:244
void add(std::unique_ptr< IReaderConverter > converter)
Adds a reader-backed converter to the registry.
Definition conversion.h:262
Public interface implemented by each conversion adapter.
Definition conversion.h:166
virtual ~IConverter()=default
virtual destructor
virtual FormatId sourceFormat() const =0
Returns the source format accepted by this converter.
virtual FormatId targetFormat() const =0
Returns the target format produced by this converter.
virtual ConversionResult convert(std::span< const std::byte > input, std::ostream &output, const ConversionRequest &request={}) const =0
Converts the input memory buffer and writes the converted output to the provided stream.
Public interface implemented by adapters that may produce multiple output documents.
Definition conversion.h:205
virtual FormatId targetFormat() const =0
Returns the target format produced by this converter.
virtual ConversionResult convert(std::span< const std::byte > input, const MultiOutputCallback &outputCallback, const ConversionRequest &request={}) const =0
Converts the input memory buffer and invokes outputCallback once for each generated output.
virtual FormatId sourceFormat() const =0
Returns the source format accepted by this converter.
virtual ~IMultiOutputConverter()=default
virtual destructor
Base class for adapter-specific option structs.
Definition conversion.h:93
virtual ~IOptions()=default
Virtual destructor.
Random-access byte reader used for container formats such as MUSX.
Definition random_access_reader.h:32
Public interface implemented by adapters whose input is a random-access container.
Definition conversion.h:184
virtual ConversionResult convert(const IRandomAccessReader &input, std::ostream &output, const ConversionRequest &request={}) const =0
Converts the input reader and writes the converted output to the provided stream.
virtual ~IReaderConverter()=default
virtual destructor
virtual FormatId targetFormat() const =0
Returns the target format produced by this converter.
virtual FormatId sourceFormat() const =0
Returns the source format accepted by this converter.
Public interface implemented by reader-backed adapters that may produce multiple output documents.
Definition conversion.h:223
virtual ConversionResult convert(const IRandomAccessReader &input, const MultiOutputCallback &outputCallback, const ConversionRequest &request={}) const =0
Converts the input reader and invokes outputCallback once for each generated output.
virtual ~IReaderMultiOutputConverter()=default
virtual destructor
virtual FormatId sourceFormat() const =0
Returns the source format accepted by this converter.
virtual FormatId targetFormat() const =0
Returns the target format produced by this converter.
Core public API for the Denigma conversion libraries.
Definition articulations.h:32
FormatId
Stable identifiers for converter input and output formats.
Definition conversion.h:45
@ MssXml
MuseScore style sheet XML.
@ EnigmaXml
Finale Enigma XML.
@ Svg
Scalable Vector Graphics XML.
@ MnxJson
MNX JSON as produced by mnxdom.
@ Musx
Finale MUSX archive.
@ MusicXml
MusicXML score-partwise XML.
MessageSeverity
Severity for log messages and diagnostics emitted by converters.
Definition conversion.h:57
OptionsT optionsFromRequest(const ConversionRequest &request, std::string_view converterName)
Returns typed options from an erased request, or default options when none were supplied.
Definition conversion.h:151
std::function< void(std::string_view suggestedName, std::span< const std::byte > data)> MultiOutputCallback
Callback used by converters that may emit zero, one, or many output buffers.
Definition conversion.h:200
Options common to all public converter adapters.
Definition conversion.h:75
std::function< void(MessageSeverity severity, std::string_view message)> logCallback
Optional callback that receives converter log messages. Defaults to no-op.
Definition conversion.h:87
bool validate
Enables converter-specific output validation when supported.
Definition conversion.h:79
bool allFontsAvailable
Every source font will be available in the environment that reads the converted output.
Definition conversion.h:85
std::string sourceName
Caller-supplied source name used for diagnostics and metadata.
Definition conversion.h:77
bool verbose
Enables verbose logging when supported by the caller.
Definition conversion.h:81
bool quiet
Suppresses info/verbose logging when true.
Definition conversion.h:83
Type-erased request used by registry-based converter calls.
Definition conversion.h:101
const IOptions * options
Adapter-specific options. Must remain valid for the duration of the conversion call.
Definition conversion.h:103
A non-fatal message emitted by a converter.
Definition conversion.h:67
std::string message
Human-readable diagnostic text.
Definition conversion.h:69
MessageSeverity severity
Message severity.
Definition conversion.h:68