本文整理汇总了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;
}
示例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;
}