Added small wrapper function for converting a bool to string

This commit is contained in:
Charles Dang 2017-04-28 12:41:38 +11:00
parent 2ddb305844
commit 647f3e12be
7 changed files with 19 additions and 8 deletions

View file

@ -412,7 +412,7 @@ public:
class lua_aspect_visitor : public boost::static_visitor<std::string> {
static std::string quote_string(const std::string& s);
public:
std::string operator()(bool b) const {return b ? "true" : "false";}
std::string operator()(bool b) const {return utils::bool_string(b);}
std::string operator()(int i) const {return std::to_string(i);}
std::string operator()(unsigned long long i) const {return std::to_string(i);}
std::string operator()(double i) const {return std::to_string(i);}

View file

@ -123,13 +123,13 @@ void drop_down_menu::pre_show(window& window)
if(!entry.has_attribute("image")) {
item["label"] = entry["label"];
item["use_markup"] = use_markup_ ? "true" : "false";
item["use_markup"] = utils::bool_string(use_markup_);
data.emplace("label", item);
}
if(entry.has_attribute("details")) {
item["label"] = entry["details"];
item["use_markup"] = use_markup_ ? "true" : "false";
item["use_markup"] = utils::bool_string(use_markup_);
data.emplace("details", item);
}

View file

@ -169,7 +169,7 @@ public:
{
string_map& item = data_[ref];
item["label"] = label;
item["use_markup"] = markup ? "true" : "false";
item["use_markup"] = utils::bool_string(markup);
return *this;
}

View file

@ -468,6 +468,14 @@ bool string_bool(const std::string& str, bool def) {
return true;
}
std::string bool_string(const bool value)
{
std::ostringstream ss;
ss << std::boolalpha << value;
return ss.str();
}
std::string signed_value(int val)
{
std::ostringstream oss;

View file

@ -263,6 +263,9 @@ inline std::string quote(const std::string &str)
/** Convert no, false, off, 0, 0.0 to false, empty to def, and others to true */
bool string_bool(const std::string& str,bool def=false);
/** Converts a bool value to 'true' or 'false' */
std::string bool_string(const bool value);
/** Convert into a signed value (using the Unicode "" and +0 convention */
std::string signed_value(int val);

View file

@ -126,7 +126,7 @@ protected:
throw game::load_game_failed("Map not found");
}
DBG_NG_TC << "snapshot: "<< (player_exists_ ? "true" : "false") <<std::endl;
DBG_NG_TC << "snapshot: " << utils::bool_string(player_exists_) <<std::endl;
unit_configs_.clear();
seen_ids_.clear();

View file

@ -456,15 +456,15 @@ std::vector<std::string> frame_parsed_parameters::debug_strings() const
}
if(!boost::indeterminate(auto_vflip_)) {
v.push_back("auto_vflip=" + std::string(auto_vflip_ ? "true" : "false"));
v.push_back("auto_vflip=" + utils::bool_string(auto_vflip_));
}
if(!boost::indeterminate(auto_hflip_)) {
v.push_back("auto_hflip=" + std::string(auto_hflip_ ? "true" : "false"));
v.push_back("auto_hflip=" + utils::bool_string(auto_hflip_));
}
if(!boost::indeterminate(primary_frame_)) {
v.push_back("primary_frame=" + std::string(primary_frame_ ? "true" : "false"));
v.push_back("primary_frame=" + utils::bool_string(primary_frame_));
}
if(!drawing_layer_.get_original().empty()) {