Ticket #1831: kml_variable_fixes.diff

File kml_variable_fixes.diff, 6.1 kB (added by mloskot, 1 year ago)

Patch for the KML driver

  • ogr/ogrsf_frmts/kml/kmlnode.cpp

    old new  
    112112} 
    113113 
    114114KMLnode::~KMLnode() { 
    115     for(unsigned short z = 0; z < this->pvpoChildren->size();z++) 
     115    unsigned short nCount; 
     116    for(nCount = 0; nCount < this->pvpoChildren->size(); nCount++) 
    116117    { 
    117         delete(this->pvpoChildren->at(z)); 
     118        delete(this->pvpoChildren->at(nCount)); 
    118119    } 
    119120    delete(this->pvpoChildren); 
    120121    delete(this->pvsContent); 
    121     for(unsigned short z = 0; z < this->pvoAttributes->size();z++) 
     122    for(nCount = 0; nCount < this->pvoAttributes->size(); nCount++) 
    122123    { 
    123         delete this->pvoAttributes->at(z); 
     124        delete this->pvoAttributes->at(nCount); 
    124125    } 
    125126    delete(this->pvoAttributes); 
    126127    if(this->psExtent != NULL) 
     
    129130 
    130131void KMLnode::print(unsigned int what) { 
    131132    std::string indent(""); 
    132     for(unsigned int z = 0; z < this->nLevel; z++) 
     133    unsigned int nCount; 
     134    for(nCount = 0; nCount < this->nLevel; nCount++) 
    133135        indent += " "; 
    134136    if(this->nLevel > 0) { 
    135137        if(this->nLayerNumber > -1) 
     
    157159            indent.c_str(), this->sName.c_str(), Nodetype2String(this->eType).c_str(), this->nLevel, this->pvpoChildren->size(),  
    158160            this->pvsContent->size(), this->pvoAttributes->size()); 
    159161    if(what == 1 || what == 3) 
    160         for(unsigned int z = 0; z < this->pvsContent->size(); z++) 
    161             CPLDebug("KML", "%s|->pvsContent: '%s'", indent.c_str(), this->pvsContent->at(z).c_str()); 
     162        for(nCount = 0; nCount < this->pvsContent->size(); nCount++) 
     163            CPLDebug("KML", "%s|->pvsContent: '%s'", indent.c_str(), this->pvsContent->at(nCount).c_str()); 
    162164    if(what == 2 || what == 3) 
    163         for(unsigned int z = 0; z < this->pvoAttributes->size(); z++) 
    164             CPLDebug("KML", "%s|->pvoAttributes: %s = '%s'", indent.c_str(), this->pvoAttributes->at(z)->sName.c_str(), this->pvoAttributes->at(z)->sValue.c_str()); 
    165     for(unsigned int z = 0; z < this->pvpoChildren->size(); z++) 
    166         this->pvpoChildren->at(z)->print(what); 
     165        for(nCount = 0; nCount < this->pvoAttributes->size(); nCount++) 
     166            CPLDebug("KML", "%s|->pvoAttributes: %s = '%s'", indent.c_str(), this->pvoAttributes->at(nCount)->sName.c_str(), this->pvoAttributes->at(nCount)->sValue.c_str()); 
     167    for(nCount = 0; nCount < this->pvpoChildren->size(); nCount++) 
     168        this->pvpoChildren->at(nCount)->print(what); 
    167169} 
    168170 
    169171void KMLnode::classify(KML *kmlclass) { 
     
    171173     
    172174    CPLDebug("KML", "Start -- sName: %s\tnLevel: %d\t", this->sName.c_str(), this->nLevel); 
    173175 
    174     for(unsigned int z = 0; z < this->pvpoChildren->size(); z++) { 
     176    for(unsigned int nCount = 0; nCount < this->pvpoChildren->size(); nCount++) { 
    175177        // Leafs are ignored 
    176         if(kmlclass->isLeaf(this->pvpoChildren->at(z)->sName)) 
     178        if(kmlclass->isLeaf(this->pvpoChildren->at(nCount)->sName)) 
    177179            continue; 
    178180        // Classify pvpoChildren 
    179         this->pvpoChildren->at(z)->classify(kmlclass); 
     181        this->pvpoChildren->at(nCount)->classify(kmlclass); 
    180182 
    181183        if(kmlclass->isContainer(this->sName)) 
    182             curr = this->pvpoChildren->at(z)->eType; 
     184            curr = this->pvpoChildren->at(nCount)->eType; 
    183185        else if(kmlclass->isFeatureContainer(this->sName)) { 
    184             if(kmlclass->isFeature(this->pvpoChildren->at(z)->sName)) { 
    185                 if(this->pvpoChildren->at(z)->sName.compare("Point") == 0) 
     186            if(kmlclass->isFeature(this->pvpoChildren->at(nCount)->sName)) { 
     187                if(this->pvpoChildren->at(nCount)->sName.compare("Point") == 0) 
    186188                    curr = Point; 
    187                 else if(this->pvpoChildren->at(z)->sName.compare("LineString") == 0) 
     189                else if(this->pvpoChildren->at(nCount)->sName.compare("LineString") == 0) 
    188190                    curr = LineString; 
    189                 else if(this->pvpoChildren->at(z)->sName.compare("Polygon") == 0) 
     191                else if(this->pvpoChildren->at(nCount)->sName.compare("Polygon") == 0) 
    190192                    curr = Polygon; 
    191193            } else if(kmlclass->isContainer(this->sName)) 
    192                 curr = this->pvpoChildren->at(z)->eType; 
     194                curr = this->pvpoChildren->at(nCount)->eType; 
    193195        } else if(kmlclass->isFeature(this->sName) || kmlclass->isRest(this->sName)) 
    194196            curr = Empty; 
    195197             
     
    211213} 
    212214 
    213215void KMLnode::eliminateEmpty(KML *kmlclass) { 
    214     for(unsigned int z = 0; z < this->pvpoChildren->size(); z++) { 
    215         if(this->pvpoChildren->at(z)->eType == Empty &&  
    216                 (kmlclass->isContainer(this->pvpoChildren->at(z)->sName) ||  
    217                 kmlclass->isFeatureContainer(this->pvpoChildren->at(z)->sName))) { 
    218             CPLDebug("KML", "Deleting sName: %s\tClassify sName: %s\tnLevel: %d\tpoParent: %s", this->pvpoChildren->at(z)->sName.c_str(), Nodetype2String(this->pvpoChildren->at(z)->eType).c_str(), this->pvpoChildren->at(z)->nLevel, this->sName.c_str()); 
    219             delete this->pvpoChildren->at(z); 
    220             this->pvpoChildren->erase(this->pvpoChildren->begin() + z); 
    221             z--; 
     216    for(unsigned int nCount = 0; nCount < this->pvpoChildren->size(); nCount++) { 
     217        if(this->pvpoChildren->at(nCount)->eType == Empty &&  
     218                (kmlclass->isContainer(this->pvpoChildren->at(nCount)->sName) ||  
     219                kmlclass->isFeatureContainer(this->pvpoChildren->at(nCount)->sName))) { 
     220            CPLDebug("KML", "Deleting sName: %s\tClassify sName: %s\tnLevel: %d\tpoParent: %s", this->pvpoChildren->at(nCount)->sName.c_str(), Nodetype2String(this->pvpoChildren->at(nCount)->eType).c_str(), this->pvpoChildren->at(nCount)->nLevel, this->sName.c_str()); 
     221            delete this->pvpoChildren->at(nCount); 
     222            this->pvpoChildren->erase(this->pvpoChildren->begin() + nCount); 
     223            nCount--; 
    222224        } else 
    223             this->pvpoChildren->at(z)->eliminateEmpty(kmlclass); 
     225            this->pvpoChildren->at(nCount)->eliminateEmpty(kmlclass); 
    224226    } 
    225227    this->calcExtent(kmlclass); 
    226228}