Warning, /include/Geant4/tools/get_env 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_get_env
0005 #define tools_get_env
0006
0007 #include <cstdlib>
0008
0009 #include "sto"
0010
0011 namespace tools {
0012
0013 inline bool is_env(const std::string& a_string){
0014 const char* env = ::getenv(a_string.c_str());
0015 return (env?true:false);
0016 }
0017
0018 inline bool get_env(const std::string& a_string,std::string& a_value){
0019 const char* env = ::getenv(a_string.c_str());
0020 if(env) {
0021 a_value = std::string(env?env:"");
0022 return true;
0023 } else {
0024 a_value.clear();
0025 return false;
0026 }
0027 }
0028
0029 template <class T>
0030 inline bool get_env(const std::string& a_string,T& a_v,const T& a_def = T()){
0031 std::string _s;
0032 if(!get_env(a_string,_s)) {a_v = a_def;return false;}
0033 return to<T>(_s,a_v,a_def);
0034 }
0035
0036 inline bool get_env_bool(const std::string& a_string,bool& a_v){
0037 std::string _s;
0038 if(!get_env(a_string,_s)) return false;
0039 return to(_s,a_v);
0040 }
0041
0042 }
0043
0044 #endif