41#ifndef G4ENVIRONMENTUTILS_HH
42#define G4ENVIRONMENTUTILS_HH
73 template <
typename _Tp>
74 void insert(
const std::string& env_id, _Tp val)
80 static std::mutex _mutex;
90 std::stringstream filler;
92 filler << std::setw(90) <<
"";
94 ss << filler.str() <<
"\n# Environment settings:\n";
95 for(
const auto& itr : env.
get())
97 ss <<
"# " << std::setw(35) << std::right << itr.first <<
"\t = \t"
98 << std::left << itr.second <<
"\n";
101 os << ss.str() << std::endl;
115template <
typename _Tp>
116_Tp
G4GetEnv(
const std::string& env_id, _Tp _default = _Tp())
118 char* env_var = std::getenv(env_id.c_str());
121 std::string str_var = std::string(env_var);
122 std::istringstream iss(str_var);
145 char* env_var = std::getenv(env_id.c_str());
146 if(env_var !=
nullptr)
166template <
typename _Tp>
167_Tp
G4GetEnv(
const std::string& env_id, _Tp _default,
const std::string& msg)
169 char* env_var = std::getenv(env_id.c_str());
172 std::string str_var = std::string(env_var);
173 std::istringstream iss(str_var);
176 G4cout <<
"Environment variable \"" << env_id <<
"\" enabled with "
177 <<
"value == " << var <<
". " << msg <<
G4endl;
199 const char* originOfException,
200 const char* exceptionCode,
202 const char* description)
204 char* env_var = std::getenv(env_id.c_str());
205 if(env_var !=
nullptr)
207 std::string str_var = std::string(env_var);
208 std::istringstream iss(str_var);
217 G4Exception(originOfException, exceptionCode, severity, description);
void G4PrintEnv(std::ostream &os=G4cout)
_Tp G4GetEnv(const std::string &env_id, _Tp _default=_Tp())
const char * G4FindDataDir(const char *)
G4String G4GetDataEnv(const std::string &env_id, const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4GLOB_DLL std::ostream G4cout
void insert(const std::string &env_id, _Tp val)
std::map< string_t, string_t > env_map_t
std::pair< string_t, string_t > env_pair_t
static G4EnvSettings * GetInstance()
const env_map_t & get() const
friend std::ostream & operator<<(std::ostream &os, const G4EnvSettings &env)