int SL_GetStringOfSize(const char* string, int system, int size)
{
	EnterCriticalSection(&slCritSec);

	// try to find the string first
	std::string str(string, size);
	google::dense_hash_map<std::string, uint16_t>::const_iterator iter = slHashMap.find(str);

	if (iter != slHashMap.end())
	{
		SL_Debug("GetStringOfSize '%s' found %i\n", string, iter->second);

		SL_AddRefToString(iter->second);

		LeaveCriticalSection(&slCritSec);
		return iter->second;
	}

	// add the string to the list
	ScriptStringData* data = &slStrings[slFirstFree];
	uint16_t stringID = slFirstFree;

	//data->data = new ScriptStringManagementData;
	data->data = (ScriptStringManagementData*)HeapAlloc(stringHeap, 0, sizeof(ScriptStringManagementData));
	//data->string = (char*)malloc(size);
	data->string = (char*)HeapAlloc(stringHeap, 0, size);
	memcpy(data->string, string, size);

	data->length = size;

	data->data->data = data;
	data->data->references = 1;
	data->data->users = system;

	// find the next free string
	for (int i = slFirstFree; i < MAX_SCRIPT_STRINGS; i++)
	{
		if (!slStrings[i].string)
		{
			slFirstFree = i;
			break;
		}
	}

	slHashMap[str] = stringID;

	LeaveCriticalSection(&slCritSec);

	SL_Debug("GetStringOfSize '%s' allocated %i (user %i)\n", string, stringID, system);

	return stringID;
}
const char* SEH_GetLocalizedString(const char* key)
{
	google::dense_hash_map<std::string, std::string>::const_iterator iter = _localizedStrings.find(key);
 
	if (iter != _localizedStrings.end())
	{
		return (*iter).second.c_str();
	}
 
	localizedEntry_s* entry = (localizedEntry_s*)DB_FindXAssetHeader(ASSET_TYPE_LOCALIZE, key);
 
	if (entry)
	{
		return entry->value;
	}
	
	return NULL;
}
int FindStringOfSize(const char* string, int size)
{
	EnterCriticalSection(&slCritSec);

	std::string str(string, size);

	google::dense_hash_map<std::string, uint16_t>::const_iterator iter = slHashMap.find(str);

	if (iter != slHashMap.end())
	{
		LeaveCriticalSection(&slCritSec);

		SL_Debug("FindStringOfSize '%s' found %i\n", string, iter->second);

		return iter->second;
	}

	SL_Debug("FindStringOfSize '%s' - no results!\n", string, iter->second);

	LeaveCriticalSection(&slCritSec);

	return 0;
}
예제 #4
0
 void assertThatHashMapHasCorrectValues(std::vector<char*> elements) {
     for (int i = 0; i < elements.size(); i += 2) {
         ASSERT_FALSE(hashMap.find(elements[i]) == hashMap.end());
         ASSERT_EQ(hashMap[elements[i]], atoi(elements[i + 1]));
     }
 }
예제 #5
0
 void assertThatHashMapHasKeys(std::vector<char*> elements) {
     for (int i = 0; i < elements.size(); ++i) {
        ASSERT_FALSE(hashMap.find(elements[i]) == hashMap.end());
     }
 }