本文整理汇总了C++中ConfigNode::add方法的典型用法代码示例。如果您正苦于以下问题:C++ ConfigNode::add方法的具体用法?C++ ConfigNode::add怎么用?C++ ConfigNode::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigNode
的用法示例。
在下文中一共展示了ConfigNode::add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse
bool ConfigParser::parse(const std::string& file, ConfigNode* ptr)
{
ConfigScanner scanner;
ConfigLexer lexer;
ConfigNode* root = ptr;
if (!scanner.read(file))
{
std::cerr << "Couldn't find config file: " << file << "\n";
return false;
}
lexer.setScanner(&scanner);
int token_type;
std::string token_data;
std::string token_label;
std::deque<ConfigNode*> nodeStack;
ConfigNode* currentNode = root;
nodeStack.push_back(currentNode);
while (lexer.get_token(&token_type, &token_data))
{
if (!token_type)
{
std::cerr << "Unrecognised data!\n";
return false;
}
// Include other files only if we're in the root node
if ((token_type == CONFIG_TOKEN_ENTITY) && (token_data == "include") && (currentNode == root))
{
int tmp_type;
std::string tmp_data;
lexer.get_token(&tmp_type, &tmp_data);
if (tmp_type == CONFIG_TOKEN_STRING)
{
if (tmp_data == file)
{
std::cerr << "Warning: recursion detected! Not including `" << tmp_data << "`.\n";
continue;
}
if (!parse(tmp_data, root))
{
return false;
}
continue;
}
else
{
lexer.put_token(tmp_type, tmp_data);
}
}
if ((token_type == CONFIG_TOKEN_ENTITY) || (token_type == CONFIG_TOKEN_LABEL))
{
token_label.assign(token_data);
}
if (token_type == CONFIG_TOKEN_OPERATOR_ASSIGN)
{
if (currentNode != root)
{
currentNode->clear();
}
}
if (token_type == CONFIG_TOKEN_BOOLEAN)
{
ConfigNode* newNode = (token_label.size() && currentNode->has(token_label)) ? currentNode->get(token_label) : new ConfigNode;
newNode->setData(token_data == "true");
if (token_label.size())
{
currentNode->set(token_label, newNode, true);
token_label.clear();
}
else
{
currentNode->add(newNode);
}
}
if (token_type == CONFIG_TOKEN_STRING)
{
ConfigNode* newNode = (token_label.size() && currentNode->has(token_label)) ? currentNode->get(token_label) : new ConfigNode;
newNode->setData(token_data);
if (token_label.size())
{
currentNode->set(token_label, newNode, true);
token_label.clear();
}
else
{
currentNode->add(newNode);
//.........这里部分代码省略.........