43 Environment(std::initializer_list<std::pair<std::string const, std::string>> init)
45 Environment(
const std::map<std::string, std::string>& defines) : defines_(defines) {}
46 Environment(std::map<std::string, std::string>&& defines) : defines_(std::move(defines)) {}
48 [[nodiscard]]
bool prefer_external()
const {
return prefer_external_; }
49 void prefer_external(
bool value) { prefer_external_ = value; }
51 [[nodiscard]]
bool allow_undefined()
const {
return allow_undefined_; }
52 void allow_undefined(
bool value) { allow_undefined_ = value; }
54 void insert(
const std::string& key,
const std::string& value) {
55 assert(defines_.count(key) == 0);
56 defines_.insert(std::make_pair(key, value));
59 void set(
const std::string& key,
const std::string& value) { defines_[key] = value; }
70 [[nodiscard]] std::optional<std::string>
get(
const std::string& key)
const {
71 return get(key, prefer_external_);
73 [[nodiscard]] std::optional<std::string>
get(
const std::string& key,
bool prefer_external)
const;
83 [[nodiscard]] std::string
get_or(
const std::string& key,
const std::string& alternative)
const {
84 return get(key).value_or(alternative);
86 [[nodiscard]] std::string
get_or(
const std::string& key,
const std::string& alternative,
87 bool prefer_external)
const {
88 return get(key, prefer_external).value_or(alternative);
99 [[nodiscard]] std::string
require(
const std::string& key)
const {
100 return require(key, prefer_external_);
102 [[nodiscard]] std::string
require(
const std::string& key,
bool prefer_external)
const;
110 [[nodiscard]] std::string
evaluate(
const std::string& s)
const {
111 return evaluate(s, prefer_external_, allow_undefined_);
113 [[nodiscard]] std::string
evaluate(
const std::string& s,
bool prefer_external,
114 bool allow_undefined)
const;
122 [[nodiscard]] std::string
interpolate(
const std::string& s)
const {
123 return interpolate(s, prefer_external_, allow_undefined_);
125 [[nodiscard]] std::string
interpolate(
const std::string& s,
bool prefer_external,
126 bool allow_undefined)
const;
129 bool prefer_external_{
true};
130 bool allow_undefined_{
false};
131 std::map<std::string, std::string> defines_;
134 inline std::string interpolate_vars(
const std::string& s,
const Environment* env =
nullptr) {
135 if (env !=
nullptr) {
136 return env->interpolate(s);
Definition: server_test.cpp:71
Definition: environment.hpp:34
std::optional< std::string > get(const std::string &key) const
Definition: environment.hpp:70
std::string evaluate(const std::string &s) const
Definition: environment.hpp:110
std::string get_or(const std::string &key, const std::string &alternative) const
Definition: environment.hpp:83
std::string interpolate(const std::string &s) const
Definition: environment.hpp:122
std::string require(const std::string &key) const
Definition: environment.hpp:99