コード例 #1
0
XMLParserHelper*
XMLIndata::createXMLParserHelper(const set<const char*>& xmlFiles)               
{
   XMLParserHelper::domStringSet_t toSortByOrder;
   XMLParserHelper::domStringSet_t toSortByTag;
   toSortByTag.insert( m_createOverviewXStr->XMLStr() );
   toSortByTag.insert( m_addRegionXStr->XMLStr() );
   toSortByTag.insert( m_regionIDsXStr->XMLStr() );
   toSortByTag.insert( m_mapSupCovXStr->XMLStr() );
   toSortByTag.insert( m_mapSupNameXStr->XMLStr() );
   
   XStr topTag( "map_generation-mc2" );
   XMLParserHelper* helpParser =
      new XMLParserHelper( topTag.XMLStr(), toSortByOrder, toSortByTag );

   if ( ! helpParser->load( xmlFiles ) ) {
      mc2log << warn 
             << "XMLIndata::processXMLData Failed loading xmlFiles. "
             << "xmlFiles.size() == " << xmlFiles.size()
             << endl;
      // Print the file names
      set<const char*>::const_iterator it = xmlFiles.begin();
      for (uint32 i=0; it != xmlFiles.end(); ++it, ++i ){
         mc2dbg << "File: " << i << " " << *it << endl;
      }
      mc2log << error << "XMLIndata::processXMLData Failed loading xmlFiles"
             << endl;
      mc2dbg << "See details from the XML parser above the file list above"
             << endl;
         
      delete helpParser;
      return NULL;
   }
   
   return helpParser;
} // createXMLParserHelper
コード例 #2
0
ファイル: wyBox2DPELoader.cpp プロジェクト: Adoni/WiEngine
void wyBox2DPELoader::characters(void* ctx, const xmlChar *ch, int len) {
    wyBox2DPELoader* thiz = (wyBox2DPELoader*)ctx;
	wyParseState* state = (wyParseState*)thiz->m_parseState;
    
	// check tag
	switch(topTag(state)) {
		case TAG_KEY:
		{
            char* key = (char*)wyCalloc(len + 1, sizeof(char));
			strncpy(key, (const char*)ch, len);
			wyUtils::trim(key);

			// save the last key
			if(state->lastKey != NULL) {
				wyFree((void*)state->lastKey);
			}
			state->lastKey = key;
			break;
		}
		case TAG_INTEGER:
		{ 
            char* temp = (char*)wyCalloc(len + 1, sizeof(char));
			strncpy(temp, (const char*)ch, len);
			wyUtils::trim(temp);
            int value = atoi(temp);
            
			switch(state->state) {
				case State_parsingMetadata:
				{
					if(0 == strcmp(state->lastKey, "format")) 
						thiz->m_plistFormat = value;

                    break;
				}
                case State_parsingFixture:
                {
					if(0 ==strcmp(state->lastKey, "filter_categoryBits"))
						state->fixtureDef->filter.categoryBits = value;
					else if(0 ==strcmp(state->lastKey, "filter_groupIndex"))
					    state->fixtureDef->filter.groupIndex = value;
                    else if(0 ==strcmp(state->lastKey, "filter_maskBits"))
                        state->fixtureDef->filter.maskBits = value;
                    
                    break;
                }
			}
            wyFree(temp);
			break;
		}
		case TAG_STRING:
		{   
            char* temp = (char*)wyCalloc(len + 1, sizeof(char));
			strncpy(temp, (const char*)ch, len);
			wyUtils::trim(temp);
            
			switch(state->state) {
				case State_parsingBody:
				{
					if( 0 == strcmp(state->lastKey, "anchorpoint") ) {
                        state->bodyMeta->m_anchorPoint = thiz->parsePoint(temp, false);
					}
					break;
				}
                case State_parsingShape:
				{
                    wyPoint p = thiz->parsePoint(temp);
					state->vertices[state->vertexIndex++].Set(p.x / thiz->m_PTMRatio, p.y / thiz->m_PTMRatio);
					break;
				}
                case State_parsingFixture:
				{
					if( 0 == strcmp(state->lastKey, "fixture_type") ) {
						if(0 == strcmp(temp, "POLYGON")) {
                            state->fixture_type = e_polygon;
                        } else if(0 == strcmp(temp, "CIRCLE")) {
                            state->fixture_type = e_circle;
                        } else {
                            LOGE("unknown fixture_type %s", temp);
                        }
					}
					break;
				}
                case State_parsingCircle:
                {
                    if(0 == strcmp(state->lastKey, "position"))
						state->position = thiz->parsePoint(temp);
                    break;
                }
                default:
                    break;    
			}
            wyFree(temp);
            break;
		}

        case TAG_REAL: {
            char* temp = (char*)wyCalloc(len + 1, sizeof(char));
			strncpy(temp, (const char*)ch, len);
			wyUtils::trim(temp); 
            float value = atof(temp);

			switch(state->state) {
				case State_parsingMetadata:
				{
					if(0 == strcmp(state->lastKey, "ptm_ratio")) { 
						thiz->m_PTMRatio= value;
                    }
                    break;
				}
                case State_parsingFixture:
                {
					if(0 ==strcmp(state->lastKey, "friction"))
						state->fixtureDef->friction = value;
					else if(0 ==strcmp(state->lastKey, "restitution"))
					    state->fixtureDef->restitution = value;
                    else if(0 ==strcmp(state->lastKey, "density"))
                        state->fixtureDef->density = value;
                    
                    break;
                }
                case State_parsingCircle:
                {
                    if(0 ==strcmp(state->lastKey, "radius"))
						state->radius = (value * thiz->m_resScale) / thiz->m_PTMRatio;
                    break;
                }
                default:
                    break;
			}
            
            wyFree(temp);
            break;
        }
        
        default:
            break;
	}

    
}
コード例 #3
0
ファイル: wyBox2DPELoader.cpp プロジェクト: Adoni/WiEngine
void wyBox2DPELoader::endElement(void* ctx, const xmlChar *name) {
	wyBox2DPELoader* thiz = (wyBox2DPELoader*)ctx;
	wyParseState* state = (wyParseState*)thiz->m_parseState;

	switch(topTag(state)) {
		case TAG_DICT:
			if(state->lastKey == NULL)
				break;

			switch(state->state) {
				case State_ready:
                    state->state = State_finish;
					break;

                case State_parsingMetadata:
                case State_parsingBodies:
					state->state = State_ready;
					break;

                case State_parsingBody:
					state->state = State_parsingBodies;
					break;

                case State_parsingFixture:
					state->state = State_parsingFixtures;
                    break;
                
                case State_parsingCircle:
                    thiz->createFixturesInfo();
                    state->state = State_parsingFixture;
                    break;
                    
                default:
                    break;
			}
			break;

        case TAG_ARRAY:
            switch(state->state) {
				case State_parsingFixtures:
                    state->state = State_parsingBody;                        
					break;
                    
				case State_parsingShapes:
                    state->state = State_parsingFixture;
					break;
                    
				case State_parsingShape:
                    thiz->createFixturesInfo(); 
                    state->state = State_parsingShapes;
					break;
                default:
                    break;
			}

            break;
            
		case TAG_TRUE:
		case TAG_FALSE:

			break;
	}

	popTag(state);
}
コード例 #4
0
ファイル: wyBox2DPELoader.cpp プロジェクト: Adoni/WiEngine
void wyBox2DPELoader::startElement(void* ctx, const xmlChar *name, const xmlChar **atts) {
	wyBox2DPELoader* thiz = (wyBox2DPELoader*)ctx;
	wyParseState* state = (wyParseState*)thiz->m_parseState;
    wyHashSet* hashSet = thiz->m_bodyMetas;
    
	// set tag
	pushTag(state, getPListTag((const char*)name));

	switch(topTag(state)) {
		case TAG_DICT:
			if(state->lastKey == NULL)
				break;

			switch(state->state) {
				case State_ready:
                {
					if(0 == strcmp(state->lastKey, "metadata"))
						state->state = State_parsingMetadata;
					else if(0 == strcmp(state->lastKey, "bodies"))
						state->state = State_parsingBodies;
					break;
                }
                case State_parsingBodies:
                {
                    wyB2BodyMeta* bodyMeta = WYNEW wyB2BodyMeta(state->lastKey);
                    wyHashSetInsert(hashSet, wyUtils::strHash(state->lastKey), bodyMeta, NULL);

                    state->bodyMeta = bodyMeta;
                    state->state = State_parsingBody;
					break;
                }
                case State_parsingFixtures:
                {
					state->state = State_parsingFixture;
                    break;
                }
                case State_parsingFixture:
                {
                    if(0 == strcmp(state->lastKey, "circle")) {
                        state->state = State_parsingCircle;
                    }
                }
                default:
                    break;
			}
			break;

        case TAG_ARRAY:
            switch(state->state) {
				case State_parsingBody:
                    if(0 == strcmp(state->lastKey, "fixtures"))
                        state->state = State_parsingFixtures;                        
					break;
                    
				case State_parsingFixture:
                    if(0 == strcmp(state->lastKey, "polygons")) {
                        state->state = State_parsingShapes;
                    }
					break;
                    
				case State_parsingShapes:
                    state->state = State_parsingShape;
                    state->vertexIndex = 0;
					break;

                default:
                    break;
			}

            break;
            
		case TAG_TRUE:
            switch(state->state) {
				case State_parsingFixture:
                {
                    if(0 == strcmp(state->lastKey, "isSensor"))
                        state->fixtureDef->isSensor = true;
                }
                default:
                    break;
			}
			break;
		case TAG_FALSE:
            switch(state->state) {
				case State_parsingFixture:
                {
                    if(0 == strcmp(state->lastKey, "isSensor"))
                        state->fixtureDef->isSensor = false;
                }
                default:
                    break;
			}
			break;
	}
}