From 59e13a066eaaa867e6455b27fcae396c0ceacadc Mon Sep 17 00:00:00 2001 From: Jyrki Vesterinen Date: Mon, 25 Jul 2016 08:12:36 +0300 Subject: [PATCH] Implement tod_manager::resolve_random() without Boost.Range (#711) * Implement tod_manager::resolve_random() without Boost.Range or Boost.Bind * Fix crash on map load --- src/tod_manager.cpp | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/tod_manager.cpp b/src/tod_manager.cpp index 5c4157b296113..5d1d5c756d0ee 100644 --- a/src/tod_manager.cpp +++ b/src/tod_manager.cpp @@ -28,8 +28,8 @@ #include "resources.hpp" #include "config_assign.hpp" -#include -#include +#include +#include #include "utils/functional.hpp" static lg::log_domain log_engine("engine"); @@ -71,27 +71,34 @@ tod_manager& tod_manager::operator=(const tod_manager& manager) return *this; } -template -struct greater -{ - greater(T val) : value (val) {} - bool operator () (T v2) const - { - return value < v2; - } - - T value; -}; - void tod_manager::resolve_random(random_new::rng& r) { //process the random_start_time string, which can be boolean yes/no true/false or a //comma-separated string of integers >= 1 referring to the times_ array indices + std::vector output_strings = utils::split(random_tod_.str()); std::vector output; - boost::copy( utils::split(random_tod_.str()) - | boost::adaptors::transformed(boost::bind(lexical_cast_default, _1 , 0)) - | boost::adaptors::filtered(greater(0)) - , std::back_inserter(output) ); + + try + { + std::transform(output_strings.begin(), output_strings.end(), std::back_inserter(output), + [](const std::string& str) + { + return std::stoi(str); + }); + } + catch (std::invalid_argument) + { + // This happens if the random_start_time string is a boolean. + // Simply ignore the exception. + } + + // Remove non-positive times + output.erase( + std::remove_if( + output.begin(), + output.end(), + [](int time){ return time <= 0; }), + output.end()); if(!output.empty()) {