Changeset 12152

Show
Ignore:
Timestamp:
09/14/07 03:58:33 (1 year ago)
Author:
mloskot
Message:

ogr/ogrsf_frmts/kml: cleaned variables scope (Ticket #1831); added typedefs of internal collections of kmlnode; started some refactoring.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gdal/ogr/ogrsf_frmts/kml/kmlnode.cpp

    r12150 r12152  
    3737/************************************************************************/ 
    3838 
    39 std::string Nodetype2String(Nodetype t) { 
     39std::string Nodetype2String(Nodetype t) 
     40
    4041    if(t == Empty) 
    4142        return "Empty"; 
     
    101102/*                         KMLnode methods                              */ 
    102103/************************************************************************/ 
    103 KMLnode::KMLnode() { 
     104 
     105KMLnode::KMLnode() 
     106
    104107    this->sName = ""; 
    105108    this->poParent = NULL; 
     
    112115} 
    113116 
    114 KMLnode::~KMLnode() { 
    115     for(unsigned short z = 0; z < this->pvpoChildren->size();z++) 
    116     { 
    117         delete(this->pvpoChildren->at(z)); 
    118     } 
     117KMLnode::~KMLnode() 
     118
     119    kml_nodes_t::size_type nCount = 0; 
     120 
     121    for( nCount = 0; nCount < pvpoChildren->size(); ++nCount ) 
     122    { 
     123        delete (pvpoChildren->at( nCount )); 
     124    } 
     125 
    119126    delete(this->pvpoChildren); 
    120127    delete(this->pvsContent); 
    121     for(unsigned short z = 0; z < this->pvoAttributes->size();z++) 
    122     { 
    123         delete this->pvoAttributes->at(z); 
    124     } 
    125     delete(this->pvoAttributes); 
    126     if(this->psExtent != NULL) 
    127         delete this->psExtent; 
    128 
    129  
    130 void KMLnode::print(unsigned int what) { 
     128 
     129    for( nCount = 0; nCount < pvoAttributes->size(); ++nCount) 
     130    { 
     131        delete pvoAttributes->at(nCount); 
     132    } 
     133     
     134    delete(pvoAttributes); 
     135 
     136    if( psExtent != NULL ) 
     137        delete psExtent; 
     138
     139 
     140void KMLnode::print(unsigned int what) 
     141
    131142    std::string indent(""); 
     143 
    132144    for(unsigned int z = 0; z < this->nLevel; z++) 
    133145        indent += " "; 
    134     if(this->nLevel > 0) { 
     146 
     147    if(this->nLevel > 0) 
     148    { 
    135149        if(this->nLayerNumber > -1) 
    136150            if(this->psExtent != NULL) 
     
    167181} 
    168182 
    169 void KMLnode::classify(KML *kmlclass) { 
     183void KMLnode::classify(KML *kmlclass) 
     184
    170185    Nodetype curr = Unknown, all = Empty; 
    171186     
     
    211226} 
    212227 
    213 void KMLnode::eliminateEmpty(KML *kmlclass) { 
     228void KMLnode::eliminateEmpty(KML *kmlclass) 
     229
    214230    for(unsigned int z = 0; z < this->pvpoChildren->size(); z++) { 
    215231        if(this->pvpoChildren->at(z)->eType == Empty &&  
     
    226242} 
    227243 
    228 void KMLnode::setType(Nodetype oNotet) { 
     244void KMLnode::setType(Nodetype oNotet) 
     245
    229246    this->eType = oNotet; 
    230247} 
    231248 
    232 Nodetype KMLnode::getType() { 
     249Nodetype KMLnode::getType() 
     250
    233251    return this->eType; 
    234252} 
    235253 
    236 void KMLnode::setName(std::string const& sIn) { 
     254void KMLnode::setName(std::string const& sIn) 
     255
    237256    this->sName = sIn; 
    238257} 
    239258 
    240 std::string KMLnode::getName() { 
     259std::string KMLnode::getName() 
     260
    241261    return this->sName; 
    242262} 
    243263 
    244 void KMLnode::setLevel(unsigned int nLev) { 
     264void KMLnode::setLevel(unsigned int nLev) 
     265
    245266    this->nLevel = nLev; 
    246267} 
    247268 
    248 unsigned int KMLnode::getLevel() { 
     269unsigned int KMLnode::getLevel() 
     270
    249271    return this->nLevel; 
    250272} 
    251273 
    252 void KMLnode::addAttribute(Attribute *poAttr) { 
     274void KMLnode::addAttribute(Attribute *poAttr) 
     275
    253276    this->pvoAttributes->push_back(poAttr); 
    254277} 
    255278 
    256 void KMLnode::setParent(KMLnode* poPar) { 
     279void KMLnode::setParent(KMLnode* poPar) 
     280
    257281    this->poParent = poPar; 
    258282} 
    259283 
    260 KMLnode* KMLnode::getParent() { 
     284KMLnode* KMLnode::getParent() 
     285
    261286    return this->poParent; 
    262287} 
    263288 
    264 void KMLnode::addChildren(KMLnode *poChil) { 
     289void KMLnode::addChildren(KMLnode *poChil) 
     290
    265291    this->pvpoChildren->push_back(poChil); 
    266292} 
    267293 
    268 unsigned short KMLnode::countChildren() { 
     294unsigned short KMLnode::countChildren() 
     295
    269296    return this->pvpoChildren->size(); 
    270297} 
    271298 
    272 KMLnode* KMLnode::getChild(unsigned short nNum) { 
     299KMLnode* KMLnode::getChild(unsigned short nNum) 
     300
    273301    return this->pvpoChildren->at(nNum); 
    274302} 
    275303 
    276 void KMLnode::addContent(std::string const& sCon) { 
     304void KMLnode::addContent(std::string const& sCon) 
     305
    277306    this->pvsContent->push_back(sCon); 
    278307} 
    279308 
    280 void KMLnode::appendContent(std::string sCon) { 
     309void KMLnode::appendContent(std::string sCon) 
     310
    281311    this->pvsContent->at(this->pvsContent->size()-1) += sCon; 
    282312} 
    283313 
    284 std::string KMLnode::getContent(unsigned short nNum) { 
     314std::string KMLnode::getContent(unsigned short nNum) 
     315
    285316    if(nNum >= this->pvsContent->size()) 
    286317        return NULL; 
     
    288319} 
    289320 
    290 void KMLnode::deleteContent(unsigned short nNum) { 
     321void KMLnode::deleteContent(unsigned short nNum) 
     322
    291323    if(nNum >= this->pvsContent->size()) 
    292324        return; 
     
    294326} 
    295327 
    296 unsigned short KMLnode::numContent() { 
     328unsigned short KMLnode::numContent() 
     329
    297330    return this->pvsContent->size(); 
    298331} 
    299332 
    300 void KMLnode::setLayerNumber(short nNum) { 
     333void KMLnode::setLayerNumber(short nNum) 
     334
    301335    this->nLayerNumber = nNum; 
    302336} 
    303337 
    304 short KMLnode::getLayerNumber() { 
     338short KMLnode::getLayerNumber() 
     339
    305340    return this->nLayerNumber; 
    306341} 
    307342 
    308 KMLnode* KMLnode::getLayer(unsigned short nNum) { 
     343KMLnode* KMLnode::getLayer(unsigned short nNum) 
     344
    309345    KMLnode *poTmp; 
    310346    if(this->nLayerNumber == nNum) 
    311347        return this; 
     348 
    312349    for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) 
     350    { 
    313351        if((poTmp = this->pvpoChildren->at(nCount)->getLayer(nNum)) != NULL) 
    314352            return poTmp; 
     353    } 
     354 
    315355    return NULL; 
    316356} 
    317357 
    318 std::string KMLnode::getNameElement() { 
     358std::string KMLnode::getNameElement() 
     359
     360    std::string sContent; 
     361 
     362    for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) 
     363    { 
     364        if(this->pvpoChildren->at(nCount)->sName.compare("name") == 0) 
     365        { 
     366            sContent = this->pvpoChildren->at(nCount)->pvsContent->at(0); 
     367            for(unsigned short nCount2 = 1; nCount2 < this->pvpoChildren->at(nCount)->pvsContent->size(); nCount2++) 
     368            { 
     369                sContent += " " + this->pvpoChildren->at(nCount)->pvsContent->at(nCount2); 
     370            } 
     371            return sContent; 
     372        } 
     373    } 
     374 
     375    return sContent; 
     376
     377 
     378std::string KMLnode::getDescriptionElement() 
     379
    319380    std::string sContent; 
    320381    for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) 
    321382    { 
    322         if(this->pvpoChildren->at(nCount)->sName.compare("name") == 0) 
     383        if(this->pvpoChildren->at(nCount)->sName.compare("description") == 0) 
    323384        { 
    324385            sContent = this->pvpoChildren->at(nCount)->pvsContent->at(0); 
    325386            for(unsigned short nCount2 = 1; nCount2 < this->pvpoChildren->at(nCount)->pvsContent->size(); nCount2++) 
     387            { 
    326388                sContent += " " + this->pvpoChildren->at(nCount)->pvsContent->at(nCount2); 
     389            } 
    327390            return sContent; 
    328391        } 
     
    331394} 
    332395 
    333 std::string KMLnode::getDescriptionElement() { 
    334     std::string sContent; 
    335     for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) 
    336     { 
    337         if(this->pvpoChildren->at(nCount)->sName.compare("description") == 0) 
    338         { 
    339             sContent = this->pvpoChildren->at(nCount)->pvsContent->at(0); 
    340             for(unsigned short nCount2 = 1; nCount2 < this->pvpoChildren->at(nCount)->pvsContent->size(); nCount2++) 
    341                 sContent += " " + this->pvpoChildren->at(nCount)->pvsContent->at(nCount2); 
    342             return sContent; 
    343         } 
    344     } 
    345     return ""; 
    346 
    347  
    348 short KMLnode::getNumFeatures() { 
     396short KMLnode::getNumFeatures() 
     397
    349398    short nNum = 0; 
    350399    for(unsigned short z = 0; z < this->pvpoChildren->size();z++) 
     
    597646} 
    598647 
    599 void KMLnode::calcExtent(KML *poKMLClass) { 
     648void KMLnode::calcExtent(KML *poKMLClass) 
     649
    600650    KMLnode *poTmp; 
    601651    Coordinate *psCoors; 
     
    604654        return; 
    605655    // Handle Features 
    606     if(poKMLClass->isFeature(this->sName)) { 
     656    if(poKMLClass->isFeature(this->sName)) 
     657    { 
    607658        this->psExtent = new Extent; 
    608659        this->psExtent->dfX1 = this->psExtent->dfX2 = this->psExtent->dfY1 = this->psExtent->dfY2 = 0.0; 
    609660        // Special for Polygons 
    610         if(this->sName.compare("Polygon") == 0) { 
    611             for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) { 
    612                 if(this->pvpoChildren->at(nCount)->sName.compare("outerBoundaryIs") == 0 ||  
    613                     this->pvpoChildren->at(nCount)->sName.compare("innerBoundaryIs") == 0) { 
    614                     if(this->pvpoChildren->at(nCount)->pvpoChildren->size() == 1) { 
     661        if(this->sName.compare("Polygon") == 0) 
     662        { 
     663            for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) 
     664            { 
     665                if(this->pvpoChildren->at(nCount)->sName.compare("outerBoundaryIs") == 0 
     666                   || this->pvpoChildren->at(nCount)->sName.compare("innerBoundaryIs") == 0) 
     667                { 
     668                    if(this->pvpoChildren->at(nCount)->pvpoChildren->size() == 1) 
     669                    { 
    615670                        poTmp = this->pvpoChildren->at(nCount)->pvpoChildren->at(0); 
    616                         for(unsigned short nCount3 = 0; nCount3 < poTmp->pvpoChildren->size(); nCount3++) { 
    617                             if(poTmp->pvpoChildren->at(nCount3)->sName.compare("coordinates") == 0) { 
    618                                 for(unsigned short nCount2 = 0; nCount2 <  
    619                                         poTmp->pvpoChildren->at(nCount3)->pvsContent->size(); nCount2++) { 
     671                        for(unsigned short nCount3 = 0; nCount3 < poTmp->pvpoChildren->size(); nCount3++) 
     672                        { 
     673                            if(poTmp->pvpoChildren->at(nCount3)->sName.compare("coordinates") == 0) 
     674                            { 
     675                                for(unsigned short nCount2 = 0; 
     676                                    nCount2 < poTmp->pvpoChildren->at(nCount3)->pvsContent->size(); nCount2++) 
     677                                { 
    620678                                    psCoors = ParseCoordinate(poTmp->pvpoChildren->at(nCount3)->pvsContent->at(nCount2)); 
    621                                     if(psCoors != NULL) { 
     679                                    if(psCoors != NULL) 
     680                                    { 
    622681                                        if(psCoors->dfLongitude < this->psExtent->dfX1 || this->psExtent->dfX1 == 0) 
    623682                                            this->psExtent->dfX1 = psCoors->dfLongitude; 
     
    637696            } 
    638697        // General for LineStrings and Points 
    639         } else { 
    640             for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) { 
    641                 if(this->pvpoChildren->at(nCount)->sName.compare("coordinates") == 0) { 
     698        } 
     699        else 
     700        { 
     701            for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) 
     702            { 
     703                if(this->pvpoChildren->at(nCount)->sName.compare("coordinates") == 0) 
     704                { 
    642705                    poTmp = this->pvpoChildren->at(nCount); 
    643                     for(unsigned short nCount2 = 0; nCount2 < poTmp->pvsContent->size(); nCount2++) { 
     706                    for(unsigned short nCount2 = 0; nCount2 < poTmp->pvsContent->size(); nCount2++) 
     707                    { 
    644708                        psCoors = ParseCoordinate(poTmp->pvsContent->at(nCount2)); 
    645                         if(psCoors != NULL) { 
     709                        if(psCoors != NULL) 
     710                        { 
    646711                            if(psCoors->dfLongitude < this->psExtent->dfX1 || this->psExtent->dfX1 == 0.0) 
    647712                                this->psExtent->dfX1 = psCoors->dfLongitude; 
     
    659724        } 
    660725    // Summarize Containers 
    661     } else if(poKMLClass->isFeatureContainer(this->sName) ||  
    662             poKMLClass->isContainer(this->sName)) { 
     726    } 
     727    else if( poKMLClass->isFeatureContainer(this->sName) 
     728             || poKMLClass->isContainer(this->sName)) 
     729    { 
    663730        this->psExtent = new Extent; 
    664731        this->psExtent->dfX1 = this->psExtent->dfX2 = this->psExtent->dfY1 = this->psExtent->dfY2 = 0.0; 
    665         for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) { 
     732        for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) 
     733        { 
    666734            this->pvpoChildren->at(nCount)->calcExtent(poKMLClass); 
    667             if(this->pvpoChildren->at(nCount)->psExtent != NULL) { 
     735            if(this->pvpoChildren->at(nCount)->psExtent != NULL) 
     736            { 
    668737                if(this->pvpoChildren->at(nCount)->psExtent->dfX1 < this->psExtent->dfX1 ||  
    669738                        this->psExtent->dfX1 == 0) 
     
    683752} 
    684753 
    685 Extent* KMLnode::getExtents() { 
     754Extent* KMLnode::getExtents() 
     755
    686756    return this->psExtent; 
    687757} 
  • trunk/gdal/ogr/ogrsf_frmts/kml/kmlnode.h

    r12150 r12152  
    4343{ 
    4444private: 
     45 
     46    typedef std::vector<KMLnode*> kml_nodes_t; 
     47    kml_nodes_t* pvpoChildren; 
     48 
     49    typedef std::vector<std::string> kml_content_t; 
     50    kml_content_t* pvsContent; 
     51 
     52    typedef std::vector<Attribute*> kml_attributes_t; 
     53    kml_attributes_t* pvoAttributes; 
     54 
     55    KMLnode *poParent; 
     56    unsigned int nLevel; 
    4557    std::string sName; 
    46     unsigned int nLevel; 
    47     KMLnode *poParent; 
    48     std::vector<KMLnode*> *pvpoChildren; 
    49     std::vector<std::string> *pvsContent; 
    50     std::vector<Attribute*> *pvoAttributes; 
     58 
    5159    Nodetype eType; 
    5260        // Layer number