int main(int argc, char **argv) { std::string nodeName = "node"; std::string hostName = "localhost"; std::string configFile = ""; for(int i = 0; i < argc; i++) { if(!strcmp(argv[i], "-nodename")) nodeName = argv[i+1]; if(!strcmp(argv[i], "-hostname")) hostName = argv[i+1]; if(!strcmp(argv[i], "-config")) configFile = argv[i+1]; } std::vector<boost::thread*> compThreads; XMLParser nodeParser; std::string configFileName = nodeName + ".xml"; if (configFile.length() > 0) configFileName = configFile; if (nodeParser.Parse(configFileName)) { ros::init(argc, argv, nodeName.c_str()); // Create Node Handle ros::NodeHandle n; ROS_INFO_STREAM(nodeName << " thread id = " << boost::this_thread::get_id()); for (int i=0;i<nodeParser.compConfigList.size();i++) { std::string libraryLocation = nodeParser.compConfigList[i].libraryLocation; void *hndl = dlopen(libraryLocation.c_str(), RTLD_NOW); if(hndl == NULL) { cerr << dlerror() << endl; exit(-1); } void *mkr = dlsym(hndl, "maker"); Component *comp_inst = ((Component *(*)(ComponentConfig &, int , char **))(mkr)) (nodeParser.compConfigList[i], argc, argv); // Create Component Threads boost::thread *comp_thread = new boost::thread(componentThreadFunc, comp_inst); compThreads.push_back(comp_thread); ROS_INFO_STREAM(nodeName << " has started " << nodeParser.compConfigList[i].compName); } for (int i=0;i<compThreads.size();i++) { compThreads[i]->join(); } return 0; } else { printf("ERROR::Unable to parse XML file\n"); return -1; } }
void DictionaryInfo::ReadLangTo(const GUTF8String& str, bool bEncoded) { strLangToCode = ""; langToLoc.clear(); if (str.length() == 0) return; string strTemp = str; if (bEncoded) Base64Decode(strTemp); strLangToRaw = strTemp.c_str(); stringstream sin(strTemp.c_str()); XMLParser parser; if (parser.Parse(sin)) { wstring strCode; if (parser.GetRoot()->GetAttribute(pszAttrCode, strCode)) strLangToCode = MakeUTF8String(strCode); ReadLocalizedStrings(langToLoc, *parser.GetRoot()); } }
OP_STATUS WebFeedStorage::LocalLoad(const uni_char *file_name) { OP_STATUS oom = OpStatus::OK; OpFile feed_file; OpStringC file_name_str(file_name); oom = feed_file.Construct(file_name_str.CStr(), OPFILE_WEBFEEDS_FOLDER); if (OpStatus::IsError(oom)) return oom; UnicodeFileInputStream in_stream; RETURN_IF_ERROR(in_stream.Construct(&feed_file, URL_XML_CONTENT, TRUE)); XMLParser *parser; URL dummy; RETURN_IF_ERROR(XMLParser::Make(parser, NULL, g_main_message_handler, this, dummy)); OpStackAutoPtr<XMLParser> protected_parser(parser); // Set up XML configuration for parsing web feed storage: XMLParser::Configuration configuration; configuration.load_external_entities = XMLParser::LOADEXTERNALENTITIES_NO; configuration.max_tokens_per_call = 0; // unlimited #if defined(_DEBUG) && defined(XML_ERRORS) configuration.generate_error_report = TRUE; #endif parser->SetConfiguration(configuration); int buf_len = 2048; BOOL more = in_stream.has_more_data(); while (OpStatus::IsSuccess(oom) && more && !parser->IsFailed()) { uni_char *buf = in_stream.get_block(buf_len); more = in_stream.has_more_data(); OP_ASSERT(buf_len % sizeof(uni_char) == 0); buf_len /= sizeof(uni_char); OP_ASSERT(buf); if (!buf) return OpStatus::ERR; oom = parser->Parse(buf, buf_len, more); OP_ASSERT(!parser->IsFailed()); #if defined(_DEBUG) && defined XML_ERRORS if (parser->IsFailed()) { XMLRange range; const char *error, *url, *fragment; range = parser->GetErrorPosition(); parser->GetErrorDescription(error, url, fragment); } #endif // defined(_DEBUG) && defined(XML_ERRORS) } return OpStatus::OK; }
//------------------------------------------// // AssetMetaDataParser::WriteMetaData //------------------------------------------// bool AssetMetaDataParser::WriteMetaDataToFile( class File& metaDataFile, const struct AssetMetaData& metaData) { if (!CheckMetaDataFileIsValid(metaDataFile)) { return false; } // Check if the file is new and cleared if (metaDataFile.GetFilemode() != File::READ_WRITE_NEW) { Log::GetLog().LogHighMsg("MetaDataFile is not empty."); return false; } //Begin the XML parsing XMLParser parser; if (!parser.Parse(metaDataFile)) { return false; } XMLElement baseElement = parser.CreateNewElement(ASSET_TAG); baseElement.CreateChildElement(ASSET_NAME_TAG, metaData.AssetName); //Determine readable name from TypeHash std::string assetType = "Invalid"; if (!mAssetFileTypeExtensions->HashIsOfAssetTypeName(metaData.AssetTypeHash, assetType)) { //Log that we cant determine type } baseElement.CreateChildElement(ASSET_TYPE_TAG, assetType); baseElement.CreateChildElement(ASSET_PATH_TAG, metaData.AssetFilePath); XMLElement attrElement = baseElement.CreateChildElement(ASSET_ATTRIBUTE_TAG); XMLElement scalarAttrElement = attrElement.CreateChildElement(ASSET_SCALAR_ATTRIBUTE_TAG); XMLElement vectorAttrElement = attrElement.CreateChildElement(ASSET_VECTOR_ATTRIBUTE_TAG); AssetScalarAttributeContainer& container = AssetDefaultAttributes<Texture2D>::DefaultScalarAttributes; for each (AssetScalarAttribute scalarAttr in container) { scalarAttrElement.CreateChildElement(scalarAttr.AttributeName, ToString(scalarAttr.AttributeValue)); }
void DictionaryInfo::ReadTitle(const GUTF8String& str, bool bEncoded) { titleLoc.clear(); if (str.length() == 0) return; string strTemp = str; if (bEncoded) Base64Decode(strTemp); strTitleRaw = strTemp.c_str(); stringstream sin(strTemp.c_str()); XMLParser parser; if (parser.Parse(sin)) ReadLocalizedStrings(titleLoc, *parser.GetRoot()); }
bool XMLDoc::ReadXMLFile(const std::string& fileName) { std::wifstream fileStream; fileStream.open(fileName.c_str(), std::wifstream::in); if( fileStream.fail() ) { wprintf(L"FILE OPEN ERROR"); return false; } unsigned int length = 0; fileStream.seekg(0, fileStream.end); length = fileStream.tellg(); fileStream.seekg(0, fileStream.beg); if ( length <= 0 ) { return false; } wchar_t* buf = new wchar_t[ length+1 ]; buf[0] = 0; fileStream.read(buf, length ); buf[length] = '\0'; XMLParser parser; _mRoot = parser.Parse(buf, length); if( _mRoot == nullptr ) { } fileStream.close(); return true; }
int main(int argc, char* argv[]) { std::string file; std::string cFile; std::string host="127.0.0.1"; std::string user; std::string port="5432"; std::string dbname; std::string passwd; bool skipnodes = false; bool clean = false; if(argc >=7 && argc <=17) { int i=1; while( i<argc) { if(strcmp(argv[i],"-file")==0) { i++; file = argv[i]; } else if(strcmp(argv[i],"-conf")==0) { i++; cFile = argv[i]; } else if(strcmp(argv[i],"-host")==0) { i++; host = argv[i]; } else if(strcmp(argv[i],"-dbname")==0) { i++; dbname = argv[i]; } else if(strcmp(argv[i],"-user")==0) { i++; user = argv[i]; } else if(strcmp(argv[i],"-port")==0) { i++; port = argv[i]; } else if(strcmp(argv[i],"-passwd")==0) { i++; passwd = argv[i]; } else if(strcmp(argv[i],"-clean")==0) { clean = true; } else if(strcmp(argv[i],"-skipnodes")==0) { skipnodes = true; } else { cout << "unknown paramer: " << argv[i] << endl; _error(); return 1; } i++; } } else { _error(); return 1; } if(file.empty() || cFile.empty() || dbname.empty() || user.empty()) { _error(); return 1; } Export2DB test(host, user, dbname, port, passwd); if(test.connect()==1) return 1; XMLParser parser; cout << "Trying to load config file " << cFile.c_str() << endl; Configuration* config = new Configuration(); ConfigurationParserCallback cCallback( *config ); cout << "Trying to parse config" << endl; int ret = parser.Parse( cCallback, cFile.c_str() ); if( ret!=0 ) { cerr << "Failed to parse config file " << cFile.c_str() << endl; return 1; } cout << "Trying to load data" << endl; OSMDocument* document = new OSMDocument( *config ); OSMDocumentParserCallback callback( *document ); cout << "Trying to parse data" << endl; ret = parser.Parse( callback, file.c_str() ); if( ret!=0 ) { if( ret == 1 ) cerr << "Failed to open data file" << endl; cerr << "Failed to parse data file " << file.c_str() << endl; return 1; } cout << "Split ways" << endl; document->SplitWays(); //############# Export2DB { if( clean ) { cout << "Dropping tables..." << endl; test.dropTables(); } cout << "Creating tables..." << endl; test.createTables(); cout << "Adding tag types and classes to database..." << endl; test.exportTypesWithClasses(config->m_Types); cout << "Adding relations to database..." << endl; test.exportRelations(document->m_Relations, config); // Optional user argument skipnodes will not add nodes to the database (saving a lot of time if not necessary) if ( !skipnodes) { cout << "Adding nodes to database..." << endl; test.exportNodes(document->m_Nodes); } cout << "Adding ways to database..." << endl; test.exportWays(document->m_SplittedWays, config); cout << "Creating topology..." << endl; test.createTopology(); } //############# /* std::vector<Way*>& ways= document.m_Ways; std::vector<Way*>::iterator it( ways.begin() ); std::vector<Way*>::iterator last( ways.end() ); while( it!=last ) { Way* pWay = *it; if( !pWay->name.empty() ) { if( pWay->m_NodeRefs.empty() ) { std::cout << pWay->name.c_str() << endl; } else { Node* n0 = pWay->m_NodeRefs.front(); Node* n1 = pWay->m_NodeRefs.back(); //if(n1->numsOfUse==1) //cout << "way-id: " << pWay->id << " name: " << pWay->name <<endl; //std::cout << n0->lon << " " << n0->lat << " " << n1->lon << " " << n1->lat << " " << pWay->name.c_str() << " highway: " << pWay->highway.c_str() << " Start numberOfUse: " << n0->numsOfUse << " End numberOfUse: " << n1->numsOfUse << " ID: " << n1->id << endl; } } if( pWay->id == 20215432 ) // Pfaenderweg { cout << pWay->name << endl; int a=4; } ++it; } */ cout << "#########################" << endl; cout << "size of streets: " << document->m_Ways.size() << endl; cout << "size of splitted ways : " << document->m_SplittedWays.size() << endl; cout << "finished" << endl; //string n; //getline( cin, n ); return 0; }
void Level::ParseLevelConfig(std::wstring fileName) { XMLParser* parser = new XMLParser(); parser->LoadFile(fileName); while (parser->Parse(L"Level")) { // Skip the tag if its not an opening tag. if (parser->GetTagType() != XMLParser::OPENING) { continue; } // Read the tag if its an opening tag std::wstring tagName = parser->GetTagName(); std::wstring tagContent = parser->GetTagContent(); if (tagName.compare(L"ID") == 0) { m_LevelName = tagContent; } else if (tagName.compare(L"StandardConfig") == 0) { m_StandardConfigPath = tagContent; } else if (tagName.compare(L"SVG") == 0) { m_SVGPath = tagContent; m_ActorLayoutPtr->AddSVGShape(String(m_SVGPath.c_str())); } else if (tagName.compare(L"Visuals") == 0) { m_VisualsPath = tagContent; m_ImgVisualsPtr = new Bitmap(String(m_VisualsPath.c_str())); // Add a polygonal shape around the level std::vector<DOUBLE2> levelBoundaries(4); levelBoundaries[0] = DOUBLE2(0, 0); levelBoundaries[1] = DOUBLE2(0, m_ImgVisualsPtr->GetHeight()); levelBoundaries[2] = DOUBLE2(m_ImgVisualsPtr->GetWidth(), m_ImgVisualsPtr->GetHeight()); levelBoundaries[3] = DOUBLE2(m_ImgVisualsPtr->GetWidth(), 0); m_ActorLayoutPtr->AddChainShape(levelBoundaries, true); } else if (tagName.compare(L"Shadows") == 0) { m_ShadowsPath = tagContent; m_ImgShadowsPtr = new Bitmap(String(m_ShadowsPath.c_str())); } else if (tagName.compare(L"Navigation") == 0) { // Loads an image that is converted and used a navigation grid m_NavigationPath = tagContent; Bitmap* navigationImg = new Bitmap(String(m_NavigationPath.c_str())); // Create a navigation grid for the pathfinding algorithm. std::vector<std::vector<COLOR>> rawPixelData = navigationImg->GetRawPixelData(); m_NavigationGrid = std::vector<std::vector<bool>>(navigationImg->GetHeight(), std::vector<bool>(navigationImg->GetWidth())); for (int i = 0; i < navigationImg->GetHeight(); ++i) { for (int j = 0; j < navigationImg->GetWidth(); ++j) { COLOR color = rawPixelData[i][j]; int avarageValue = (color.red + color.green + color.blue) / 3; if (avarageValue < 128) { m_NavigationGrid[i][j] = false; } else { m_NavigationGrid[i][j] = true; } } rawPixelData[i].clear(); } rawPixelData.clear(); delete navigationImg; } else if (tagName.compare(L"Objective") == 0) { m_ObjectivePath = tagContent; m_ImgIntroPtr = new Bitmap(String(m_ObjectivePath.c_str())); } else if (tagName.compare(L"AudioMainMusic") == 0) { m_AudioMainMusic = tagContent; } else if (tagName.compare(L"AudioCompletedMusic") == 0) { m_AudioCompletedMusic = tagContent; } else if (tagName.compare(L"AudioCompletedEffect") == 0) { m_AudioCompletedEffect = tagContent; } else if (tagName.compare(L"EndZone") == 0) { if (m_EndZonePtr != nullptr) { DeleteResource(m_EndZonePtr); } m_EndZonePtr = new LevelEndZone(parser); m_EndZonePtr->SetActive(false); } else if (tagName.compare(L"Score") == 0) { if (m_ScorePtr != nullptr) { DeleteResource(m_ScorePtr); } m_ScorePtr = new LevelScore(parser); } else if (tagName.compare(L"TargetTime") == 0) { m_TargetCompletionTime = std::stod(tagContent); } else if (tagName.compare(L"Door") == 0) { m_DoorPtrs.push_back(new Door(parser)); } else if (tagName.compare(L"Pickup") == 0) { m_PickupPtrs.push_back(new Pickup(parser)); } else if (tagName.compare(L"Enemies") == 0) { // Sub-parsing level. // Per enemy type (a patrolling or stationary unit) while (parser->Parse(L"Enemies")) { if (parser->GetTagType() != XMLParser::OPENING) { continue; } tagName = parser->GetTagName(); if (tagName.compare(L"Patrol") == 0) { m_EnemyPtrs.push_back(new PatrollingEnemy(parser)); } else if (tagName.compare(L"Guard") == 0) { m_EnemyPtrs.push_back(new GuardingEnemy(parser)); } } } else if (tagName.compare(L"Hostages") == 0) { // Sub-level parsing for hostages while (parser->Parse(L"Hostages")) { if (parser->GetTagType() != XMLParser::OPENING) { continue; } tagName = parser->GetTagName(); if (tagName.compare(L"Hostage") == 0) { m_HostagePtrs.push_back(new Hostage(parser)); } } } else if (tagName.compare(L"Player") == 0) { m_PlayerPtr = new Player(parser); m_CameraPtr = new Camera(m_PlayerPtr); m_CameraPtr->Tick(0.0); m_HUD->SetTarget(m_PlayerPtr); } } delete parser; }
HX_RESULT RTSPMediaDesc::fromExternalRep(char* pData) { XMLParser parser; XMLTag* pTag = 0; CByteQueue* pQueue = new CByteQueue((UINT16)strlen(pData)); HXBOOL inMediaHeader = FALSE; HXBOOL inMediaStream = FALSE; HX_RESULT hresult = HXR_OK; RTSPPropertyList* pMediaHeader = 0; RTSPPropertyList* pMediaStream = 0; pQueue->EnQueue(pData, (UINT16)strlen(pData)); for(;;) { UINT32 bytesUsed; UINT32 bytesAvail = pQueue->GetQueuedItemCount(); if(bytesAvail <= 0) { break; } BYTE* pBuf = new BYTE[bytesAvail]; BYTE* p = pBuf; HX_ASSERT(bytesAvail == (UINT16)bytesAvail); pQueue->DeQueue(pBuf, (UINT16)bytesAvail); bytesUsed = bytesAvail; if(pTag) { delete pTag; pTag = 0; } XMLParseResult rc = parser.Parse((const char*&)p, bytesAvail, pTag); HX_ASSERT(bytesAvail == (UINT16)bytesAvail); pQueue->EnQueue(p, (UINT16)(bytesAvail - (p - pBuf))); switch(rc) { case XMLPTag: { switch(pTag->m_type) { case XMLPlainTag: { if(strcasecmp(pTag->m_name, "MediaHeader") == 0) { if(inMediaHeader) { //XXXBAB parse error } if(pMediaHeader) { delete pMediaHeader; } pMediaHeader = new RTSPPropertyList; inMediaHeader = TRUE; inMediaStream = FALSE; } else if(strcasecmp(pTag->m_name, "MediaStream") == 0) { if(inMediaStream) { //XXXBAB parse error } pMediaStream = new RTSPPropertyList; inMediaHeader = FALSE; inMediaStream = TRUE; } else { RTSPProperty* pProp = makeProperty(pTag); if(pProp) { if(inMediaHeader) { pMediaHeader->addProperty(pProp); } else if(inMediaStream) { pMediaStream->addProperty(pProp); } } } } break; case XMLEndTag: { if(strcasecmp(pTag->m_name, "MediaHeader") == 0) { if(inMediaHeader) { m_pFileHeader = pMediaHeader; } else { // error } inMediaHeader = FALSE; } else if(strcasecmp(pTag->m_name, "MediaStream") == 0) { if(inMediaStream) { m_streams->AddTail(pMediaStream); } else { // error } inMediaStream = FALSE; } } break; default: { // unexpected } break; } } break; case XMLPPlainText: { // unexpected } break; case XMLPComment: { // oh, yeah? } break; default: { // unexpected } break; } delete[] pBuf; } if(pTag) { delete pTag; } delete pQueue; return hresult; }