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.cpp | 94 ------------------------------------------------------- 1 file changed, 94 deletions(-) delete mode 100644 src/file/mail.cpp (limited to 'src/file/mail.cpp') diff --git a/src/file/mail.cpp b/src/file/mail.cpp deleted file mode 100644 index a7e30ea..0000000 --- a/src/file/mail.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include - -#include "mail.hpp" -#include "logger/logger_set.hpp" - -namespace smtp::file -{ - - // - //Constructors - // - - Mail::Mail( std::string const& path_file, checker::RegistratorMails const& registrator_errors ) - : mPathFile( path_file ) - , mRegistratorErrors( registrator_errors ) - { - } - - // - //Public methods - // - - manage::MailsSet Mail::Read() const - { - static const std::string METHOD_NAME = "Read mails"; - - std::ifstream mail_file{ mPathFile, std::fstream::in }; - if ( !mail_file.is_open() ) - { - logger::LoggerSet::GetInstance()->LogError( METHOD_NAME, "Unable to open file to read " + mPathFile ); - return {}; - } - - auto result = ReadFile( mail_file ); - - mail_file.close(); - return result; - } - - bool Mail::Write( manage::MailsSet const& data ) const - { - static const std::string METHOD_NAME = "Write mails"; - - std::ofstream mail_file{ mPathFile, std::fstream::out | std::fstream::trunc }; - - - if ( !mail_file.is_open() ) - { - logger::LoggerSet::GetInstance()->LogError( METHOD_NAME, "Unable to open file to write " + mPathFile ); - return false; - } - - auto result = WriteFile( mail_file, data ); - - mail_file.close(); - return result; - } - - // - //Private methods - // - - manage::MailsSet Mail::ReadFile( std::ifstream& mail_file ) const - { - std::string line{}; - manage::MailsSet result; - - while ( std::getline( mail_file, line ) ) - { - if( mRegistratorErrors.Check( line ) ) - { - result.push_back( line ); - } - } - return result; - } - - bool Mail::WriteFile( std::ofstream& mail_file, manage::MailsSet const& data ) const - { - bool result = true; - for( const auto& mail : data ) - { - if( mRegistratorErrors.Check( mail ) ) - { - mail_file << mail << "\n"; - } - else - { - result = false; - } - } - return result; - } -} -- cgit v1.2.3