add to_string method to MAKE_ENUM
structs generated by the MAKE_ENUM makro now have a .to_string() method.
This commit is contained in:
parent
f16dec91b9
commit
08e3862efa
8 changed files with 20 additions and 17 deletions
|
@ -460,7 +460,7 @@ config map_context::to_config()
|
|||
side["side"] = side_num;
|
||||
side["hidden"] = t->hidden();
|
||||
|
||||
side["controller"] = team::CONTROLLER::enum_to_string (t->controller());
|
||||
side["controller"] = t->controller();
|
||||
side["no_leader"] = t->no_leader();
|
||||
|
||||
side["team_name"] = t->team_name();
|
||||
|
|
|
@ -191,7 +191,7 @@ configure::configure(game_display& disp, const config &cfg, chat& c, config& gam
|
|||
|
||||
std::vector<std::string> translated_modes;
|
||||
for(size_t i = 0; i < mp_game_settings::RANDOM_FACTION_MODE::count; ++i) {
|
||||
std::string mode_str = mp_game_settings::RANDOM_FACTION_MODE::enum_to_string(mp_game_settings::RANDOM_FACTION_MODE::from_int(i));
|
||||
std::string mode_str = mp_game_settings::RANDOM_FACTION_MODE::from_int(i).to_string();
|
||||
translated_modes.push_back(translation::gettext(mode_str.c_str()));
|
||||
}
|
||||
random_faction_mode_.set_items(translated_modes);
|
||||
|
@ -244,7 +244,7 @@ configure::~configure()
|
|||
// Save values for next game
|
||||
DBG_MP << "storing parameter values in preferences" << std::endl;
|
||||
preferences::set_shuffle_sides(engine_.shuffle_sides());
|
||||
preferences::set_random_faction_mode(mp_game_settings::RANDOM_FACTION_MODE::enum_to_string(engine_.random_faction_mode()));
|
||||
preferences::set_random_faction_mode(engine_.random_faction_mode().to_string());
|
||||
preferences::set_use_map_settings(engine_.use_map_settings());
|
||||
preferences::set_countdown(engine_.mp_countdown());
|
||||
preferences::set_countdown_init_time(engine_.mp_countdown_init_time());
|
||||
|
|
|
@ -68,7 +68,7 @@ static config get_selected_helper(const ng::create_engine * eng_ptr)
|
|||
("icon", eng.current_level().icon())
|
||||
("description", eng.current_level().description())
|
||||
("allow_era_choice", eng.current_level().allow_era_choice())
|
||||
("type", ng::level::TYPE::enum_to_string(eng.current_level_type()));
|
||||
("type", eng.current_level_type());
|
||||
}
|
||||
|
||||
static config find_helper(const ng::create_engine * eng_ptr, const config & cfg)
|
||||
|
@ -77,8 +77,7 @@ static config find_helper(const ng::create_engine * eng_ptr, const config & cfg)
|
|||
const ng::create_engine & eng = *eng_ptr;
|
||||
std::string str = cfg["id"].str();
|
||||
|
||||
return config_of("index", eng.find_level_by_id(str))
|
||||
("type", ng::level::TYPE::enum_to_string(eng.find_level_type_by_id(str)));
|
||||
return config_of("index", eng.find_level_by_id(str))("type", eng.find_level_type_by_id(str));
|
||||
}
|
||||
|
||||
create::create(game_display& disp, const config& cfg, saved_game& state,
|
||||
|
@ -227,7 +226,7 @@ create::create(game_display& disp, const config& cfg, saved_game& state,
|
|||
void create::select_level_type_helper(const std::string & str)
|
||||
{
|
||||
for (size_t idx = 0; idx < available_level_types_.size(); idx++) {
|
||||
if (ng::level::TYPE::enum_to_string(available_level_types_[idx]) == str) {
|
||||
if (available_level_types_[idx].to_string() == str) {
|
||||
level_type_combo_.set_selected(idx);
|
||||
init_level_type_changed(0);
|
||||
process_event_impl(process_event_data(false, false, false));
|
||||
|
|
|
@ -76,12 +76,12 @@ void tadvanced_graphics_options::setup_scale_button(const std::string & case_id,
|
|||
try {
|
||||
algo = SCALING_ALGORITHM::string_to_enum(preferences::get(pref_id));
|
||||
} catch (bad_enum_cast &) {
|
||||
preferences::set(pref_id, SCALING_ALGORITHM::enum_to_string(algo));
|
||||
preferences::set(pref_id, algo.to_string());
|
||||
}
|
||||
|
||||
// algo is now synced with preference, and default value of linear if something went wrong
|
||||
|
||||
ttoggle_button * b = &find_widget<ttoggle_button>(&window, pref_id + "_" + SCALING_ALGORITHM::enum_to_string(button), false);
|
||||
ttoggle_button * b = &find_widget<ttoggle_button>(&window, pref_id + "_" + button.to_string(), false);
|
||||
b->set_value(algo == button);
|
||||
|
||||
connect_signal_mouse_left_click(*b, boost::bind(&tadvanced_graphics_options::scale_button_callback, this, pref_id, button, boost::ref(window)));
|
||||
|
@ -93,17 +93,17 @@ void tadvanced_graphics_options::scale_button_callback(std::string pref_id, SCAL
|
|||
try {
|
||||
algo = SCALING_ALGORITHM::string_to_enum(preferences::get(pref_id));
|
||||
} catch (bad_enum_cast &) {
|
||||
preferences::set(pref_id, SCALING_ALGORITHM::enum_to_string(algo));
|
||||
preferences::set(pref_id, algo.to_string());
|
||||
}
|
||||
|
||||
if (algo != me) {
|
||||
image::flush_cache();
|
||||
}
|
||||
|
||||
preferences::set(pref_id, SCALING_ALGORITHM::enum_to_string(me));
|
||||
preferences::set(pref_id, me.to_string());
|
||||
|
||||
for (size_t x = 0; x < SCALING_ALGORITHM::count; ++x) {
|
||||
ttoggle_button * b = &find_widget<ttoggle_button>(&window, pref_id + "_" + SCALING_ALGORITHM::enum_to_string(SCALING_ALGORITHM::from_int(x)), false);
|
||||
ttoggle_button * b = &find_widget<ttoggle_button>(&window, pref_id + "_" + SCALING_ALGORITHM::from_int(x).to_string(), false);
|
||||
b->set_value(x == me.cast<size_t>());
|
||||
}
|
||||
|
||||
|
|
|
@ -165,6 +165,10 @@ struct NAME : public enum_tag \
|
|||
assert(false && "Corrupted enum found with identifier NAME"); \
|
||||
throw "assertion ignored"; \
|
||||
} \
|
||||
std::string to_string () const \
|
||||
{ \
|
||||
return enum_to_string(*this); \
|
||||
} \
|
||||
friend std::ostream& operator<< (std::ostream & os, NAME val) \
|
||||
{ \
|
||||
os << enum_to_string(val); \
|
||||
|
|
|
@ -2810,9 +2810,9 @@ void console_handler::do_controller()
|
|||
return;
|
||||
}
|
||||
|
||||
std::string report = team::CONTROLLER::enum_to_string (menu_handler_.teams()[side_num - 1].controller());
|
||||
std::string report = menu_handler_.teams()[side_num - 1].controller().to_string();
|
||||
if (!menu_handler_.teams()[side_num - 1].is_proxy_human()) {
|
||||
report += " (" + team::PROXY_CONTROLLER::enum_to_string(menu_handler_.teams()[side_num - 1].proxy_controller()) + ")";
|
||||
report += " (" + menu_handler_.teams()[side_num - 1].proxy_controller().to_string() + ")";
|
||||
}
|
||||
|
||||
print(get_cmd(), report);
|
||||
|
|
|
@ -70,8 +70,8 @@ static int impl_side_get(lua_State *L)
|
|||
return_string_attrib("team_name", t.team_name());
|
||||
return_string_attrib("name", t.name());
|
||||
return_string_attrib("color", t.color());
|
||||
return_cstring_attrib("controller", team::CONTROLLER::enum_to_string(t.controller()).c_str());
|
||||
return_string_attrib("defeat_condition", team::DEFEAT_CONDITION::enum_to_string(t.defeat_condition()));
|
||||
return_cstring_attrib("controller", t.controller().to_string().c_str());
|
||||
return_string_attrib("defeat_condition", t.defeat_condition().to_string());
|
||||
return_bool_attrib("lost", t.lost());
|
||||
|
||||
if (strcmp(m, "recruit") == 0) {
|
||||
|
|
|
@ -228,7 +228,7 @@ bool side_filter::match_internal(const team &t) const
|
|||
ERR_NG << "ignoring controller= in SSF due to danger of OOS errors" << std::endl;
|
||||
else
|
||||
{
|
||||
if(cfg_controller.str() != team::CONTROLLER::enum_to_string (t.controller()))
|
||||
if(cfg_controller.str() != t.controller().to_string())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue