#include "struct_to_string.hpp" namespace smtp::converter { std::string StructToString::Convert( manage::SettingsFields const& from ) const { std::string result; ApplyPort( from, result ); ApplyHost( from, result ); ApplyPassword( from, result ); ApplyUsername( from, result ); ApplySsl( from, result ); ApplyAuth( from, result ); return result; } void StructToString::ApplyAuth( manage::SettingsFields const& from, std::string& result ) const { static const std::string FIELD = "is_need_auth"; result += GetBoolParam( FIELD, from.is_need_auth); } void StructToString::ApplySsl( manage::SettingsFields const& from, std::string& result ) const { static const std::string FIELD = "is_need_ssl"; result += GetBoolParam( FIELD, from.is_need_ssl); } void StructToString::ApplyUsername( manage::SettingsFields const& from, std::string& result ) const { static const std::string FIELD = "username"; result += GetStringParam( FIELD, from.username ); } void StructToString::ApplyPassword( manage::SettingsFields const& from, std::string& result ) const { static const std::string FIELD = "password"; result += GetStringParam( FIELD, from.password ); } void StructToString::ApplyHost( manage::SettingsFields const& from, std::string& result ) const { static const std::string FIELD = "host"; result += GetStringParam( FIELD, from.host ); } void StructToString::ApplyPort( manage::SettingsFields const& from, std::string& result ) const { static const std::string FIELD = "port"; result += GetStringParam( FIELD, from.port ); } std::string StructToString::GetStringParam(const std::string &field, const std::string ¶m) const { std::string result; result += field; result += '='; result += param; result += '&'; return result; } std::string StructToString::GetBoolParam(const std::string &field, bool param) const { std::string result; result += field; result += '='; result += param ? "true" : "false"; result += '&'; return result; } }