From d0a9c7a4424be599020f93ae1097f5ffeba2efd4 Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Fri, 25 Jun 2021 12:55:28 +0200 Subject: [PATCH] [GL/Station] Refactor createStation(). --- GeoLib/Station.cpp | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/GeoLib/Station.cpp b/GeoLib/Station.cpp index 8d2ed2dbabe..3532ee91c9b 100644 --- a/GeoLib/Station.cpp +++ b/GeoLib/Station.cpp @@ -46,30 +46,27 @@ Station::~Station() Station* Station::createStation(const std::string& line) { - Station* station = new Station(); std::list<std::string> fields = BaseLib::splitString(line, '\t'); - if (fields.size() >= 3) - { - auto it = fields.begin(); - station->_name = *it; - (*station)[0] = std::strtod( - (BaseLib::replaceString(",", ".", *(++it))).c_str(), nullptr); - (*station)[1] = std::strtod( - (BaseLib::replaceString(",", ".", *(++it))).c_str(), nullptr); - if (++it != fields.end()) - { - (*station)[2] = std::strtod( - (BaseLib::replaceString(",", ".", *it)).c_str(), nullptr); - } - } - else + if (fields.size() < 3) { INFO("Station::createStation() - Unexpected file format."); - delete station; return nullptr; } - return station; + + auto it = fields.begin(); + std::string name = *it; + auto const x = std::strtod( + (BaseLib::replaceString(",", ".", *(++it))).c_str(), nullptr); + auto const y = std::strtod( + (BaseLib::replaceString(",", ".", *(++it))).c_str(), nullptr); + auto z = 0.0; + if (++it != fields.end()) + { + z = std::strtod((BaseLib::replaceString(",", ".", *it)).c_str(), + nullptr); + } + return new Station(x, y, z, name); } Station* Station::createStation(const std::string& name, double x, double y, -- GitLab