Import Geant4 10.4.0 source tree
This commit is contained in:
@@ -17,12 +17,14 @@
|
||||
|
||||
namespace tools {
|
||||
|
||||
inline bool isenv(const std::string& a_string){
|
||||
inline bool is_env(const std::string& a_string){
|
||||
const char* env = ::getenv(a_string.c_str());
|
||||
return (env?true:false);
|
||||
}
|
||||
|
||||
inline bool getenv(const std::string& a_string,std::string& a_value){
|
||||
inline bool isenv(const std::string& a_string){return is_env(a_string);} //deprecated.
|
||||
|
||||
inline bool get_env(const std::string& a_string,std::string& a_value){
|
||||
const char* env = ::getenv(a_string.c_str());
|
||||
if(env) {
|
||||
a_value = std::string(env?env:"");
|
||||
@@ -32,6 +34,7 @@ inline bool getenv(const std::string& a_string,std::string& a_value){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
inline bool getenv(const std::string& a_string,std::string& a_value){return get_env(a_string,a_value);} //deprecated.
|
||||
|
||||
template <class T>
|
||||
inline bool get_env(const std::string& a_string,T& a_v){
|
||||
@@ -46,49 +49,54 @@ inline bool get_env_bool(const std::string& a_string,bool& a_v){
|
||||
return to(s,a_v);
|
||||
}
|
||||
|
||||
inline bool putenv(const std::string& a_env,const std::string& a_value){
|
||||
inline bool put_env(const std::string& a_env,const std::string& a_value){
|
||||
std::string value = a_env+"="+a_value;
|
||||
if(::putenv(tools::str_dup(value.c_str(),false))) return false;
|
||||
#ifdef TOOLS_MEM
|
||||
if(::putenv(str_dup(value.c_str(),false))) return false;
|
||||
#else
|
||||
if(::putenv(str_dup(value.c_str()))) return false;
|
||||
#endif
|
||||
//check:
|
||||
std::string s;
|
||||
if(!getenv(a_env,s)) return false;
|
||||
if(s!=a_value) return false;
|
||||
return true;
|
||||
}
|
||||
inline bool putenv(const std::string& a_env,const std::string& a_value){return put_env(a_env,a_value);} //deprecated.
|
||||
|
||||
inline bool rmenv(const std::string& a_env){
|
||||
inline bool rm_env(const std::string& a_env){
|
||||
#ifdef _MSC_VER
|
||||
std::string value = a_env+"=";
|
||||
if(::putenv(tools::str_dup(value.c_str(),false))) return false;
|
||||
#ifdef TOOLS_MEM
|
||||
if(::putenv(str_dup(value.c_str(),false))) return false;
|
||||
#else
|
||||
if(::putenv(str_dup(value.c_str()))) return false;
|
||||
#endif
|
||||
#else
|
||||
::unsetenv(a_env.c_str());
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool rmenv(const std::string& a_env) {return rm_env(a_env);} //deprecated. Still used in OnX.
|
||||
|
||||
inline bool check_getenv(std::ostream& a_out,
|
||||
const std::string& a_new,const std::string& a_old,
|
||||
std::string& a_env){
|
||||
if(tools::getenv(a_new,a_env)) return true;
|
||||
if(tools::getenv(a_old,a_env)) {
|
||||
a_out << "Environment variable " << sout(a_old) << " is deprecated."
|
||||
<< " Use " << sout(a_new) << " instead."
|
||||
<< std::endl;
|
||||
if(get_env(a_new,a_env)) return true;
|
||||
if(get_env(a_old,a_env)) {
|
||||
a_out << "Environment variable " << sout(a_old) << " is deprecated. Use " << sout(a_new) << " instead." << std::endl;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline int execute(const std::string& a_string) {
|
||||
return ::system(a_string.c_str());
|
||||
}
|
||||
inline int execute(const std::string& a_string) {return ::system(a_string.c_str());}
|
||||
|
||||
inline bool env_append(const std::string& a_env,
|
||||
const std::string& a_sep,
|
||||
const std::vector<std::string>& a_vals){
|
||||
inline bool env_append(const std::string& a_env,const std::string& a_sep,const std::vector<std::string>& a_vals){
|
||||
std::string env_value;
|
||||
if(tools::isenv(a_env)) {
|
||||
if(!tools::getenv(a_env,env_value)) return false;
|
||||
if(is_env(a_env)) {
|
||||
if(!get_env(a_env,env_value)) return false;
|
||||
}
|
||||
|
||||
{std::vector<std::string>::const_iterator it;
|
||||
@@ -98,9 +106,9 @@ inline bool env_append(const std::string& a_env,
|
||||
|
||||
if(env_value.size()) {
|
||||
std::vector<std::string> ws;
|
||||
tools::words(env_value,a_sep,false,ws);
|
||||
words(env_value,a_sep,false,ws);
|
||||
// Remove existing one, so that value be put at end.
|
||||
tools::remove(ws,value);
|
||||
remove(ws,value);
|
||||
if(!nums2s<std::string>(ws,env_value,a_sep)) {}
|
||||
}
|
||||
|
||||
@@ -117,8 +125,7 @@ inline bool env_path_append(const std::string& a_env,const std::vector<std::stri
|
||||
return env_append(a_env,psep(),a_paths);
|
||||
}
|
||||
|
||||
inline bool env_append_path(const std::string& a_env,
|
||||
const std::string& a_path){
|
||||
inline bool env_append_path(const std::string& a_env,const std::string& a_path){
|
||||
std::vector<std::string> v;
|
||||
v.push_back(a_path);
|
||||
return env_append(a_env,psep(),v);
|
||||
|
||||
Reference in New Issue
Block a user