Beispiel #1
0
Entry* LocalStore::Get(const char* identifier)
{
	if (identifier == NULL)
	{
		return NULL;
	}

	Category* category = &m_rootCategory;
	Entry* entry = NULL;

	int identifierLen = strlen(identifier);
	char* identifierCopy = new char[identifierLen+1];
	memcpy(identifierCopy, identifier, identifierLen);
	identifierCopy[identifierLen] = NULL;

	//Loop over tokens
	char* nextToken = NULL;
	char* token = strtok(identifierCopy, ".");
	while (token != NULL)
	{
		//The next token is retrieved first so that we know which one is the last one.
		nextToken = strtok(NULL, ".");

		//If we haven't reached the last token, then the current one is a category.
		if (nextToken != NULL)
		{
			category = category->GetSubcategory(token);
			if (!category)
			{
				return NULL;
			}
		}
		//Otherwise we've reached the value.
		else
		{
			entry = category->GetEntryByName(token);
		}

		//Next token becomes current token for next loop iteration.
		token = nextToken;
	}

	delete[] identifierCopy;

	return entry;
}