Salome HOME
Copyright update 2021
[tools/libbatch.git] / src / Core / Test / SimpleParser.cxx
index 162fd19fedb85b299a35e98183ad3b5a6a0842e2..c01849da375328287fe7afb9f04ccb84334117a6 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 /*
  *  SimpleParser.cpp
 using namespace std;
 
 
-ParserException::ParserException(string msg) throw()
+ParserException::ParserException(string msg) noexcept
   : exception(),
     _msg(msg)
 {
 }
 
-ParserException::~ParserException() throw()
+ParserException::~ParserException() noexcept
 {
 }
 
-const char * ParserException::what() const throw()
+const char * ParserException::what() const noexcept
 {
   return _msg.c_str();
 }
 
 
-SimpleParser::SimpleParser() throw()
+SimpleParser::SimpleParser() noexcept
 {
 }
 
-SimpleParser::~SimpleParser() throw()
+SimpleParser::~SimpleParser() noexcept
 {
 }
 
-std::string SimpleParser::trim(const std::string & str) const throw()
+std::string SimpleParser::trim(const std::string & str) const noexcept
 {
   size_t beg = str.find_first_not_of(" \t");
   if (beg == string::npos) beg = 0;
@@ -70,7 +70,7 @@ std::string SimpleParser::trim(const std::string & str) const throw()
   return str.substr(beg, end-beg+1);
 }
 
-void SimpleParser::parse(const string & filename) throw(ParserException)
+void SimpleParser::parse(const string & filename)
 {
   ifstream fileStream(filename.c_str());
   if (!fileStream) {
@@ -109,7 +109,7 @@ void SimpleParser::parse(const string & filename) throw(ParserException)
   fileStream.close();
 }
 
-void SimpleParser::parseTestConfigFile() throw(ParserException)
+void SimpleParser::parseTestConfigFile()
 {
   char * filename = getenv(TEST_CONFIG_FILE_ENV_VAR);
   if (filename == NULL) {
@@ -119,7 +119,7 @@ void SimpleParser::parseTestConfigFile() throw(ParserException)
   }
 }
 
-const string & SimpleParser::getValue(const string & key) const throw(ParserException)
+const string & SimpleParser::getValue(const string & key) const
 {
   map<string,string>::const_iterator iter = _configmap.find(key);
   if (iter == _configmap.end()) {
@@ -128,7 +128,22 @@ const string & SimpleParser::getValue(const string & key) const throw(ParserExce
   return iter->second;
 }
 
-int SimpleParser::getValueAsInt(const string & key) const throw(ParserException)
+const string & SimpleParser::getTestValue(const string & bmType, const string & protocolStr,
+                                          const string & key) const
+{
+  string fullkey = string("TEST_") + bmType + "_" + protocolStr + "_" + key;
+  try {
+    return getValue(fullkey);
+  } catch (const ParserException &) {}
+  fullkey = string("TEST_") + bmType + "_" + key;
+  try {
+    return getValue(fullkey);
+  } catch (const ParserException &) {}
+  fullkey = string("TEST_") + key;
+  return getValue(fullkey);
+}
+
+int SimpleParser::getValueAsInt(const string & key) const
 {
   const string & valueStr = getValue(key);
   const char * valueCStr = valueStr.c_str();
@@ -140,7 +155,22 @@ int SimpleParser::getValueAsInt(const string & key) const throw(ParserException)
   return res;
 }
 
-ostream & operator <<(ostream & os, const SimpleParser & parser) throw()
+int SimpleParser::getTestValueAsInt(const string & bmType, const string & protocolStr,
+                                    const string & key) const
+{
+  string fullkey = string("TEST_") + bmType + "_" + protocolStr + "_" + key;
+  try {
+    return getValueAsInt(fullkey);
+  } catch (const ParserException &) {}
+  fullkey = string("TEST_") + bmType + "_" + key;
+  try {
+    return getValueAsInt(fullkey);
+  } catch (const ParserException &) {}
+  fullkey = string("TEST_") + key;
+  return getValueAsInt(fullkey);
+}
+
+ostream & operator <<(ostream & os, const SimpleParser & parser) noexcept
 {
   if (parser._configmap.empty()) {
     os << "Empty map" << endl;