コード例 #1
0
ファイル: XmlParse.cpp プロジェクト: zhaoruoxu/lyraefx
 bool XmlParseConfig(Config &c, TiXmlElement *conf)
 {
     if ( conf == NULL ) return false;
     stringstream ss;
     TiXmlElement *config = conf->FirstChildElement();
     for ( ; config; config = config->NextSiblingElement() ) {
         if ( config->Type() != TiXmlNode::TINYXML_ELEMENT ) continue;
         string configType(config->Value());
         const char *name = config->Attribute("Name");
         if ( !name ) {
             Severe("Config Name attribute missing");
             return false;
         }
         string configName(name);
         if ( configType == "Float" ) {
             double value;
             if ( !config->Attribute("Value", &value) ) {
                 ss << "Config [" << configName << "] missing value";
                 Severe(ss);
                 return false;
             }
             c.AddAttribute(configName, (float) value);
         } else if ( configType == "Int32" ) {
             int i;
             if ( !config->Attribute("Value", &i) ) {
                 ss << "Config [" << configName << "] missing value";
                 Severe(ss);
                 return false;
             }
             c.AddAttribute(configName, i);
         } else if ( configType == "Vector" ) {
             Vector vec;
             TiXmlElement *elemVec = config->FirstChildElement("Value");
             if ( !elemVec ) {
                 ss << "Config [" << configName << "] missing value";
                 Severe(ss);
                 return false;
             }
             if ( !XmlParseVector(vec, elemVec) ) return false;
             c.AddAttribute(configName, vec);
         } else if ( configType == "Bool" ) {
             int b;
             if ( !config->Attribute("Value", &b) ) {
                 ss << "Config [" << configName << "] missing value";
                 Severe(ss);
                 return false;
             }
             c.AddAttribute(configName, b != 0);
         } else {
             ss << "Unknown config type: [" << configType << "]";
             Severe(ss);
             return false;
         }
     }
     return true;
 }