From c409cda11569e222fe83353c68718a4adfd9188b Mon Sep 17 00:00:00 2001 From: Adrien Matta <matta@lpccaen.in2p3.fr> Date: Thu, 6 Jun 2024 10:59:46 +0200 Subject: [PATCH] * Adding functionnality to aliases - now can support a list of vector --- NPLib/Core/NPInputParser.cxx | 21 ++++++++++++++++++++- NPLib/Core/NPInputParser.h | 3 ++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/NPLib/Core/NPInputParser.cxx b/NPLib/Core/NPInputParser.cxx index 87f6f348e..afe07e383 100644 --- a/NPLib/Core/NPInputParser.cxx +++ b/NPLib/Core/NPInputParser.cxx @@ -221,7 +221,23 @@ TVector3 NPL::InputBlock::GetTVector3(std::string Token, std::string default_uni return TVector3(x, y, z); } //////////////////////////////////////////////////////////////////////////////// -std::vector<std::string> NPL::InputBlock::GetVectorString(std::string Token) { +std::vector<std::string> NPL::InputBlock::GetVectorList(std::string Token, std::string separator) { + auto line = GetValue(Token); + std::vector<std::string> val; + while (line.find("(") != std::string::npos) { + auto start = line.find_first_of("("); + auto stop = line.find_first_of(")"); + auto b = line.begin(); + auto v = line.substr(start, stop - start + 1); + v.replace(v.find("("), 1, ""); + v.replace(v.find(")"), 1, ""); + val.push_back(v); + line.erase(b + start, b + stop + 1); + } + return val; +} +//////////////////////////////////////////////////////////////////////////////// +std::vector<std::string> NPL::InputBlock::GetVectorString(std::string Token, std::string separator) { int verbose = 1; // NPOptionManager::getInstance()->GetVerboseLevel(); std::stringstream iss(GetValue(Token)); @@ -397,6 +413,9 @@ void NPL::InputParser::TreatAliases() { name += alias[i]->GetMainValue(); std::string action = alias[i]->GetString("Action"); std::vector<std::string> value = alias[i]->GetVectorString("Value"); + if (value[0].find("(") != std::string::npos) + value = alias[i]->GetVectorList("Value"); + if (action == "Replace" && value.size() != 1) NPL::SendErrorAndExit("NPL::InputParser", "Inplace alias can only take one value"); diff --git a/NPLib/Core/NPInputParser.h b/NPLib/Core/NPInputParser.h index 788dd3ec7..c60c3a9cb 100644 --- a/NPLib/Core/NPInputParser.h +++ b/NPLib/Core/NPInputParser.h @@ -80,7 +80,8 @@ namespace NPL { TVector3 GetTVector3(std::string Token, std::string default_unit); std::vector<double> GetVectorDouble(std::string Token, std::string default_unit); std::vector<int> GetVectorInt(std::string Token); - std::vector<std::string> GetVectorString(std::string Token); + std::vector<std::string> GetVectorString(std::string Token, std::string separator = " "); + std::vector<std::string> GetVectorList(std::string Token, std::string separator = " "); std::vector<NPL::InputBlock*> GetSubBlock(std::string Token); std::vector<std::string> GetLines() { return m_Lines; }; -- GitLab