Exemplo n.º 1
0
std::unique_ptr<const BaseContainer> AdapterChain::doConverterExtract(const BaseContainer &from_data) const
{
    if (converters_.empty()
        && archiver_->getContainerType() != writer_->getContainerType()
       )
    {
        throw MethodNotApplicableException("converters are needed but are not specified");
    }

    // first step is different
    bool first = true;
    unique_ptr<const BaseContainer> data;
    for (const auto& converter : converters_)
    {
        if (first)
        {
            if (converter->getArchiveContainerType() != from_data.getType())	error("Adapters are incompatible");
            data = std::move(converter->extract(from_data));

            first = false;
        }
        else
        {
            if (converter->getArchiveContainerType() != data->getType())	error("Adapters are incompatible");
            data = std::move(converter->extract(*data));
        }
    }

    return data;
}
Exemplo n.º 2
0
void AdapterChain::doWriterExtract(const BaseContainer &from_data, string to_file) const
{
    if (!writer_)	throw MethodNotApplicableException("a writer is needed but is not specified");

    if (writer_->getContainerType() != from_data.getType())	error("Adapters are incompatible");
    const OutputFileInfo outinfo = {to_file, file_extension_};
    writer_->write(from_data, outinfo);
}