1 #include <boost/filesystem.hpp> 2 #include <boost/algorithm/string.hpp> 4 #include <vcsn/config.hh> 18 require(boost::filesystem::exists(p),
19 "config file does not exist:", p);
20 return YAML::LoadFile(p.string());
27 if (from.IsScalar() || from.IsSequence())
29 else if (from.IsMap())
32 auto key = e.first.as<std::string>();
36 merge_recurse(e.second, node);
39 else if (
out.Tag() !=
"!StyleList")
40 merge_recurse(e.second,
out[key]);
42 raise(
"bad config value");
68 return as<std::string>();
75 "configuration: requesting a key (", key,
78 "configuration: invalid key: ", key);
92 return node_[key].IsDefined();
97 #if VCSN_YAML_CPP_REMOVE_WORKS 100 raise(
"configuration: libyaml-cpp is broken, cannot remove node ", key);
106 require(
node_.IsSequence(),
"configuration: node is not a sequence");
107 return node_.begin();
117 auto dest_node = Clone(from.
node_);
118 merge_recurse(
node_, dest_node);
127 std::unique_ptr<std::vector<std::string>>
130 auto res = std::make_unique<std::vector<std::string>>();
131 require(
node_.IsMap(),
"configuration: node is not a map");
134 res->emplace_back(e.first.as<std::string>());
150 auto path =
xgetenv(
"VCSN_DATA_PATH", VCSN_DATADIR);
154 config_tree_ = load_file(flib.find_file(
"config.yaml"));
156 merge_recurse(load_file(flib.find_file(
"version.yaml")),
159 if (!std::getenv(
"VCSN_NO_HOME_CONFIG"))
162 if (boost::filesystem::exists(p))
179 auto subkeys = std::vector<std::string>{};
182 if (subkeys.size() == 2 && subkeys[0] ==
"configuration")
184 auto env_var =
"VCSN_" + boost::to_upper_copy(subkeys[1]);
185 if (
auto res = std::getenv(env_var.c_str()))
189 for (
const auto& subkey : subkeys)
191 std::make_unique<detail::config::value>((*config)[subkey]);
void remove(const std::string &key)
Remove a key.
bool is_valid(const std::string &key) const
Check that this node refers to a key that exists in the tree.
std::string xgetenv(const std::string &var, const std::string &val="")
getenv(var) if defined, otherwise val.
rat::expression_polynomial_t< ExpSet > split(const ExpSet &rs, const typename ExpSet::value_t &e)
Split an expression.
auto sort(const Aut &a) -> permutation_automaton< Aut >
config()
Load all the configuration files.
The class returned by [] operators.
friend void swap(value &first, value &second)
std::unique_ptr< std::vector< std::string > > gen_keys() const
std::string expand_tilda(const std::string &res)
Expand initial "~" in res.
Explicit path representation.
std::string str() const
Get the node value as a string.
std::string configuration(const std::string &key)
Get the string mapped by key (e.g., "configuration.version", "dot.styles").
value & operator=(value rhs)
Assign a new value to this key.
std::vector< std::string > keys() const
void swap(config::value &first, config::value &second)
detail::config & get_config()
Get the configuration singleton.
value operator[](const std::string &key) const
value operator[](const std::string &key)
Access a subkey.
Manage sets of inclusion paths.
std::unique_ptr< const std::vector< std::string > > keys_
std::ostream & print(std::ostream &out) const
void require(Bool b, Args &&... args)
If b is not verified, raise an error with args as message.
void merge(const value &from)
Merge a value into another one - and modify the first.
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.