2#include <batchlas/export.hh>
31 const std::string s(v);
32 return (s ==
"1" || s ==
"true" || s ==
"TRUE" || s ==
"on" || s ==
"ON");
46 const std::string s(v);
47 return (s ==
"0" || s ==
"false" || s ==
"FALSE" || s ==
"off" || s ==
"OFF");
56 const char* v = std::getenv(name);
57 if (!v)
return fallback;
59 return std::stoi(std::string(v));
74 return v > 0 ? v : fallback;
79inline std::string
env_string_or(
const char* name,
const std::string& fallback) {
80 const char* v = std::getenv(name);
81 if (!v || !*v)
return fallback;
82 return std::string(v);
111 if (
const char* old = std::getenv(name_)) {
113 had_old_value_ =
true;
116 ::setenv(name_, value, 1);
125 if (had_old_value_) {
126 ::setenv(name_, old_value_.c_str(), 1);
140 std::string old_value_;
141 bool had_old_value_ =
false;
ScopedEnvVar(const char *name, const char *value)
Pin name to value for the scope.
ScopedEnvVar & operator=(const ScopedEnvVar &)=delete
ScopedEnvVar(const ScopedEnvVar &)=delete
~ScopedEnvVar()
Restore the previous value (or unset state) and reload the settings.
int env_int_or(const char *name, int fallback)
The integer value of environment variable name.
std::string env_string_or(const char *name, const std::string &fallback)
The value of environment variable name, or fallback when it is unset or empty.
bool env_falsy(const char *v)
True when v is exactly one of 0, false, FALSE, off, OFF.
bool env_truthy(const char *v)
True when v is exactly one of 1, true, TRUE, on, ON.
int env_positive_int_or(const char *name, int fallback)
As env_int_or(), but a value <= 0 also yields fallback.
void reload_settings()
Re-read the environment on top of the last configure() (or the defaults).