#include "file_to_struct.hpp" namespace smtp::converter { general::SettingsFields FileToStruct::Convert( general::SettingsFileDataType const& from ) const { general::SettingsFields result; ApplyAuth( result, from ); ApplySsl( result, from ); ApplyUsername( result, from ); ApplyPassword( result, from ); ApplyHost( result, from ); ApplyPort( result, from ); return result; } void FileToStruct::ApplyAuth( general::SettingsFields &result, general::SettingsFileDataType const& from ) const { static const std::string FIELD = "is_need_auth"; ApplyBool(from, FIELD, result.is_need_auth); } void FileToStruct::ApplySsl( general::SettingsFields &result, general::SettingsFileDataType const& from ) const { static const std::string FIELD = "is_need_ssl"; ApplyBool(from, FIELD, result.is_need_ssl); } void FileToStruct::ApplyBool( general::SettingsFileDataType const& from, std::string const& search_field, bool& field ) const { static const std::string TRUE_AS_STRING = "true"; static const std::string FALSE_AS_STRING = "false"; auto find = from.find( search_field ); if( find == from.end() ) { return; } if( find->second != TRUE_AS_STRING && find->second != FALSE_AS_STRING ) { return; } field = (find->second == TRUE_AS_STRING); } void FileToStruct::ApplyUsername( general::SettingsFields &result, general::SettingsFileDataType const& from ) const { static const std::string FIELD = "username"; ApplyString( from, FIELD, result.username ); } void FileToStruct::ApplyPassword( general::SettingsFields &result, general::SettingsFileDataType const& from ) const { static const std::string FIELD = "password"; ApplyString( from, FIELD, result.password ); } void FileToStruct::ApplyHost( general::SettingsFields &result, general::SettingsFileDataType const& from ) const { static const std::string FIELD = "host"; ApplyString( from, FIELD, result.host ); } void FileToStruct::ApplyPort( general::SettingsFields &result, general::SettingsFileDataType const& from ) const { static const std::string FIELD = "port"; ApplyString(from, FIELD, result.port); } void FileToStruct::ApplyString( general::SettingsFileDataType const& from, std::string const& search_field, std::string& field ) const { auto find = from.find( search_field ); if( find == from.end() ) { return; } field = find->second; } }