Exemplo n.º 1
0
int File::GetInt(const char *key, int defaultValue)
{
	CAT_DEBUG_ENFORCE(key);

	// Add this path to the hash table
	SanitizedKey san_key(key);
	KeyAdapter key_input(san_key);
	LineItem *item = _table.Lookup(key_input);
	if (item) return item->GetValueInt();

	// If default value is not undefined,
#if !defined(CAT_RAGDOLL_STORE_EMPTY)
	if (defaultValue != 0)
#endif
	{
		// Create a new item for this key
		item = _table.Create(key_input);
		if (item)
		{
			// Push onto the new list
			CAT_FSLL_PUSH_FRONT(_newest, item, _sort_next);
			item->_enlisted = true;

			SanitizeKeyStringCase(key, item->CaseKey());

			item->SetValueInt(defaultValue);
		}
	}

	return defaultValue;
}
Exemplo n.º 2
0
void File::SetInt(const char *key, int value, RWLock *lock)
{
	CAT_DEBUG_ENFORCE(key && lock);

	lock->WriteLock();

	// Add this path to the hash table
	SanitizedKey san_key(key);
	KeyAdapter key_input(san_key);
	LineItem *item = _table.Lookup(key_input);
	if (!item)
	{
#if !defined(CAT_RAGDOLL_STORE_EMPTY)
		if (value != 0)
#endif
		{
			// Create a new item for this key
			item = _table.Create(key_input);
			if (item)
			{
				// Push onto the new list
				CAT_FSLL_PUSH_FRONT(_newest, item, _sort_next);
				item->_enlisted = true;

				SanitizeKeyStringCase(key, item->CaseKey());

				item->SetValueInt(value);
			}
		}
	}
	else
	{
		// If item is not listed yet,
		if (!item->_enlisted)
		{
			CAT_FSLL_PUSH_FRONT(_modded, item, _sort_next);
			item->_enlisted = true;
		}

		item->SetValueInt(value);
	}

	lock->WriteUnlock();
}
Exemplo n.º 3
0
void File::Get(const char *key, const char *defaultValue, std::string &out_value, RWLock *lock)
{
	CAT_DEBUG_ENFORCE(key && lock && defaultValue);

	lock->ReadLock();

	// Add this path to the hash table
	SanitizedKey san_key(key);
	KeyAdapter key_input(san_key);
	LineItem *item = _table.Lookup(key_input);
	if (item)
	{
		out_value = item->GetValueStr();
		lock->ReadUnlock();
		return;
	}

	lock->ReadUnlock();

	// If default value is not undefined,
#if !defined(CAT_RAGDOLL_STORE_EMPTY)
	if (defaultValue[0] != '\0')
#endif
	{
		lock->WriteLock();

		// Create a new item for this key
		item = _table.Create(key_input);
		if (item)
		{
			// Push onto the new list
			CAT_FSLL_PUSH_FRONT(_newest, item, _sort_next);
			item->_enlisted = true;

			SanitizeKeyStringCase(key, item->CaseKey());

			item->SetValueStr(defaultValue);
		}

		lock->WriteUnlock();
	}

	out_value = defaultValue;
}