Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/snums 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_snums
0005 #define tools_snums
0006 
0007 #include "words"
0008 #include "sto"
0009 #include "forit"
0010 
0011 namespace tools {
0012 
0013 template <class T> //T must be numbers (not std::string).
0014 inline bool snums(const std::string& a_string,
0015                   std::istringstream& a_iss,std::vector<std::string>& a_tmp,
0016                   const std::string& a_sep,
0017                   std::vector<T>& a_values,bool a_clear = true) {
0018   if(a_clear) a_values.clear();
0019   words(a_string,a_sep,false,a_tmp);
0020   T value;
0021   tools_vforcit(std::string,a_tmp,it) {
0022     a_iss.str(*it);
0023     a_iss.clear(); //IMPORTANT.
0024     a_iss >> value;
0025     if(a_iss.fail()) {a_values.clear();return false;}
0026     a_values.push_back(value);
0027   }
0028   return true;
0029 }
0030 
0031 template <class T> //T must be numbers (not std::string).
0032 inline bool snums(const std::string& a_string,const std::string& a_sep,std::vector<T>& a_values,bool a_clear = true) {
0033   std::istringstream iss;
0034   std::vector<std::string> words;
0035   return snums(a_string,iss,words,a_sep,a_values,a_clear);
0036 }
0037 
0038 }
0039 
0040 #endif