From f4c9d41f0a7c3455d44372ac879365dbcc076c1e Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Mon, 18 May 2015 17:20:27 +0000 Subject: [PATCH] allow lists in DefineConstant + on command line with -setlistofnumbers + propagate info to onelab clients --- Common/CommandLine.cpp | 19 ++++++++++++++++++- Common/GmshMessage.cpp | 2 +- Common/GmshMessage.h | 4 ++-- Common/OpenFile.cpp | 6 +++--- Common/onelabUtils.cpp | 14 +++++++++++--- 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/Common/CommandLine.cpp b/Common/CommandLine.cpp index 3768e66615..7f2ccf5eb6 100644 --- a/Common/CommandLine.cpp +++ b/Common/CommandLine.cpp @@ -553,12 +553,29 @@ void GetOptions(int argc, char *argv[]) i++; if (i + 1 < argc && argv[i][0] != '-') { gmsh_yysymbols[argv[i]].value = std::vector<double>(1, atof(argv[i + 1])); - Msg::GetCommandLineNumbers()[argv[i]] = atof(argv[i + 1]); + Msg::GetCommandLineNumbers()[argv[i]] = std::vector<double>(1, atof(argv[i + 1])); i += 2; } else Msg::Error("Missing name and/or value for number definition"); } + else if (!strcmp(argv[i]+1, "setlist") || + !strcmp(argv[i]+1, "setlistofnumbers")) { + i++; + if (i + 1 < argc && argv[i][0] != '-') { + std::string n(argv[i]); + std::vector<double> v(1, atof(argv[i + 1])); + i += 2; + while(i < argc && argv[i][0] != '-'){ + v.push_back(atof(argv[i])); + i++; + } + gmsh_yysymbols[n].value = v; + Msg::GetCommandLineNumbers()[n] = v; + } + else + Msg::Error("Missing name and/or value for definition of list of numbers"); + } #endif else if(!strcmp(argv[i] + 1, "option")) { i++; diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp index 2c8c2fef3a..9cd7190adc 100644 --- a/Common/GmshMessage.cpp +++ b/Common/GmshMessage.cpp @@ -64,7 +64,7 @@ std::string Msg::_firstError; GmshMessage *Msg::_callback = 0; std::string Msg::_commandLine; std::string Msg::_launchDate; -std::map<std::string, double> Msg::_commandLineNumbers; +std::map<std::string, std::vector<double> > Msg::_commandLineNumbers; std::map<std::string, std::string> Msg::_commandLineStrings; #if !defined(HAVE_ONELAB2) GmshClient *Msg::_client = 0; diff --git a/Common/GmshMessage.h b/Common/GmshMessage.h index 802b8afaca..b80018b8db 100644 --- a/Common/GmshMessage.h +++ b/Common/GmshMessage.h @@ -48,7 +48,7 @@ class Msg { // command-line and startup time static std::string _commandLine, _launchDate; // command-line-specified numbers and strings - static std::map<std::string, double> _commandLineNumbers; + static std::map<std::string, std::vector<double> > _commandLineNumbers; static std::map<std::string, std::string> _commandLineStrings; #if !defined(HAVE_ONELAB2) // communication with Gmsh when run remotely @@ -83,7 +83,7 @@ class Msg { static int GetVerbosity(){ return _verbosity; } static std::string GetLaunchDate(){ return _launchDate; } static std::string GetCommandLineArgs(){ return _commandLine; } - static std::map<std::string, double> &GetCommandLineNumbers() + static std::map<std::string, std::vector<double> > &GetCommandLineNumbers() { return _commandLineNumbers; } diff --git a/Common/OpenFile.cpp b/Common/OpenFile.cpp index a1fc73ac99..8e7b16e5e3 100644 --- a/Common/OpenFile.cpp +++ b/Common/OpenFile.cpp @@ -674,9 +674,9 @@ void OpenProject(const std::string &fileName, bool setWindowTitle) #if defined(HAVE_PARSER) gmsh_yysymbols.clear(); gmsh_yystringsymbols.clear(); - std::map<std::string, double> cln(Msg::GetCommandLineNumbers()); - for(std::map<std::string, double>::iterator it = cln.begin(); it != cln.end(); it++) - gmsh_yysymbols[it->first].value = std::vector<double>(1, it->second); + std::map<std::string, std::vector<double> > cln(Msg::GetCommandLineNumbers()); + for(std::map<std::string, std::vector<double> >::iterator it = cln.begin(); it != cln.end(); it++) + gmsh_yysymbols[it->first].value = it->second; std::map<std::string, std::string> cls(Msg::GetCommandLineStrings()); for(std::map<std::string, std::string>::iterator it = cls.begin(); it != cls.end(); it++) gmsh_yystringsymbols[it->first] = it->second; diff --git a/Common/onelabUtils.cpp b/Common/onelabUtils.cpp index 4ece1c08b1..eb91af2208 100644 --- a/Common/onelabUtils.cpp +++ b/Common/onelabUtils.cpp @@ -128,9 +128,17 @@ namespace onelabUtils { // good idea?) std::ostringstream sstream; sstream.precision(16); - std::map<std::string, double> cln(Msg::GetCommandLineNumbers()); - for(std::map<std::string, double>::iterator it = cln.begin(); it != cln.end(); it++) - sstream << " -setnumber " << it->first << " " << it->second; + std::map<std::string, std::vector<double> > cln(Msg::GetCommandLineNumbers()); + for(std::map<std::string, std::vector<double> >::iterator it = cln.begin(); it != cln.end(); it++){ + if(it->second.size() == 1){ + sstream << " -setnumber " << it->first << " " << it->second[0]; + } + else{ + sstream << " -setlistofnumbers " << it->first; + for(unsigned int i = 0; i < it->second.size(); i++) + sstream << " " << it->second[i]; + } + } std::map<std::string, std::string> cls(Msg::GetCommandLineStrings()); for(std::map<std::string, std::string>::iterator it = cls.begin(); it != cls.end(); it++) sstream << " -setstring " << it->first << " " << it->second; -- GitLab