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;
}
Ejemplo n.º 3
0
Archivo: count.cpp Proyecto: drio/egrl
void dump_results(google::dense_hash_map<std::string, Probe*> &h_probes)
{
  int cs1[5], cs2[5];
  Probe *op; // Original probe

  google::dense_hash_map<std::string, Probe *>::iterator p_iter;
  for (p_iter=h_probes.begin(); p_iter!=h_probes.end(); p_iter++) {
    // In op we want always the original probe, not the rc one
    op = p_iter->second->is_a_rc_probe ? p_iter->second->rc : p_iter->second;
    if (!op->visited && (op->has_hits() || op->rc->has_hits())) {
      op->get_counters(cs1);
      op->rc->get_counters(cs2);
      std::cout
        << op->get_chrm() << ","
        << op->get_coordinates() <<  ","
        << op->get_id() <<  ","
        << op->get_ref() <<  ","
        << op->get_var() <<  ","

        << cs1[0] << ","
        << cs1[1] << ","
        << cs1[2] << ","
        << cs1[3] << ","
        << cs1[4] << ","

        << cs2[0] << ","
        << cs2[1] << ","
        << cs2[2] << ","
        << cs2[3] << ","
        << cs2[4] << ","

        << cs1[0] + cs2[0] << ","
        << cs1[1] + cs2[1] << ","
        << cs1[2] + cs2[2] << ","
        << cs1[3] + cs2[3] << ","
        << cs1[4] + cs2[4]

        << std::endl;

      op->visited = 1;
      op->rc->visited = 1;
    }
  }
}
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;
}
Ejemplo n.º 5
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]));
     }
 }
Ejemplo n.º 6
0
 void assertThatHashMapHasKeys(std::vector<char*> elements) {
     for (int i = 0; i < elements.size(); ++i) {
        ASSERT_FALSE(hashMap.find(elements[i]) == hashMap.end());
     }
 }