diff options
author | 2016-01-11 09:18:43 +0100 | |
---|---|---|
committer | 2016-01-11 09:18:43 +0100 | |
commit | 36195292e370de0fb6b32085c105a236995ce36e (patch) | |
tree | 1fb147c3e21824272b60e4989f606bc9c206030c /src/emu/ioport.cpp | |
parent | 7c944fa3b02cd26dec3c27f1e6a4c0d33f462c4e (diff) | |
parent | 115db95642ad6d861aad63775b92350e0491f2dd (diff) |
Merge pull request #561 from ajrhacker/strings
Return std::string objects by value rather than pass by reference [ajrhacker]
Diffstat (limited to 'src/emu/ioport.cpp')
-rw-r--r-- | src/emu/ioport.cpp | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/src/emu/ioport.cpp b/src/emu/ioport.cpp index aa4a7daf7b5..282cc5c256c 100644 --- a/src/emu/ioport.cpp +++ b/src/emu/ioport.cpp @@ -897,8 +897,7 @@ void natural_keyboard::post(unicode_char ch) if (LOG_NATURAL_KEYBOARD) { const keycode_map_entry *code = find_code(ch); - std::string tempstr; - machine().logerror("natural_keyboard::post(): code=%i (%s) field->name='%s'\n", int(ch), unicode_to_string(tempstr, ch), (code != nullptr && code->field[0] != nullptr) ? code->field[0]->name() : "<null>"); + machine().logerror("natural_keyboard::post(): code=%i (%s) field->name='%s'\n", int(ch), unicode_to_string(ch).c_str(), (code != nullptr && code->field[0] != nullptr) ? code->field[0]->name() : "<null>"); } // can we post this key in the queue directly? @@ -1101,8 +1100,7 @@ void natural_keyboard::build_codes(ioport_manager &manager) if (LOG_NATURAL_KEYBOARD) { - std::string tempstr; - machine().logerror("natural_keyboard: code=%i (%s) port=%p field->name='%s'\n", int(code), unicode_to_string(tempstr, code), (void *)port, field->name()); + machine().logerror("natural_keyboard: code=%i (%s) port=%p field->name='%s'\n", int(code), unicode_to_string(code).c_str(), (void *)port, field->name()); } } } @@ -1234,9 +1232,9 @@ void natural_keyboard::timer(void *ptr, int param) // logging and debugging //------------------------------------------------- -const char *natural_keyboard::unicode_to_string(std::string &buffer, unicode_char ch) +std::string natural_keyboard::unicode_to_string(unicode_char ch) { - buffer.clear(); + std::string buffer; switch (ch) { // check some magic values @@ -1256,15 +1254,15 @@ const char *natural_keyboard::unicode_to_string(std::string &buffer, unicode_cha { // try to obtain a codename with code_name(); this can result in an empty string input_code code(DEVICE_CLASS_KEYBOARD, 0, ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, input_item_id(ch - UCHAR_MAMEKEY_BEGIN)); - machine().input().code_name(buffer, code); + buffer = machine().input().code_name(code); } // did we fail to resolve? if so, we have a last resort - if (buffer.length() == 0) + if (buffer.empty()) strprintf(buffer,"U+%04X", unsigned(ch)); break; } - return buffer.c_str(); + return buffer; } @@ -1307,8 +1305,10 @@ void natural_keyboard::frame_update(ioport_port &port, ioport_value &digital) // key_name - returns the name of a specific key //------------------------------------------------- -const char *natural_keyboard::key_name(std::string &str, unicode_char ch) +std::string natural_keyboard::key_name(unicode_char ch) const { + std::string str; + // attempt to get the string from the character info table const char_info *ci = char_info::find(ch); const char *result = (ci != nullptr) ? ci->name : nullptr; @@ -1327,7 +1327,7 @@ const char *natural_keyboard::key_name(std::string &str, unicode_char ch) // otherwise, opt for question marks else str.assign("???"); - return str.c_str(); + return str; } @@ -1337,7 +1337,7 @@ const char *natural_keyboard::key_name(std::string &str, unicode_char ch) std::string natural_keyboard::dump() { - std::string buffer, tempstr; + std::string buffer; const size_t left_column_width = 24; // loop through all codes @@ -1345,7 +1345,7 @@ std::string natural_keyboard::dump() { // describe the character code - strcatprintf(buffer,"%08X (%s) ", code.ch, unicode_to_string(tempstr, code.ch)); + strcatprintf(buffer,"%08X (%s) ", code.ch, unicode_to_string(code.ch).c_str()); // pad with spaces while (buffer.length() < left_column_width) @@ -2173,20 +2173,19 @@ ioport_field_live::ioport_field_live(ioport_field &field, analog_field *analog) if (field.type_class() == INPUT_CLASS_KEYBOARD && field.specific_name() == nullptr) { // loop through each character on the field - std::string tempstr; for (int which = 0; ; which++) { unicode_char ch = field.keyboard_code(which); if (ch == 0) break; - strcatprintf(name, "%-*s ", MAX(SPACE_COUNT - 1, 0), field.manager().natkeyboard().key_name(tempstr, ch)); + strcatprintf(name, "%-*s ", MAX(SPACE_COUNT - 1, 0), field.manager().natkeyboard().key_name(ch).c_str()); } // trim extra spaces strtrimspace(name); // special case - if (name.length() == 0) + if (name.empty()) name.assign("Unnamed Key"); } } @@ -3175,7 +3174,7 @@ void ioport_manager::save_sequence(xml_data_node *parentnode, input_seq_type typ if (seq.length() == 0) seqstring.assign("NONE"); else - machine().input().seq_to_tokens(seqstring, seq); + seqstring = machine().input().seq_to_tokens(seq); // add the new node xml_data_node *seqnode = xml_add_child(parentnode, "newseq", seqstring.c_str()); @@ -3233,8 +3232,7 @@ void ioport_manager::save_default_inputs(xml_data_node *parentnode) if (portnode != nullptr) { // add the port information and attributes - std::string tempstr; - xml_set_attribute(portnode, "type", input_type_to_token(tempstr, entry->type(), entry->player())); + xml_set_attribute(portnode, "type", input_type_to_token(entry->type(), entry->player()).c_str()); // add only the sequences that have changed from the defaults for (input_seq_type type = SEQ_TYPE_STANDARD; type < SEQ_TYPE_TOTAL; ++type) @@ -3288,9 +3286,8 @@ void ioport_manager::save_game_inputs(xml_data_node *parentnode) if (portnode != nullptr) { // add the identifying information and attributes - std::string tempstr; xml_set_attribute(portnode, "tag", port->tag()); - xml_set_attribute(portnode, "type", input_type_to_token(tempstr, field->type(), field->player())); + xml_set_attribute(portnode, "type", input_type_to_token(field->type(), field->player()).c_str()); xml_set_attribute_int(portnode, "mask", field->mask()); xml_set_attribute_int(portnode, "defvalue", field->defvalue() & field->mask()); @@ -4399,15 +4396,15 @@ ioport_type ioport_manager::token_to_input_type(const char *string, int &player) // type and player to a string token //------------------------------------------------- -const char *ioport_manager::input_type_to_token(std::string &str, ioport_type type, int player) +std::string ioport_manager::input_type_to_token(ioport_type type, int player) { // look up the port and return the token input_type_entry *entry = m_type_to_entry[type][player]; if (entry != nullptr) - return str.assign(entry->token()).c_str(); + return std::string(entry->token()); // if that fails, carry on - return strformat(str, "TYPE_OTHER(%d,%d)", type, player).c_str(); + return strformat("TYPE_OTHER(%d,%d)", type, player); } |