Warning, /include/Geant4/tools/sto is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_sto
0005 #define tools_sto
0006
0007 #include <string>
0008
0009 namespace tools {
0010
0011 inline bool to(const std::string& a_string,bool& a_value,bool a_def = false){
0012 if( (a_string=="1")
0013 ||(a_string=="true")||(a_string=="TRUE")||(a_string=="True")
0014 ||(a_string=="yes")||(a_string=="YES")||(a_string=="Yes")
0015 ||(a_string=="on")||(a_string=="ON")||(a_string=="On")
0016 ){
0017 a_value = true;
0018 return true;
0019 } else if((a_string=="0")
0020 ||(a_string=="false")||(a_string=="FALSE")||(a_string=="False")
0021 ||(a_string=="no")||(a_string=="NO")||(a_string=="No")
0022 ||(a_string=="off")||(a_string=="OFF")||(a_string=="Off")
0023 ){
0024 a_value = false;
0025 return true;
0026 } else {
0027 a_value = a_def;
0028 return false;
0029 }
0030 }
0031
0032 }
0033
0034 #include <sstream>
0035
0036 namespace tools {
0037
0038 template <class T>
0039 inline bool to(const std::string& a_s,T& a_v,const T& a_def = T()) {
0040 if(a_s.empty()) {a_v = a_def;return false;} //for TOOLS_STL istringstream.
0041 std::istringstream strm(a_s.c_str());
0042 strm >> a_v;
0043 if(strm.fail()) {a_v = a_def;return false;}
0044 return strm.eof();
0045 }
0046
0047 }
0048
0049 #endif