vstdio / ood

Репозиторий для лабораторных работ по дисциплине "Объектно-ориентированное проектирование"
MIT License
0 stars 0 forks source link

Замечания по паттерну "Декоратор" - потоки #4

Open alexey-malov opened 6 years ago

alexey-malov commented 6 years ago
    if (argc < 3)
    {
        std::cerr << "Invalid arguments count..." << std::endl;
        std::cerr << "Usage: Streams.exe [options] <input file> <output file>" << std::endl;
        return 1;
    }
alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
CompressOutputStreamDecorator::~CompressOutputStreamDecorator()
{
    Flush();
}
alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
        for (uint8_t i = 0; i < chunk->count; ++i)
        {
            m_decompressedBuffer.push_back(chunk->byte);
            ++unpacked;
        }
alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
using InputStreamDecorator = function<unique_ptr<IInputStream>(unique_ptr<IInputStream>&& s);
using OutputStreamDecorator = function<unique_ptr<IOutputStream>(unique_ptr<IOutputStream>&& s);
vector<InputStreamDecorator> inputDecorators;
vector<OutputStreamDecorator> outputDecorators;

inputDecorators.emplace_back([](auto&& s){
    return make_unique<Decompress>(move(s));
});
inputDecorator.emplace_back([key](auto&& s){
    return make_unique<Decrypt>(move(s));
});

for (auto&& d : inputDecorators)
{
    s = d(move(s));
}

либо

InputStreamDecorator  applyDecompressor;
for (auto&& option : options)
{
    if (option == "--decompress") 
        applyDecompressor = [](auto&& s){
            return make_unique<Decompress>(move(s));
        };
    ...
}

if (applyDecompressor)
{
    s = applyDecompressor(move(s));
}
if (applyDecryptor)
{
    s = applyDecryptor(move(s));
}