Changeset - r27399:588375abeca3
[Not reviewed]
master
0 2 0
Rubidium - 16 months ago 2023-05-18 09:02:36
rubidium@openttd.org
Codechange: replace std::vector + duplicate preventing include with std::set
2 files changed with 5 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/hotkeys.cpp
Show inline comments
 
@@ -210,15 +210,15 @@ static std::string KeycodeToString(uint1
 
 * @param hotkey The keycodes of this hotkey need to be converted to a string.
 
 * @return A string representation of all keycodes.
 
 */
 
std::string SaveKeycodes(const Hotkey *hotkey)
 
{
 
	std::string str;
 
	for (uint i = 0; i < hotkey->keycodes.size(); i++) {
 
		if (i > 0) str += ",";
 
		str += KeycodeToString(hotkey->keycodes[i]);
 
	for (auto keycode : hotkey->keycodes) {
 
		if (!str.empty()) str += ",";
 
		str += KeycodeToString(keycode);
 
	}
 
	return str;
 
}
 

	
 
/**
 
 * Create a new Hotkey object with a single default keycode.
 
@@ -254,13 +254,13 @@ Hotkey::Hotkey(const uint16 *default_key
 
 * Add a keycode to this hotkey, from now that keycode will be matched
 
 * in addition to any previously added keycodes.
 
 * @param keycode The keycode to add.
 
 */
 
void Hotkey::AddKeycode(uint16 keycode)
 
{
 
	include(this->keycodes, keycode);
 
	this->keycodes.insert(keycode);
 
}
 

	
 
HotkeyList::HotkeyList(const char *ini_group, Hotkey *items, GlobalHotkeyHandlerFunc global_hotkey_handler) :
 
	global_hotkey_handler(global_hotkey_handler), ini_group(ini_group), items(items)
 
{
 
	if (_hotkey_lists == nullptr) _hotkey_lists = new std::vector<HotkeyList*>();
src/hotkeys.h
Show inline comments
 
@@ -7,13 +7,12 @@
 

	
 
/** @file hotkeys.h %Hotkey related functions. */
 

	
 
#ifndef HOTKEYS_H
 
#define HOTKEYS_H
 

	
 
#include "core/smallvec_type.hpp"
 
#include "gfx_type.h"
 
#include "window_type.h"
 
#include "string_type.h"
 

	
 
/**
 
 * All data for a single hotkey. The name (for saving/loading a configfile),
 
@@ -24,13 +23,13 @@ struct Hotkey {
 
	Hotkey(const uint16 *default_keycodes, const char *name, int num);
 

	
 
	void AddKeycode(uint16 keycode);
 

	
 
	const char *name;
 
	int num;
 
	std::vector<uint16> keycodes;
 
	std::set<uint16> keycodes;
 
};
 

	
 
#define HOTKEY_LIST_END Hotkey((uint16)0, nullptr, -1)
 

	
 
struct IniFile;
 

	
0 comments (0 inline, 0 general)