diff options
Diffstat (limited to 'src/converter/struct_to_string.cpp')
-rw-r--r-- | src/converter/struct_to_string.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/converter/struct_to_string.cpp b/src/converter/struct_to_string.cpp new file mode 100644 index 0000000..c86a6c8 --- /dev/null +++ b/src/converter/struct_to_string.cpp @@ -0,0 +1,82 @@ +#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; + } +} |