Move config_variable_set class into a header
This commit is contained in:
parent
fd537c1bf3
commit
67ba87a36c
3 changed files with 20 additions and 20 deletions
|
@ -58,7 +58,8 @@
|
|||
#include "serialization/binary_or_text.hpp"
|
||||
#include "variable_info.hpp"
|
||||
#include "formula/string_utils.hpp"
|
||||
#include "config.hpp" //Also for variable_set
|
||||
#include "config.hpp"
|
||||
#include "variable.hpp" // for config_variable_set
|
||||
|
||||
#include <boost/range/adaptors.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
|
@ -229,27 +230,9 @@ void saved_game::expand_scenario()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct config_variable_set : public variable_set
|
||||
{
|
||||
const config& cfg_;
|
||||
config_variable_set(const config& cfg) : cfg_(cfg) {}
|
||||
virtual config::attribute_value get_variable_const(const std::string &id) const
|
||||
{
|
||||
try
|
||||
{
|
||||
variable_access_const variable(id, cfg_);
|
||||
return variable.as_scalar();
|
||||
}
|
||||
catch(const invalid_variablename_exception&)
|
||||
{
|
||||
ERR_NG << "invalid variablename " << id << "\n";
|
||||
return config::attribute_value();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
bool variable_to_bool(const config& vars, const std::string& expression)
|
||||
{
|
||||
std::string res = utils::interpolate_variables_into_string(expression, config_variable_set(vars));
|
||||
|
|
|
@ -56,6 +56,16 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
config_attribute_value config_variable_set::get_variable_const(const std::string &id) const {
|
||||
try {
|
||||
variable_access_const variable(id, cfg_);
|
||||
return variable.as_scalar();
|
||||
} catch(const invalid_variablename_exception&) {
|
||||
ERR_NG << "invalid variablename " << id << "\n";
|
||||
return config::attribute_value();
|
||||
}
|
||||
}
|
||||
|
||||
const config vconfig::default_empty_config = config();
|
||||
|
||||
|
||||
|
|
|
@ -23,6 +23,13 @@
|
|||
|
||||
class unit_map;
|
||||
|
||||
class config_variable_set : public variable_set {
|
||||
const config& cfg_;
|
||||
public:
|
||||
config_variable_set(const config& cfg) : cfg_(cfg) {}
|
||||
virtual config::attribute_value get_variable_const(const std::string &id) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* A variable-expanding proxy for the config class. This class roughly behaves
|
||||
* as a constant config object, but automatically expands variables.
|
||||
|
|
Loading…
Add table
Reference in a new issue