Changeset - r23602:f83b6cbc2d6c
[Not reviewed]
master
0 15 0
Michael Lutz - 6 years ago 2019-04-02 19:31:33
michi@icosahedron.de
Codechange: If something is a vector of strings, use a vector of strings instead of an AutoFreeSmallVector.
15 files changed with 94 insertions and 104 deletions:
0 comments (0 inline, 0 general)
src/console_cmds.cpp
Show inline comments
 
@@ -553,7 +553,7 @@ DEF_CONSOLE_CMD(ConUnBan)
 
	/* Try by IP. */
 
	uint index;
 
	for (index = 0; index < _network_ban_list.size(); index++) {
 
		if (strcmp(_network_ban_list[index], argv[1]) == 0) break;
 
		if (_network_ban_list[index] == argv[1]) break;
 
	}
 

	
 
	/* Try by index. */
 
@@ -563,9 +563,8 @@ DEF_CONSOLE_CMD(ConUnBan)
 

	
 
	if (index < _network_ban_list.size()) {
 
		char msg[64];
 
		seprintf(msg, lastof(msg), "Unbanned %s", _network_ban_list[index]);
 
		seprintf(msg, lastof(msg), "Unbanned %s", _network_ban_list[index].c_str());
 
		IConsolePrint(CC_DEFAULT, msg);
 
		free(_network_ban_list[index]);
 
		_network_ban_list.erase(_network_ban_list.begin() + index);
 
	} else {
 
		IConsolePrint(CC_DEFAULT, "Invalid list index or IP not in ban-list.");
 
@@ -585,8 +584,8 @@ DEF_CONSOLE_CMD(ConBanList)
 
	IConsolePrint(CC_DEFAULT, "Banlist: ");
 

	
 
	uint i = 1;
 
	for (char *entry : _network_ban_list) {
 
		IConsolePrintF(CC_DEFAULT, "  %d) %s", i, entry);
 
	for (const auto &entry : _network_ban_list) {
 
		IConsolePrintF(CC_DEFAULT, "  %d) %s", i, entry.c_str());
 
	}
 

	
 
	return true;
src/core/smallvec_type.hpp
Show inline comments
 
@@ -99,6 +99,4 @@ public:
 
	}
 
};
 

	
 
typedef AutoFreeSmallVector<char*> StringList; ///< Type for a list of strings.
 

	
 
#endif /* SMALLVEC_TYPE_HPP */
src/game/game_text.cpp
Show inline comments
 
@@ -111,7 +111,7 @@ std::unique_ptr<LanguageStrings> ReadRaw
 
			while (i > 0 && (buffer[i - 1] == '\r' || buffer[i - 1] == '\n' || buffer[i - 1] == ' ')) i--;
 
			buffer[i] = '\0';
 

	
 
			ret->lines.push_back(stredup(buffer, buffer + to_read - 1));
 
			ret->lines.emplace_back(buffer, buffer + to_read - 1);
 

	
 
			if (len > to_read) {
 
				to_read = 0;
 
@@ -129,8 +129,8 @@ std::unique_ptr<LanguageStrings> ReadRaw
 

	
 
/** A reader that simply reads using fopen. */
 
struct StringListReader : StringReader {
 
	const char * const *p;   ///< The current location of the iteration.
 
	const char * const *end; ///< The end of the iteration.
 
	StringList::const_iterator p;   ///< The current location of the iteration.
 
	StringList::const_iterator end; ///< The end of the iteration.
 

	
 
	/**
 
	 * Create the reader.
 
@@ -140,7 +140,7 @@ struct StringListReader : StringReader {
 
	 * @param translation Are we reading a translation?
 
	 */
 
	StringListReader(StringData &data, const LanguageStrings &strings, bool master, bool translation) :
 
			StringReader(data, strings.language, master, translation), p(strings.lines.data()), end(p + strings.lines.size())
 
			StringReader(data, strings.language, master, translation), p(strings.lines.begin()), end(strings.lines.end())
 
	{
 
	}
 

	
 
@@ -148,7 +148,7 @@ struct StringListReader : StringReader {
 
	{
 
		if (this->p == this->end) return NULL;
 

	
 
		strecpy(buffer, *this->p, last);
 
		strecpy(buffer, this->p->c_str(), last);
 
		this->p++;
 

	
 
		return buffer;
 
@@ -157,13 +157,13 @@ struct StringListReader : StringReader {
 

	
 
/** Class for writing an encoded language. */
 
struct TranslationWriter : LanguageWriter {
 
	StringList *strings; ///< The encoded strings.
 
	StringList &strings; ///< The encoded strings.
 

	
 
	/**
 
	 * Writer for the encoded data.
 
	 * @param strings The string table to add the strings to.
 
	 */
 
	TranslationWriter(StringList *strings) : strings(strings)
 
	TranslationWriter(StringList &strings) : strings(strings)
 
	{
 
	}
 

	
 
@@ -184,28 +184,25 @@ struct TranslationWriter : LanguageWrite
 

	
 
	void Write(const byte *buffer, size_t length)
 
	{
 
		char *dest = MallocT<char>(length + 1);
 
		memcpy(dest, buffer, length);
 
		dest[length] = '\0';
 
		this->strings->push_back(dest);
 
		this->strings.emplace_back((const char *)buffer, length);
 
	}
 
};
 

	
 
/** Class for writing the string IDs. */
 
struct StringNameWriter : HeaderWriter {
 
	StringList *strings; ///< The string names.
 
	StringList &strings; ///< The string names.
 

	
 
	/**
 
	 * Writer for the string names.
 
	 * @param strings The string table to add the strings to.
 
	 */
 
	StringNameWriter(StringList *strings) : strings(strings)
 
	StringNameWriter(StringList &strings) : strings(strings)
 
	{
 
	}
 

	
 
	void WriteStringID(const char *name, int stringid)
 
	{
 
		if (stringid == (int)this->strings->size()) this->strings->push_back(stredup(name));
 
		if (stringid == (int)this->strings.size()) this->strings.emplace_back(name);
 
	}
 

	
 
	void Finalise(const StringData &data)
 
@@ -314,7 +311,7 @@ void GameStrings::Compile()
 

	
 
	this->version = data.Version();
 

	
 
	StringNameWriter id_writer(&this->string_names);
 
	StringNameWriter id_writer(this->string_names);
 
	id_writer.WriteHeader(data);
 

	
 
	for (const auto &p : this->raw_strings) {
 
@@ -324,7 +321,7 @@ void GameStrings::Compile()
 
		if (_errors != 0) throw std::exception();
 

	
 
		this->compiled_strings.emplace_back(new LanguageStrings(p->language));
 
		TranslationWriter writer(&this->compiled_strings.back()->lines);
 
		TranslationWriter writer(this->compiled_strings.back()->lines);
 
		writer.WriteLang(data);
 
	}
 
}
 
@@ -340,7 +337,7 @@ GameStrings *_current_data = NULL;
 
const char *GetGameStringPtr(uint id)
 
{
 
	if (id >= _current_data->cur_language->lines.size()) return GetStringPtr(STR_UNDEFINED);
 
	return _current_data->cur_language->lines[id];
 
	return _current_data->cur_language->lines[id].c_str();
 
}
 

	
 
/**
 
@@ -359,8 +356,8 @@ void RegisterGameTranslation(Squirrel *e
 
	if (SQ_FAILED(sq_get(vm, -2))) return;
 

	
 
	int idx = 0;
 
	for (const char * const p : _current_data->string_names) {
 
		sq_pushstring(vm, p, -1);
 
	for (const auto &p : _current_data->string_names) {
 
		sq_pushstring(vm, p.c_str(), -1);
 
		sq_pushinteger(vm, idx);
 
		sq_rawset(vm, -3);
 
		idx++;
src/network/core/address.cpp
Show inline comments
 
@@ -156,7 +156,7 @@ bool NetworkAddress::IsFamily(int family
 
 * @note netmask without /n assumes all bits need to match.
 
 * @return true if this IP is within the netmask.
 
 */
 
bool NetworkAddress::IsInNetmask(char *netmask)
 
bool NetworkAddress::IsInNetmask(const char *netmask)
 
{
 
	/* Resolve it if we didn't do it already */
 
	if (!this->IsResolved()) this->GetAddress();
 
@@ -166,17 +166,16 @@ bool NetworkAddress::IsInNetmask(char *n
 
	NetworkAddress mask_address;
 

	
 
	/* Check for CIDR separator */
 
	char *chr_cidr = strchr(netmask, '/');
 
	const char *chr_cidr = strchr(netmask, '/');
 
	if (chr_cidr != NULL) {
 
		int tmp_cidr = atoi(chr_cidr + 1);
 

	
 
		/* Invalid CIDR, treat as single host */
 
		if (tmp_cidr > 0 || tmp_cidr < cidr) cidr = tmp_cidr;
 

	
 
		/* Remove and then replace the / so that NetworkAddress works on the IP portion */
 
		*chr_cidr = '\0';
 
		mask_address = NetworkAddress(netmask, 0, this->address.ss_family);
 
		*chr_cidr = '/';
 
		/* Remove the / so that NetworkAddress works on the IP portion */
 
		std::string ip_str(netmask, chr_cidr - netmask);
 
		mask_address = NetworkAddress(ip_str.c_str(), 0, this->address.ss_family);
 
	} else {
 
		mask_address = NetworkAddress(netmask, 0, this->address.ss_family);
 
	}
src/network/core/address.h
Show inline comments
 
@@ -129,7 +129,7 @@ public:
 
	}
 

	
 
	bool IsFamily(int family);
 
	bool IsInNetmask(char *netmask);
 
	bool IsInNetmask(const char *netmask);
 

	
 
	/**
 
	 * Compare the address of this class with the address of another.
src/network/core/tcp_listen.h
Show inline comments
 
@@ -54,13 +54,13 @@ public:
 

	
 
			/* Check if the client is banned */
 
			bool banned = false;
 
			for (char *entry : _network_ban_list) {
 
				banned = address.IsInNetmask(entry);
 
			for (const auto &entry : _network_ban_list) {
 
				banned = address.IsInNetmask(entry.c_str());
 
				if (banned) {
 
					Packet p(Tban_packet);
 
					p.PrepareToSend();
 

	
 
					DEBUG(net, 1, "[%s] Banned ip tried to join (%s), refused", Tsocket::GetName(), entry);
 
					DEBUG(net, 1, "[%s] Banned ip tried to join (%s), refused", Tsocket::GetName(), entry.c_str());
 

	
 
					if (send(s, (const char*)p.buffer, p.size, 0) < 0) {
 
						DEBUG(net, 0, "send failed with error %d", GET_LAST_ERROR());
src/network/network.cpp
Show inline comments
 
@@ -632,8 +632,8 @@ void NetworkAddServer(const char *b)
 
 */
 
void GetBindAddresses(NetworkAddressList *addresses, uint16 port)
 
{
 
	for (char *iter : _network_bind_list) {
 
		addresses->emplace_back(iter, port);
 
	for (const auto &iter : _network_bind_list) {
 
		addresses->emplace_back(iter.c_str(), port);
 
	}
 

	
 
	/* No address, so bind to everything. */
 
@@ -647,10 +647,10 @@ void GetBindAddresses(NetworkAddressList
 
 * by the function that generates the config file. */
 
void NetworkRebuildHostList()
 
{
 
	_network_host_list.Clear();
 
	_network_host_list.clear();
 

	
 
	for (NetworkGameList *item = _network_game_list; item != NULL; item = item->next) {
 
		if (item->manually) _network_host_list.push_back(stredup(item->address.GetAddressAsString(false)));
 
		if (item->manually) _network_host_list.emplace_back(item->address.GetAddressAsString(false));
 
	}
 
}
 

	
src/network/network_gui.cpp
Show inline comments
 
@@ -1045,8 +1045,8 @@ void ShowNetworkGameWindow()
 
	if (first) {
 
		first = false;
 
		/* Add all servers from the config file to our list. */
 
		for (char *iter : _network_host_list) {
 
			NetworkAddServer(iter);
 
		for (const auto &iter : _network_host_list) {
 
			NetworkAddServer(iter.c_str());
 
		}
 
	}
 

	
src/network/network_server.cpp
Show inline comments
 
@@ -2083,13 +2083,13 @@ uint NetworkServerKickOrBanIP(const char
 
	/* Add address to ban-list */
 
	if (ban) {
 
		bool contains = false;
 
		for (char *iter : _network_ban_list) {
 
			if (strcmp(iter, ip) == 0) {
 
		for (const auto &iter : _network_ban_list) {
 
			if (iter == ip) {
 
				contains = true;
 
				break;
 
			}
 
		}
 
		if (!contains) _network_ban_list.push_back(stredup(ip));
 
		if (!contains) _network_ban_list.emplace_back(ip);
 
	}
 

	
 
	uint n = 0;
 
@@ -2098,7 +2098,7 @@ uint NetworkServerKickOrBanIP(const char
 
	NetworkClientSocket *cs;
 
	FOR_ALL_CLIENT_SOCKETS(cs) {
 
		if (cs->client_id == CLIENT_ID_SERVER) continue;
 
		if (cs->client_address.IsInNetmask(const_cast<char *>(ip))) {
 
		if (cs->client_address.IsInNetmask(ip)) {
 
			NetworkServerKickClient(cs->client_id);
 
			n++;
 
		}
src/newgrf_gui.cpp
Show inline comments
 
@@ -565,8 +565,6 @@ void ShowNewGRFTextfileWindow(TextfileTy
 
	new NewGRFTextfileWindow(file_type, c);
 
}
 

	
 
static GRFPresetList _grf_preset_list; ///< List of known NewGRF presets. @see GetGRFPresetList
 

	
 
typedef std::map<uint32, const GRFConfig *> GrfIdMap; ///< Map of grfid to the grf config.
 

	
 
/**
 
@@ -605,6 +603,8 @@ struct NewGRFWindow : public Window, New
 
	StringFilter string_filter; ///< Filter for available grf.
 
	QueryString filter_editbox; ///< Filter editbox;
 

	
 
	StringList grf_presets;     ///< List of known NewGRF presets.
 

	
 
	GRFConfig *actives;         ///< Temporary active grf list to which changes are made.
 
	GRFConfig *active_sel;      ///< Selected active grf item.
 

	
 
@@ -632,7 +632,7 @@ struct NewGRFWindow : public Window, New
 
		this->active_over = -1;
 

	
 
		CopyGRFConfigList(&this->actives, *orig_list, false);
 
		GetGRFPresetList(&_grf_preset_list);
 
		this->grf_presets = GetGRFPresetList();
 

	
 
		this->CreateNestedTree();
 
		this->vscroll = this->GetScrollbar(WID_NS_SCROLLBAR);
 
@@ -673,7 +673,6 @@ struct NewGRFWindow : public Window, New
 

	
 
		/* Remove the temporary copy of grf-list used in window */
 
		ClearGRFConfigList(&this->actives);
 
		_grf_preset_list.Clear();
 
	}
 

	
 
	/**
 
@@ -747,11 +746,9 @@ struct NewGRFWindow : public Window, New
 

	
 
			case WID_NS_PRESET_LIST: {
 
				Dimension d = GetStringBoundingBox(STR_NUM_CUSTOM);
 
				for (uint i = 0; i < _grf_preset_list.size(); i++) {
 
					if (_grf_preset_list[i] != NULL) {
 
						SetDParamStr(0, _grf_preset_list[i]);
 
						d = maxdim(d, GetStringBoundingBox(STR_JUST_RAW_STRING));
 
					}
 
				for (const auto &i : this->grf_presets) {
 
					SetDParamStr(0, i.c_str());
 
					d = maxdim(d, GetStringBoundingBox(STR_JUST_RAW_STRING));
 
				}
 
				d.width += padding.width;
 
				*size = maxdim(d, *size);
 
@@ -783,7 +780,7 @@ struct NewGRFWindow : public Window, New
 
					SetDParam(0, STR_NUM_CUSTOM);
 
				} else {
 
					SetDParam(0, STR_JUST_RAW_STRING);
 
					SetDParamStr(1, _grf_preset_list[this->preset]);
 
					SetDParamStr(1, this->grf_presets[this->preset].c_str());
 
				}
 
				break;
 
		}
 
@@ -929,10 +926,8 @@ struct NewGRFWindow : public Window, New
 
				/* Add 'None' option for clearing list */
 
				list.emplace_back(new DropDownListStringItem(STR_NONE, -1, false));
 

	
 
				for (uint i = 0; i < _grf_preset_list.size(); i++) {
 
					if (_grf_preset_list[i] != NULL) {
 
						list.emplace_back(new DropDownListCharStringItem(_grf_preset_list[i], i, false));
 
					}
 
				for (uint i = 0; i < this->grf_presets.size(); i++) {
 
					list.emplace_back(new DropDownListCharStringItem(this->grf_presets[i].c_str(), i, false));
 
				}
 

	
 
				this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
 
@@ -949,14 +944,14 @@ struct NewGRFWindow : public Window, New
 
			}
 

	
 
			case WID_NS_PRESET_SAVE:
 
				ShowSavePresetWindow((this->preset == -1) ? NULL : _grf_preset_list[this->preset]);
 
				ShowSavePresetWindow((this->preset == -1) ? NULL : this->grf_presets[this->preset].c_str());
 
				break;
 

	
 
			case WID_NS_PRESET_DELETE:
 
				if (this->preset == -1) return;
 

	
 
				DeleteGRFPresetFromConfig(_grf_preset_list[this->preset]);
 
				GetGRFPresetList(&_grf_preset_list);
 
				DeleteGRFPresetFromConfig(this->grf_presets[this->preset].c_str());
 
				this->grf_presets = GetGRFPresetList();
 
				this->preset = -1;
 
				this->InvalidateData();
 
				this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
 
@@ -1156,7 +1151,7 @@ struct NewGRFWindow : public Window, New
 
		this->preset = index;
 

	
 
		if (index != -1) {
 
			this->actives = LoadGRFPresetFromConfig(_grf_preset_list[index]);
 
			this->actives = LoadGRFPresetFromConfig(this->grf_presets[index].c_str());
 
		}
 
		this->avails.ForceRebuild();
 

	
 
@@ -1172,11 +1167,11 @@ struct NewGRFWindow : public Window, New
 
		if (str == NULL) return;
 

	
 
		SaveGRFPresetToConfig(str, this->actives);
 
		GetGRFPresetList(&_grf_preset_list);
 
		this->grf_presets = GetGRFPresetList();
 

	
 
		/* Switch to this preset */
 
		for (uint i = 0; i < _grf_preset_list.size(); i++) {
 
			if (_grf_preset_list[i] != NULL && strcmp(_grf_preset_list[i], str) == 0) {
 
		for (uint i = 0; i < this->grf_presets.size(); i++) {
 
			if (this->grf_presets[i] == str) {
 
				this->preset = i;
 
				break;
 
			}
 
@@ -2038,7 +2033,7 @@ static WindowDesc _save_preset_desc(
 
/** Class for the save preset window. */
 
struct SavePresetWindow : public Window {
 
	QueryString presetname_editbox; ///< Edit box of the save preset.
 
	GRFPresetList presets; ///< Available presets.
 
	StringList presets; ///< Available presets.
 
	Scrollbar *vscroll; ///< Pointer to the scrollbar widget.
 
	int selected; ///< Selected entry in the preset list, or \c -1 if none selected.
 

	
 
@@ -2048,11 +2043,11 @@ struct SavePresetWindow : public Window 
 
	 */
 
	SavePresetWindow(const char *initial_text) : Window(&_save_preset_desc), presetname_editbox(32)
 
	{
 
		GetGRFPresetList(&this->presets);
 
		this->presets = GetGRFPresetList();
 
		this->selected = -1;
 
		if (initial_text != NULL) {
 
			for (uint i = 0; i < this->presets.size(); i++) {
 
				if (!strcmp(initial_text, this->presets[i])) {
 
				if (this->presets[i] == initial_text) {
 
					this->selected = i;
 
					break;
 
				}
 
@@ -2083,7 +2078,7 @@ struct SavePresetWindow : public Window 
 
				resize->height = FONT_HEIGHT_NORMAL + 2U;
 
				size->height = 0;
 
				for (uint i = 0; i < this->presets.size(); i++) {
 
					Dimension d = GetStringBoundingBox(this->presets[i]);
 
					Dimension d = GetStringBoundingBox(this->presets[i].c_str());
 
					size->width = max(size->width, d.width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT);
 
					resize->height = max(resize->height, d.height);
 
				}
 
@@ -2108,7 +2103,7 @@ struct SavePresetWindow : public Window 
 
				for (uint i = min_index; i < max_index; i++) {
 
					if ((int)i == this->selected) GfxFillRect(r.left + 1, y, r.right - 1, y + step_height - 2, PC_DARK_BLUE);
 

	
 
					const char *text = this->presets[i];
 
					const char *text = this->presets[i].c_str();
 
					DrawString(r.left + WD_FRAMERECT_LEFT, r.right, y + offset_y, text, ((int)i == this->selected) ? TC_WHITE : TC_SILVER);
 
					y += step_height;
 
				}
 
@@ -2124,7 +2119,7 @@ struct SavePresetWindow : public Window 
 
				uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SVP_PRESET_LIST);
 
				if (row < this->presets.size()) {
 
					this->selected = row;
 
					this->presetname_editbox.text.Assign(this->presets[row]);
 
					this->presetname_editbox.text.Assign(this->presets[row].c_str());
 
					this->SetWidgetDirty(WID_SVP_PRESET_LIST);
 
					this->SetWidgetDirty(WID_SVP_EDITBOX);
 
				}
src/openttd.cpp
Show inline comments
 
@@ -445,8 +445,8 @@ struct AfterNewGRFScan : NewGRFScanCallb
 
		if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed;
 

	
 
		if (dedicated_host != NULL) {
 
			_network_bind_list.Clear();
 
			_network_bind_list.push_back(stredup(dedicated_host));
 
			_network_bind_list.clear();
 
			_network_bind_list.emplace_back(dedicated_host);
 
		}
 
		if (dedicated_port != 0) _settings_client.network.server_port = dedicated_port;
 

	
src/saveload/game_sl.cpp
Show inline comments
 
@@ -129,14 +129,14 @@ static const SaveLoad _game_language_str
 
	 SLE_END()
 
};
 

	
 
static void SaveReal_GSTR(LanguageStrings *ls)
 
static void SaveReal_GSTR(const LanguageStrings *ls)
 
{
 
	_game_saveload_string  = ls->language;
 
	_game_saveload_strings = (uint)ls->lines.size();
 

	
 
	SlObject(NULL, _game_language_header);
 
	for (uint i = 0; i < _game_saveload_strings; i++) {
 
		_game_saveload_string = ls->lines[i];
 
	for (const auto &i : ls->lines) {
 
		_game_saveload_string = i.c_str();
 
		SlObject(NULL, _game_language_string);
 
	}
 
}
 
@@ -153,7 +153,7 @@ static void Load_GSTR()
 
		std::unique_ptr<LanguageStrings> ls(new LanguageStrings(_game_saveload_string != NULL ? _game_saveload_string : ""));
 
		for (uint i = 0; i < _game_saveload_strings; i++) {
 
			SlObject(NULL, _game_language_string);
 
			ls->lines.push_back(stredup(_game_saveload_string != NULL ? _game_saveload_string : ""));
 
			ls->lines.emplace_back(_game_saveload_string != NULL ? _game_saveload_string : "");
 
		}
 

	
 
		_current_data->raw_strings.push_back(std::move(ls));
src/settings.cpp
Show inline comments
 
@@ -84,7 +84,7 @@ static ErrorList _settings_error_list; /
 

	
 

	
 
typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const char *grpname, void *object);
 
typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList *list);
 
typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList &list);
 

	
 
static bool IsSignedVarMemType(VarType vt);
 

	
 
@@ -718,16 +718,16 @@ static void IniSaveSettings(IniFile *ini
 
 * @param grpname character string identifying the section-header of the ini file that will be parsed
 
 * @param list new list with entries of the given section
 
 */
 
static void IniLoadSettingList(IniFile *ini, const char *grpname, StringList *list)
 
static void IniLoadSettingList(IniFile *ini, const char *grpname, StringList &list)
 
{
 
	IniGroup *group = ini->GetGroup(grpname);
 

	
 
	if (group == NULL || list == NULL) return;
 
	if (group == NULL) return;
 

	
 
	list->Clear();
 
	list.clear();
 

	
 
	for (const IniItem *item = group->item; item != NULL; item = item->next) {
 
		if (item->name != NULL) list->push_back(stredup(item->name));
 
		if (item->name != NULL) list.emplace_back(item->name);
 
	}
 
}
 

	
 
@@ -740,15 +740,15 @@ static void IniLoadSettingList(IniFile *
 
 * @param list pointer to an string(pointer) array that will be used as the
 
 *             source to be saved into the relevant ini section
 
 */
 
static void IniSaveSettingList(IniFile *ini, const char *grpname, StringList *list)
 
static void IniSaveSettingList(IniFile *ini, const char *grpname, StringList &list)
 
{
 
	IniGroup *group = ini->GetGroup(grpname);
 

	
 
	if (group == NULL || list == NULL) return;
 
	if (group == NULL) return;
 
	group->Clear();
 

	
 
	for (char *iter : *list) {
 
		group->GetItem(iter, true)->SetValue("");
 
	for (const auto &iter : list) {
 
		group->GetItem(iter.c_str(), true)->SetValue("");
 
	}
 
}
 

	
 
@@ -1699,9 +1699,9 @@ static void HandleSettingDescs(IniFile *
 
		proc(ini, _currency_settings,"currency", &_custom_currency);
 
		proc(ini, _company_settings, "company",  &_settings_client.company);
 

	
 
		proc_list(ini, "server_bind_addresses", &_network_bind_list);
 
		proc_list(ini, "servers", &_network_host_list);
 
		proc_list(ini, "bans",    &_network_ban_list);
 
		proc_list(ini, "server_bind_addresses", _network_bind_list);
 
		proc_list(ini, "servers", _network_host_list);
 
		proc_list(ini, "bans",    _network_ban_list);
 
	}
 
}
 

	
 
@@ -1767,21 +1767,20 @@ void SaveToConfig()
 

	
 
/**
 
 * Get the list of known NewGrf presets.
 
 * @param[in,out] list Pointer to list for storing the preset names.
 
 * @returns List of preset names.
 
 */
 
void GetGRFPresetList(GRFPresetList *list)
 
StringList GetGRFPresetList()
 
{
 
	list->Clear();
 
	StringList list;
 

	
 
	IniFile *ini = IniLoadConfig();
 
	IniGroup *group;
 
	for (group = ini->group; group != NULL; group = group->next) {
 
	std::unique_ptr<IniFile> ini(IniLoadConfig());
 
	for (IniGroup *group = ini->group; group != NULL; group = group->next) {
 
		if (strncmp(group->name, "preset-", 7) == 0) {
 
			list->push_back(stredup(group->name + 7));
 
			list.emplace_back(group->name + 7);
 
		}
 
	}
 

	
 
	delete ini;
 
	return list;
 
}
 

	
 
/**
src/settings_func.h
Show inline comments
 
@@ -14,6 +14,7 @@
 

	
 
#include "core/smallvec_type.hpp"
 
#include "company_type.h"
 
#include "string_type.h"
 

	
 
struct IniFile;
 

	
 
@@ -28,11 +29,7 @@ void SaveToConfig();
 
void IniLoadWindowSettings(IniFile *ini, const char *grpname, void *desc);
 
void IniSaveWindowSettings(IniFile *ini, const char *grpname, void *desc);
 

	
 
/* Functions to load and save NewGRF settings to a separate
 
 * configuration file, used for presets. */
 
typedef AutoFreeSmallVector<char *> GRFPresetList;
 

	
 
void GetGRFPresetList(GRFPresetList *list);
 
StringList GetGRFPresetList();
 
struct GRFConfig *LoadGRFPresetFromConfig(const char *config_name);
 
void SaveGRFPresetToConfig(const char *config_name, struct GRFConfig *config);
 
void DeleteGRFPresetFromConfig(const char *config_name);
src/string_type.h
Show inline comments
 
@@ -13,6 +13,8 @@
 
#define STRING_TYPE_H
 

	
 
#include "core/enum_type.hpp"
 
#include <vector>
 
#include <string>
 

	
 
/** A non-breaking space. */
 
#define NBSP "\xC2\xA0"
 
@@ -53,4 +55,8 @@ enum StringValidationSettings {
 
};
 
DECLARE_ENUM_AS_BIT_SET(StringValidationSettings)
 

	
 

	
 
/** Type for a list of strings. */
 
typedef std::vector<std::string> StringList;
 

	
 
#endif /* STRING_TYPE_H */
0 comments (0 inline, 0 general)