// Decode block of characters if input!=NO_INPUT // throws SAXException() void CommonReadHandler::characters(const XMLCh* const chars,const XMLSize_t length) { if(input==NO_INPUT) return; char *xData=XMLString::transcode(chars); switch(input) { case TEXT_BLOCK: switch(inputID) { case DESCRIPTION: fmobj->SetDescription(xData); break; case CHAR_ARRAY: if(inputPtr!=NULL) delete [] inputPtr; inputPtr=new char[strlen(xData)+1]; strcpy(inputPtr,xData); // the end element method should assign its pointer to inputPtr break; default: myCharacters(xData,(int)length); break; } break; case INT_NUM: sscanf(xData,"%d",(int *)inputPtr); break; case DOUBLE_NUM: sscanf(xData,"%lf",(double *)inputPtr); *((double *)inputPtr)*=gScaling; gScaling=1.; break; case ANALYSIS_NUM: sscanf(xData,"%d",&fmobj->np); if(!fmobj->ValidAnalysisType()) throw SAXException("Unknown <Analysis> type in the <Header>."); break; case NOT_NUM: break; default: myCharacters(xData,(int)length); break; } delete [] xData; }
void PCLoaderXML::myStartElement(int element, const SUMOSAXAttributes& attrs) { if (element != SUMO_TAG_POI && element != SUMO_TAG_POLY) { return; } if (element == SUMO_TAG_POI) { bool ok = true; // get the id, report an error if not given or empty... std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok); SUMOReal x = attrs.getSUMORealReporting(SUMO_ATTR_X, id.c_str(), ok); SUMOReal y = attrs.getSUMORealReporting(SUMO_ATTR_Y, id.c_str(), ok); std::string type = attrs.getOptStringReporting(SUMO_ATTR_TYPE, id.c_str(), ok, ""); if (!ok) { return; } Position pos(x, y); if (!GeoConvHelper::getProcessing().x2cartesian(pos)) { WRITE_WARNING("Unable to project coordinates for POI '" + id + "'."); } // patch the values bool discard = myOptions.getBool("discard"); int layer = myOptions.getInt("layer"); RGBColor color; if (myTypeMap.has(type)) { const PCTypeMap::TypeDef& def = myTypeMap.get(type); id = def.prefix + id; type = def.id; color = RGBColor::parseColor(def.color); discard = def.discard; layer = def.layer; } else { id = myOptions.getString("prefix") + id; type = myOptions.getString("type"); color = RGBColor::parseColor(myOptions.getString("color")); } if (!discard) { bool ignorePrunning = false; if (OptionsCont::getOptions().isInStringVector("prune.keep-list", id)) { ignorePrunning = true; } PointOfInterest* poi = new PointOfInterest(id, type, pos, color); if (!myCont.insert(id, poi, layer, ignorePrunning)) { WRITE_ERROR("POI '" + id + "' could not been added."); delete poi; } } } if (element == SUMO_TAG_POLY) { bool discard = myOptions.getBool("discard"); int layer = myOptions.getInt("layer"); bool ok = true; std::string id = attrs.getOptStringReporting(SUMO_ATTR_ID, myCurrentID.c_str(), ok, ""); std::string type = attrs.getOptStringReporting(SUMO_ATTR_TYPE, myCurrentID.c_str(), ok, ""); if (!ok) { return; } RGBColor color; if (myTypeMap.has(type)) { const PCTypeMap::TypeDef& def = myTypeMap.get(type); id = def.prefix + id; type = def.id; color = RGBColor::parseColor(def.color); discard = def.discard; layer = def.layer; } else { id = myOptions.getString("prefix") + id; type = myOptions.getString("type"); color = RGBColor::parseColor(myOptions.getString("color")); } if (!discard) { bool ignorePrunning = false; if (OptionsCont::getOptions().isInStringVector("prune.keep-list", id)) { ignorePrunning = true; } myCurrentID = id; myCurrentType = type; myCurrentColor = color; myCurrentIgnorePrunning = ignorePrunning; myCurrentLayer = layer; if (attrs.hasAttribute(SUMO_ATTR_SHAPE)) { // @deprecated At some time, no shape definition using characters will be allowed myCharacters(element, attrs.getStringReporting(SUMO_ATTR_SHAPE, myCurrentID.c_str(), ok)); } } } }