void Material::setParameter(const std::string & name,const std::vector<std::string> & value) { ConfigNode * child = root->findChild(name,false); if(child == NULL) { child = new ConfigNode(root,name); } child->clearValues(); std::vector<std::string>::const_iterator it = value.begin(); while(it != value.end()) { child->addValue(*it); it++; } }
void ConfigLoader::_parseNodes(std::ifstream &stream, ConfigNode *parent) { typedef std::pair<std::string, ConfigNode*> ScriptItem; while (true) { switch (tok) { //Node case TOKEN_Text: //Add the new node ConfigNode *newNode; if (parent) { newNode = parent->addChild(tokVal); } else { newNode = new ConfigNode(0, tokVal); } //Get values _nextToken(stream); while (tok == TOKEN_Text) { newNode->addValue(tokVal); _nextToken(stream); } //Add root nodes to scriptList if (!parent){ std::string key; if (newNode->getValues().empty()) { key = newNode->getName() + ' '; } else { key = newNode->getName() + ' ' + newNode->getValues().front(); } m_scriptList.insert(ScriptItem(key, newNode)); } _skipNewLines(stream); //Add any sub-nodes if (tok == TOKEN_OpenBrace) { //Parse nodes _nextToken(stream); _parseNodes(stream, newNode); //Check for matching closing brace if (tok != TOKEN_CloseBrace) { throw std::runtime_error("Parse Error: Expecting closing brace"); } _nextToken(stream); _skipNewLines(stream); } break; //Out of place brace case TOKEN_OpenBrace: throw std::runtime_error("Parse Error: Opening brace out of plane"); break; //Return if end of nodes have been reached case TOKEN_CloseBrace: return; //Return if reached end of file case TOKEN_EOF: return; case TOKEN_NewLine: _nextToken(stream); break; } }; }