From 43e721305c866ad4b2c4c35d1133f169e41dd49b Mon Sep 17 00:00:00 2001 From: claiff Date: Wed, 5 Oct 2022 15:57:43 +0300 Subject: file reader/writer split by decorators --- src/file/mail/checker_decorator.cpp | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/file/mail/checker_decorator.cpp (limited to 'src/file/mail/checker_decorator.cpp') diff --git a/src/file/mail/checker_decorator.cpp b/src/file/mail/checker_decorator.cpp new file mode 100644 index 0000000..54da9da --- /dev/null +++ b/src/file/mail/checker_decorator.cpp @@ -0,0 +1,58 @@ +#include "checker_decorator.hpp" +#include "logger/logger_set.hpp" + +namespace smtp::file::mail +{ + + // + //Constructors + // + + CheckerDecorator::CheckerDecorator( checker::RegistratorMails const& registrator_errors ) + : mRegistratorErrors( registrator_errors ) + { + } + + // + //Public methods + // + + manage::MailsSet CheckerDecorator::Read() const + { + manage::MailsSet result; + + if( !mBase ) + { + return result; + } + + auto parsed_data = mBase->Read(); + + for( auto const& line : parsed_data ) + { + if( mRegistratorErrors.Check( line ) ) + { + result.push_back( line ); + } + } + return result; + } + + bool CheckerDecorator::Write( manage::MailsSet const& data ) const + { + manage::MailsSet result; + + for( const auto& line : data ) + { + if( mRegistratorErrors.Check( line ) ) + { + result.push_back( line ); + } + } + if( mBase ) + { + return mBase->Write(result); + } + return false; + } +} -- cgit v1.2.3