Skip to content

Commit

Permalink
catch invalid variablename exception when using
Browse files Browse the repository at this point in the history
these exceptiosn are not thrown yet in all cases. This patch prepares a
patch taht makes use of it.
  • Loading branch information
gfgtdf committed Jun 29, 2014
1 parent 5110a87 commit 23b0c53
Show file tree
Hide file tree
Showing 7 changed files with 469 additions and 304 deletions.
33 changes: 27 additions & 6 deletions src/game_data.cpp
Expand Up @@ -107,35 +107,56 @@ game_data::game_data(const game_data& data)
, scenario_(data.scenario_)
, next_scenario_(data.next_scenario_)
{}

//throws
config::attribute_value &game_data::get_variable(const std::string& key)
{
return get_variable_access(key, variable_info::TYPE_SCALAR).as_scalar();
}

config::attribute_value game_data::get_variable_const(const std::string &key) const
{
return get_variable_access_readonly(key, variable_info::TYPE_SCALAR).as_scalar_const();
try
{
return get_variable_access_readonly(key, variable_info::TYPE_SCALAR).as_scalar_const();
}
catch(const invalid_variable_info_exception&)
{
return config::attribute_value();
}
}

//throws
config& game_data::get_variable_cfg(const std::string& key)
{
return get_variable_access(key, variable_info::TYPE_CONTAINER).as_container();
}

void game_data::set_variable(const std::string& key, const t_string& value)
{
get_variable(key) = value;
try
{
get_variable(key) = value;
}
catch(const invalid_variable_info_exception&)
{
ERR_NG << "variable " << key << "cannot be set to " << value << std::endl;
}
}

//throws
config& game_data::add_variable_cfg(const std::string& key, const config& value)
{
return get_variable_access(key, variable_info::TYPE_ARRAY).add_child(value);
}

void game_data::clear_variable_cfg(const std::string& varname)
{
get_variable_access_noadd(varname, variable_info::TYPE_CONTAINER).clear(true);
try
{
get_variable_access_noadd(varname, variable_info::TYPE_CONTAINER).clear(true);
}
catch(const invalid_variable_info_exception&)
{
//variable doesn't exist, nothing to delete
}
}

void game_data::clear_variable(const std::string& varname)
Expand Down

0 comments on commit 23b0c53

Please sign in to comment.