diff --git a/src/ComputingTasks.cc b/src/ComputingTasks.cc index a4b8fe17c19775c232d39ad3400be7df26cd50e4..c71dce24ea83ff935ae0ee97dea224ecb71cfe37 100644 --- a/src/ComputingTasks.cc +++ b/src/ComputingTasks.cc @@ -28,7 +28,6 @@ using namespace std; #include <boost/algorithm/string/trim.hpp> #include <boost/algorithm/string/split.hpp> -#include <boost/lexical_cast.hpp> #include <boost/tokenizer.hpp> #include <utility> @@ -3106,7 +3105,7 @@ MarkovSwitchingStatement::MarkovSwitchingStatement(OptionsList options_list_arg) auto it_num_regimes = options_list.num_options.find("ms.number_of_regimes"); assert(it_num_regimes != options_list.num_options.end()); - auto num_regimes = lexical_cast< int >(it_num_regimes->second); + auto num_regimes = stoi(it_num_regimes->second); vector<string> tokenizedRestrictions; split(tokenizedRestrictions, it_num->second, is_any_of("["), token_compress_on); @@ -3131,8 +3130,8 @@ MarkovSwitchingStatement::MarkovSwitchingStatement(OptionsList options_list_arg) try { - auto from_regime = lexical_cast< int >(restriction[0]); - auto to_regime = lexical_cast< int >(restriction[1]); + auto from_regime = stoi(restriction[0]); + auto to_regime = stoi(restriction[1]); if (from_regime > num_regimes || to_regime > num_regimes) { cerr << "ERROR: the regimes specified in the restrictions option must be " @@ -3148,7 +3147,7 @@ MarkovSwitchingStatement::MarkovSwitchingStatement(OptionsList options_list_arg) exit(EXIT_FAILURE); } - auto transition_probability = lexical_cast< double >(restriction[2]); + auto transition_probability = stod(restriction[2]); if (transition_probability > 1.0) { cerr << "ERROR: the transition probability, " << transition_probability @@ -3157,7 +3156,7 @@ MarkovSwitchingStatement::MarkovSwitchingStatement(OptionsList options_list_arg) } restriction_map[{ from_regime, to_regime }] = transition_probability; } - catch (const bad_lexical_cast &) + catch (const invalid_argument &) { cerr << "ERROR: The first two arguments for a restriction must be integers " << "specifying the regime and the last must be a double specifying the " @@ -3188,7 +3187,7 @@ MarkovSwitchingStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo auto it_num_regimes = options_list.num_options.find("ms.number_of_regimes"); assert(it_num_regimes != options_list.num_options.end()); - auto num_regimes = lexical_cast< int >(it_num_regimes->second); + auto num_regimes = stoi(it_num_regimes->second); vector<double> col_trans_prob_sum(num_regimes, 0); vector<double> row_trans_prob_sum(num_regimes, 0); vector<bool> all_restrictions_in_row(num_regimes, true); diff --git a/src/ConfigFile.cc b/src/ConfigFile.cc index 555444709982d34ffca9505acbe14d038dcdedd6..43876dc50742bfd02b936c29f407c3d51c55f70c 100644 --- a/src/ConfigFile.cc +++ b/src/ConfigFile.cc @@ -25,7 +25,6 @@ #include "ConfigFile.hh" #include <boost/algorithm/string/trim.hpp> #include <boost/algorithm/string/split.hpp> -#include <boost/lexical_cast.hpp> #include <boost/tokenizer.hpp> using namespace std; @@ -297,7 +296,7 @@ ConfigFile::getConfigFileInfo(const string &config_file) if (tokenizedCpuNbr.size() == 1) { minCpuNbr = 1; - maxCpuNbr = lexical_cast< int >(tokenizedCpuNbr.front()); + maxCpuNbr = stoi(tokenizedCpuNbr.front()); } else if (tokenizedCpuNbr.size() == 2 && tokenizedCpuNbr[0].at(0) == '[' @@ -305,11 +304,11 @@ ConfigFile::getConfigFileInfo(const string &config_file) { tokenizedCpuNbr[0].erase(0, 1); tokenizedCpuNbr[1].erase(tokenizedCpuNbr[1].size()-1, 1); - minCpuNbr = lexical_cast< int >(tokenizedCpuNbr[0]); - maxCpuNbr = lexical_cast< int >(tokenizedCpuNbr[1]); + minCpuNbr = stoi(tokenizedCpuNbr[0]); + maxCpuNbr = stoi(tokenizedCpuNbr[1]); } } - catch (const bad_lexical_cast &) + catch (const invalid_argument &) { cerr << "ERROR: Could not convert value to integer for CPUnbr." << endl; exit(EXIT_FAILURE); @@ -400,7 +399,7 @@ ConfigFile::getConfigFileInfo(const string &config_file) else try { - auto weight = lexical_cast<double>(token.c_str()); + auto weight = stod(token); if (weight <= 0) { cerr << "ERROR (in config file): Misspecification of weights passed to Members option." << endl; @@ -408,7 +407,7 @@ ConfigFile::getConfigFileInfo(const string &config_file) } member_nodes[node_name] = weight; } - catch (bad_lexical_cast &) + catch (const invalid_argument &) { cerr << "ERROR (in config file): Misspecification of weights passed to Members option." << endl; exit(EXIT_FAILURE); @@ -558,9 +557,9 @@ ConfigFile::checkPass(WarningConsolidation &warnings) const if (!slave_node.second->port.empty()) try { - boost::lexical_cast< int >(slave_node.second->port); + stoi(slave_node.second->port); } - catch (const boost::bad_lexical_cast &) + catch (const invalid_argument &) { cerr << "ERROR (node " << slave_node.first << "): the port must be an integer." << endl; exit(EXIT_FAILURE); diff --git a/src/macro/MacroDriver.cc b/src/macro/MacroDriver.cc index 50899cc77be8fe2f450159c8c5ecfaac325659c9..cbdb2533ca32ee5c5a1fd340025dddaddb29e7e7 100644 --- a/src/macro/MacroDriver.cc +++ b/src/macro/MacroDriver.cc @@ -21,7 +21,6 @@ #include <iostream> #include <fstream> #include <sstream> -#include <boost/lexical_cast.hpp> #include "MacroDriver.hh" @@ -52,10 +51,10 @@ MacroDriver::parse(const string &f, const string &fb, const string &modfiletxt, for (auto & define : defines) try { - boost::lexical_cast<int>(define.second); + stoi(define.second); file_with_endl << "@#define " << define.first << " = " << define.second << endl; } - catch (boost::bad_lexical_cast &) + catch (const invalid_argument &) { if (!define.second.empty() && define.second.at(0) == '[' && define.second.at(define.second.length()-1) == ']') // If the input is an array. Issue #1578 diff --git a/src/macro/MacroValue.cc b/src/macro/MacroValue.cc index f31b94546e1595777b1e216ca6141a4b62971c07..8e5f316094a91407ddf700bbc27975f642473873 100644 --- a/src/macro/MacroValue.cc +++ b/src/macro/MacroValue.cc @@ -444,3 +444,40 @@ StringMV::in(const MacroValue *array) const noexcept(false) return new IntMV(driver, result); } + +template<> +string +ArrayMV<int>::print() const +{ + ostringstream ss; + ss << "["; + for (auto it = values.begin(); + it != values.end(); it++) + { + if (it != values.begin()) + ss << ", "; + + ss << *it; + } + ss << "]"; + return ss.str(); +} + +template<> +string +ArrayMV<string>::print() const +{ + ostringstream ss; + ss << "{"; + for (auto it = values.begin(); + it != values.end(); it++) + { + if (it != values.begin()) + ss << ", "; + + ss << "'" << *it << "'"; + } + ss << "}"; + return ss.str(); +} + diff --git a/src/macro/MacroValue.hh b/src/macro/MacroValue.hh index 593eafedcd240e4d6052e9e4296bc39868b537a8..6c997d31d7efba7bcf613e71adeefb5c6410de0a 100644 --- a/src/macro/MacroValue.hh +++ b/src/macro/MacroValue.hh @@ -24,7 +24,6 @@ #include <utility> #include <vector> #include <sstream> -#include <boost/lexical_cast.hpp> using namespace std; @@ -340,43 +339,6 @@ ArrayMV<T>::toString() const return ss.str(); } -template<typename T> -string -ArrayMV<T>::print() const -{ - bool printStrArr = false; - try - { - auto it = values.begin(); - boost::lexical_cast<int>(*it); - } - catch (boost::bad_lexical_cast &) - { - printStrArr= true; - } - ostringstream ss; - if (printStrArr) - ss << "{"; - else - ss << "["; - for (auto it = values.begin(); - it != values.end(); it++) - { - if (it != values.begin()) - ss << ", "; - - if (printStrArr) - ss << "'" << *it << "'"; - else - ss << *it; - } - if (printStrArr) - ss << "}"; - else - ss << "]"; - return ss.str(); -} - template<typename T> const MacroValue * ArrayMV<T>::toArray() const