Changeset - r16240:4f0e181f881c
[Not reviewed]
master
0 5 0
frosch - 14 years ago 2010-10-16 20:34:43
frosch@openttd.org
(svn r20951) -Codechange: Add SmallMap::Contains() and use it.
5 files changed with 16 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_gui.cpp
Show inline comments
 
@@ -318,7 +318,7 @@ struct AISettingsWindow : public Window 
 
				SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
 
			} else {
 
				DrawArrowButtons(buttons_left, y + 2, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > (*it).min_value, editable && current_value < (*it).max_value);
 
				if (it->labels != NULL && it->labels->Find(current_value) != it->labels->End()) {
 
				if (it->labels != NULL && it->labels->Contains(current_value)) {
 
					SetDParam(idx++, STR_JUST_RAW_STRING);
 
					SetDParamStr(idx++, it->labels->Find(current_value)->second);
 
				} else {
src/ai/ai_info.cpp
Show inline comments
 
@@ -307,7 +307,8 @@ SQInteger AIInfo::AddLabels(HSQUIRRELVM 
 
		int key = atoi(key_string + 1);
 
		const char *label = SQ2OTTD(sq_label);
 

	
 
		if (config->labels->Find(key) == config->labels->End()) config->labels->Insert(key, strdup(label));
 
		/* !Contains() prevents strdup from leaking. */
 
		if (!config->labels->Contains(key)) config->labels->Insert(key, strdup(label));
 

	
 
		sq_pop(vm, 2);
 
	}
src/core/smallmap_type.hpp
Show inline comments
 
@@ -55,6 +55,16 @@ struct SmallMap : SmallVector<SmallPair<
 
	}
 

	
 
	/**
 
	 * Tests whether a key is assigned in this map.
 
	 * @param key key to test
 
	 * @return true iff the item is present
 
	 */
 
	FORCEINLINE bool Contains(const T &key)
 
	{
 
		return this->Find(key) != this->End();
 
	}
 

	
 
	/**
 
	 * Removes given pair from this map
 
	 * @param pair pair to remove
 
	 * @note it has to be pointer to pair in this map. It is overwritten by the last item.
 
@@ -90,7 +100,7 @@ struct SmallMap : SmallVector<SmallPair<
 
	 */
 
	FORCEINLINE bool Insert(const T &key, const U &data)
 
	{
 
		if (this->Find(key) != this->End()) return false;
 
		if (this->Contains(key)) return false;
 
		Pair *n = this->Append();
 
		n->first = key;
 
		n->second = data;
src/network/core/address.cpp
Show inline comments
 
@@ -212,7 +212,7 @@ SOCKET NetworkAddress::Resolve(int famil
 
		 * ofcourse totally unneeded ;) */
 
		if (sockets != NULL) {
 
			NetworkAddress address(runp->ai_addr, (int)runp->ai_addrlen);
 
			if (sockets->Find(address) != sockets->End()) continue;
 
			if (sockets->Contains(address)) continue;
 
		}
 
		sock = func(runp);
 
		if (sock == INVALID_SOCKET) continue;
src/newgrf_gui.cpp
Show inline comments
 
@@ -258,7 +258,7 @@ struct NewGRFParametersWindow : public W
 
				DrawArrowButtons(buttons_left, y + 2, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, current_value > par_info->min_value, current_value < par_info->max_value);
 
				SetDParam(2, STR_JUST_INT);
 
				SetDParam(3, current_value);
 
				if (par_info->value_names.Find(current_value) != par_info->value_names.End()) {
 
				if (par_info->value_names.Contains(current_value)) {
 
					const char *label = GetGRFStringFromGRFText(par_info->value_names.Find(current_value)->second);
 
					if (label != NULL) {
 
						SetDParam(2, STR_JUST_RAW_STRING);
0 comments (0 inline, 0 general)