From 96b7fa7ce53a81619405be0246b2c2e5ba655af3 Mon Sep 17 00:00:00 2001 From: mlitre Date: Thu, 12 Sep 2024 21:04:38 +0200 Subject: [PATCH 1/2] refactor: Replace get_vector_from_csv with split_string Removed references to get_vector_from_csv by split_string since this last method is more extensible / reusable. Signed-off-by: mlitre --- lib/ocpp/v16/charge_point_configuration.cpp | 2 +- lib/ocpp/v16/charge_point_impl.cpp | 2 +- lib/ocpp/v201/charge_point.cpp | 6 +++--- lib/ocpp/v201/connectivity_manager.cpp | 4 ++-- lib/ocpp/v201/device_model.cpp | 6 +++--- lib/ocpp/v201/utils.cpp | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/ocpp/v16/charge_point_configuration.cpp b/lib/ocpp/v16/charge_point_configuration.cpp index 8975d42a9..63f2ead75 100644 --- a/lib/ocpp/v16/charge_point_configuration.cpp +++ b/lib/ocpp/v16/charge_point_configuration.cpp @@ -210,7 +210,7 @@ std::string to_csl(const std::vector& vec) { } void ChargePointConfiguration::init_supported_measurands() { - const auto _supported_measurands = ocpp::get_vector_from_csv(this->config["Internal"]["SupportedMeasurands"]); + const auto _supported_measurands = ocpp::split_string(this->config["Internal"]["SupportedMeasurands"], ','); for (const auto& measurand : _supported_measurands) { try { const auto _measurand = conversions::string_to_measurand(measurand); diff --git a/lib/ocpp/v16/charge_point_impl.cpp b/lib/ocpp/v16/charge_point_impl.cpp index 46a9e7f83..1413eca50 100644 --- a/lib/ocpp/v16/charge_point_impl.cpp +++ b/lib/ocpp/v16/charge_point_impl.cpp @@ -4165,7 +4165,7 @@ void ChargePointImpl::stop_transaction(int32_t connector, Reason reason, std::op std::vector ChargePointImpl::get_measurands_vec(const std::string& measurands_csv) { std::vector measurands; - std::vector measurands_strings = ocpp::get_vector_from_csv(measurands_csv); + std::vector measurands_strings = ocpp::split_string(measurands_csv, ','); for (const auto& measurand_string : measurands_strings) { try { diff --git a/lib/ocpp/v201/charge_point.cpp b/lib/ocpp/v201/charge_point.cpp index ef7972fe5..2c7f86d44 100644 --- a/lib/ocpp/v201/charge_point.cpp +++ b/lib/ocpp/v201/charge_point.cpp @@ -1078,8 +1078,8 @@ void ChargePoint::remove_network_connection_profiles_below_actual_security_profi VARIABLE_ATTRIBUTE_VALUE_SOURCE_INTERNAL); // Update the NetworkConfigurationPriority so only remaining profiles are in there - const auto network_priority = ocpp::get_vector_from_csv( - this->device_model->get_value(ControllerComponentVariables::NetworkConfigurationPriority)); + const auto network_priority = ocpp::split_string( + this->device_model->get_value(ControllerComponentVariables::NetworkConfigurationPriority), ','); auto in_network_profiles = [&network_connection_profiles](const std::string& item) { auto is_same_slot = [&item](const SetNetworkProfileRequest& profile) { @@ -1679,7 +1679,7 @@ void ChargePoint::handle_variables_changed(const std::mapdevice_model->get_value(ControllerComponentVariables::SecurityProfile); for (const auto configuration_slot : network_configuration_priorities) { diff --git a/lib/ocpp/v201/connectivity_manager.cpp b/lib/ocpp/v201/connectivity_manager.cpp index 3d9bfdede..d87ba3fa1 100644 --- a/lib/ocpp/v201/connectivity_manager.cpp +++ b/lib/ocpp/v201/connectivity_manager.cpp @@ -267,8 +267,8 @@ void ConnectivityManager::cache_network_connection_profiles() { this->network_connection_profiles = json::parse(this->device_model.get_value(ControllerComponentVariables::NetworkConnectionProfiles)); - this->network_connection_priorities = ocpp::get_vector_from_csv( - this->device_model.get_value(ControllerComponentVariables::NetworkConfigurationPriority)); + this->network_connection_priorities = ocpp::split_string( + this->device_model.get_value(ControllerComponentVariables::NetworkConfigurationPriority), ','); if (this->network_connection_priorities.empty()) { EVLOG_AND_THROW(std::runtime_error("NetworkConfigurationPriority must not be empty")); diff --git a/lib/ocpp/v201/device_model.cpp b/lib/ocpp/v201/device_model.cpp index fe56abac2..c9edde94c 100644 --- a/lib/ocpp/v201/device_model.cpp +++ b/lib/ocpp/v201/device_model.cpp @@ -175,7 +175,7 @@ bool validate_value(const VariableCharacteristics& characteristics, const std::s if (!characteristics.valuesList.has_value()) { return true; } - const auto values_list = ocpp::get_vector_from_csv(characteristics.valuesList.value().get()); + const auto values_list = ocpp::split_string(characteristics.valuesList.value().get(), ','); return std::find(values_list.begin(), values_list.end(), value) != values_list.end(); } default: // same validation for MemberList or SequenceList @@ -186,8 +186,8 @@ bool validate_value(const VariableCharacteristics& characteristics, const std::s if (!characteristics.valuesList.has_value()) { return true; } - const auto values_list = ocpp::get_vector_from_csv(characteristics.valuesList.value().get()); - const auto value_csv = get_vector_from_csv(value); + const auto values_list = ocpp::split_string(characteristics.valuesList.value().get(), ','); + const auto value_csv = ocpp::split_string(value, ','); for (const auto& v : value_csv) { if (std::find(values_list.begin(), values_list.end(), v) == values_list.end()) { return false; diff --git a/lib/ocpp/v201/utils.cpp b/lib/ocpp/v201/utils.cpp index da2ae3809..5d8256c2c 100644 --- a/lib/ocpp/v201/utils.cpp +++ b/lib/ocpp/v201/utils.cpp @@ -16,7 +16,7 @@ namespace utils { std::vector get_measurands_vec(const std::string& measurands_csv) { std::vector measurands; - std::vector measurands_strings = ocpp::get_vector_from_csv(measurands_csv); + std::vector measurands_strings = ocpp::split_string(measurands_csv, ','); for (const auto& measurand_string : measurands_strings) { try { From 14ba5db21b5bbef902c2a0c19567d57762341d51 Mon Sep 17 00:00:00 2001 From: mlitre Date: Mon, 16 Sep 2024 19:06:39 +0200 Subject: [PATCH 2/2] refactor!: Remove get_vector_from_csv Method completely removed since we can just use the split_string method instead. Signed-off-by: mlitre --- include/ocpp/common/utils.hpp | 2 -- lib/ocpp/common/utils.cpp | 10 ---------- 2 files changed, 12 deletions(-) diff --git a/include/ocpp/common/utils.hpp b/include/ocpp/common/utils.hpp index c29b4bdf4..cbeed531b 100644 --- a/include/ocpp/common/utils.hpp +++ b/include/ocpp/common/utils.hpp @@ -12,8 +12,6 @@ namespace ocpp { /// \brief Case insensitive compare for a case insensitive (Ci)String bool iequals(const std::string& lhs, const std::string rhs); -std::vector get_vector_from_csv(const std::string& csv_str); - bool is_integer(const std::string& value); std::tuple is_positive_integer(const std::string& value); bool is_decimal_number(const std::string& value); diff --git a/lib/ocpp/common/utils.cpp b/lib/ocpp/common/utils.cpp index 270cc3252..3f204cf24 100644 --- a/lib/ocpp/common/utils.cpp +++ b/lib/ocpp/common/utils.cpp @@ -14,16 +14,6 @@ bool iequals(const std::string& lhs, const std::string rhs) { return boost::algorithm::iequals(lhs, rhs); } -std::vector get_vector_from_csv(const std::string& csv_str) { - std::vector csv; - std::string str; - std::stringstream ss(csv_str); - while (std::getline(ss, str, ',')) { - csv.push_back(str); - } - return csv; -} - bool is_integer(const std::string& value) { if (value.empty()) { return false;