当前位置: 首页>>代码示例>>C++>>正文


C++ Category::GetSubcategory方法代码示例

本文整理汇总了C++中Category::GetSubcategory方法的典型用法代码示例。如果您正苦于以下问题:C++ Category::GetSubcategory方法的具体用法?C++ Category::GetSubcategory怎么用?C++ Category::GetSubcategory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Category的用法示例。


在下文中一共展示了Category::GetSubcategory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Delete

bool LocalStore::Delete(const char* identifier)
{
	if (identifier == NULL)
	{
		return false;
	}

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

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

	//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);
		}
		//Otherwise we've reached the value.
		else
		{
			//Iterate through and delete
			List<Entry*>& entries = category->GetEntries();
			List<Entry*>::Node* n = entries.Begin();
			while (n != NULL)
			{
				if (n->GetValue()->GetName() == token)
				{
					delete n->GetValue();
					entries.Erase(n);

					delete[] identifierCopy;

					return true;
				}

				n = n->GetNext();
			}
		}

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

	delete[] identifierCopy;

	return false;
}
开发者ID:DarthCoder117,项目名称:RRDTP,代码行数:57,代码来源:LocalStore.cpp

示例2: Get

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;
}
开发者ID:DarthCoder117,项目名称:RRDTP,代码行数:46,代码来源:LocalStore.cpp


注:本文中的Category::GetSubcategory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。