Changeset 12873

Show
Ignore:
Timestamp:
11/19/07 19:50:47 (9 months ago)
Author:
mloskot
Message:

Fixed const-correctness in KML utility classes (#1831).

Files:

Legend:

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

    r12871 r12873  
    397397} 
    398398 
    399 bool KML::getExtents(double *pdfXMin, double *pdfXMax, double *pdfYMin, double *pdfYMax) { 
    400     if(poCurrent_ != NULL) 
    401     { 
    402         Extent *poXT = poCurrent_->getExtents(); 
     399bool KML::getExtents(double *pdfXMin, double *pdfXMax, double *pdfYMin, double *pdfYMax) 
     400
     401    if( poCurrent_ != NULL ) 
     402    { 
     403        Extent const* poXT = poCurrent_->getExtents(); 
    403404        *pdfXMin = poXT->dfX1; 
    404405        *pdfXMax = poXT->dfX2; 
    405406        *pdfYMin = poXT->dfY1; 
    406407        *pdfYMax = poXT->dfY2; 
     408 
    407409        return TRUE; 
    408410    } 
    409     else 
    410         return FALSE; 
    411 } 
    412  
     411 
     412    return FALSE; 
     413} 
     414 
  • trunk/gdal/ogr/ogrsf_frmts/kml/kmlnode.cpp

    r12872 r12873  
    242242} 
    243243 
    244 Nodetype KMLNode::getType() 
     244Nodetype KMLNode::getType() const 
    245245{ 
    246246    return eType_; 
     
    252252} 
    253253 
    254 std::string KMLNode::getName() 
     254std::string KMLNode::getName() const 
    255255{ 
    256256    return sName_; 
    257257} 
    258258 
    259 void KMLNode::setLevel(unsigned int nLev) 
     259void KMLNode::setLevel(std::size_t nLev) 
    260260{ 
    261261    nLevel_ = nLev; 
    262262} 
    263263 
    264 unsigned int KMLNode::getLevel() 
     264std::size_t KMLNode::getLevel() const 
    265265{ 
    266266    return nLevel_; 
     
    277277} 
    278278 
    279 KMLNode* KMLNode::getParent() 
     279KMLNode* KMLNode::getParent() const 
    280280{ 
    281281    return poParent_; 
     
    287287} 
    288288 
    289 unsigned short KMLNode::countChildren() 
     289std::size_t KMLNode::countChildren() 
    290290{ 
    291291    return pvpoChildren_->size(); 
    292292} 
    293293 
    294 KMLNode* KMLNode::getChild(unsigned short nNum) 
    295 
    296     return pvpoChildren_->at(nNum); 
    297 
    298  
    299 void KMLNode::addContent(std::string const& sCon) 
    300 
    301     pvsContent_->push_back(sCon); 
    302 
    303  
    304 void KMLNode::appendContent(std::string sCon) 
    305 
    306     pvsContent_->at(pvsContent_->size()-1) += sCon; 
    307 
    308  
    309 std::string KMLNode::getContent(unsigned short nNum) 
    310 
    311     if(nNum >= pvsContent_->size()) 
    312         return ""; 
    313     return pvsContent_->at(nNum); 
    314 
    315  
    316 void KMLNode::deleteContent(unsigned short nNum) 
    317 
    318     if(nNum >= pvsContent_->size()) 
    319         return; 
    320     pvsContent_->erase(pvsContent_->begin() + nNum); 
    321 
    322  
    323 unsigned short KMLNode::numContent() 
     294KMLNode* KMLNode::getChild(std::size_t index) const 
     295
     296    return pvpoChildren_->at(index); 
     297
     298 
     299void KMLNode::addContent(std::string const& text) 
     300
     301    pvsContent_->push_back(text); 
     302
     303 
     304void KMLNode::appendContent(std::string const& text) 
     305
     306    std::string& tmp = pvsContent_->at(pvsContent_->size() - 1); 
     307    tmp += text; 
     308
     309 
     310std::string KMLNode::getContent(std::size_t index) const 
     311
     312    std::string tmp; 
     313    if( index < pvsContent_->size() ) 
     314    { 
     315        tmp = pvsContent_->at(index); 
     316    } 
     317    return tmp; 
     318
     319 
     320void KMLNode::deleteContent(std::size_t index) 
     321
     322    if( index < pvsContent_->size() ) 
     323    { 
     324        pvsContent_->erase(pvsContent_->begin() + index); 
     325    } 
     326
     327 
     328std::size_t KMLNode::numContent() 
    324329{ 
    325330    return pvsContent_->size(); 
    326331} 
    327332 
    328 void KMLNode::setLayerNumber(short nNum) 
     333void KMLNode::setLayerNumber(int nNum) 
    329334{ 
    330335    nLayerNumber_ = nNum; 
    331336} 
    332337 
    333 short KMLNode::getLayerNumber() 
     338int KMLNode::getLayerNumber() const 
    334339{ 
    335340    return nLayerNumber_; 
    336341} 
    337342 
    338 KMLNode* KMLNode::getLayer(unsigned short nNum) 
    339 { 
    340     KMLNode *poTmp
     343KMLNode* KMLNode::getLayer(int nNum) 
     344{ 
     345    KMLNode* poTmp = NULL
    341346    if(nLayerNumber_ == nNum) 
    342347        return this; 
    343348 
    344     for(unsigned short nCount = 0; nCount < pvpoChildren_->size(); nCount++) 
    345     { 
    346         if((poTmp = pvpoChildren_->at(nCount)->getLayer(nNum)) != NULL) 
     349    kml_nodes_t::size_type size = pvpoChildren_->size(); 
     350    for( kml_nodes_t::size_type i = 0; i < size; ++i ) 
     351    { 
     352        if((poTmp = pvpoChildren_->at(i)->getLayer(nNum)) != NULL) 
    347353            return poTmp; 
    348354    } 
     
    351357} 
    352358 
    353 std::string KMLNode::getNameElement() 
    354 
    355     std::string sContent; 
    356  
    357     for(unsigned short nCount = 0; nCount < pvpoChildren_->size(); nCount++) 
    358     { 
    359         if(pvpoChildren_->at(nCount)->sName_.compare("name") == 0) 
    360         { 
    361             unsigned int nSize = pvpoChildren_->at(nCount)->pvsContent_->size(); 
    362             if (nSize > 0) 
    363             { 
    364                 sContent = pvpoChildren_->at(nCount)->pvsContent_->at(0); 
    365                 for(unsigned int nCount2 = 1; nCount2 < nSize; nCount2++) 
     359std::string KMLNode::getNameElement() const 
     360
     361    std::string sElem; 
     362    kml_nodes_t::size_type subsize = 0; 
     363    kml_nodes_t::size_type size = pvpoChildren_->size(); 
     364 
     365    for( kml_nodes_t::size_type i = 0; i < size; ++i ) 
     366    { 
     367        if( pvpoChildren_->at(i)->sName_.compare("name") == 0 ) 
     368        { 
     369            subsize = pvpoChildren_->at(i)->pvsContent_->size(); 
     370            if( subsize > 0 ) 
     371            { 
     372                sElem = pvpoChildren_->at(i)->pvsContent_->at(0); 
     373                for( kml_nodes_t::size_type j = 1; j < subsize; ++i ) 
    366374                { 
    367                     sContent += " " + pvpoChildren_->at(nCount)->pvsContent_->at(nCount2); 
     375                    sElem += " " + pvpoChildren_->at(j)->pvsContent_->at(j); 
    368376                } 
    369                 return sContent
     377                return sElem
    370378            } 
    371379            break; 
    372380        } 
    373381    } 
    374  
    375382    return ""; 
    376383} 
    377384 
    378 std::string KMLNode::getDescriptionElement() 
    379 
    380     std::string sContent; 
    381     for(unsigned short nCount = 0; nCount < pvpoChildren_->size(); nCount++) 
    382     { 
    383         if(pvpoChildren_->at(nCount)->sName_.compare("description") == 0) 
    384         { 
    385             unsigned int nSize = pvpoChildren_->at(nCount)->pvsContent_->size(); 
    386             if (nSize > 0) 
    387             { 
    388                 sContent = pvpoChildren_->at(nCount)->pvsContent_->at(0); 
    389                 for(unsigned int nCount2 = 1; nCount2 < nSize; nCount2++) 
     385std::string KMLNode::getDescriptionElement() const 
     386
     387    std::string sElem; 
     388    kml_nodes_t::size_type subsize = 0; 
     389    kml_nodes_t::size_type size = pvpoChildren_->size(); 
     390    for( kml_nodes_t::size_type i = 0; i < size; ++i ) 
     391    { 
     392        if( pvpoChildren_->at(i)->sName_.compare("description") == 0 ) 
     393        { 
     394            subsize = pvpoChildren_->at(i)->pvsContent_->size(); 
     395            if ( subsize > 0 ) 
     396            { 
     397                sElem = pvpoChildren_->at(i)->pvsContent_->at(0); 
     398                for( kml_nodes_t::size_type j = 1; j < subsize; ++j ) 
    390399                { 
    391                     sContent += " " + pvpoChildren_->at(nCount)->pvsContent_->at(nCount2); 
     400                    sElem += " " + pvpoChildren_->at(i)->pvsContent_->at(j); 
    392401                } 
    393                 return sContent
     402                return sElem
    394403            } 
    395404            break; 
     
    399408} 
    400409 
    401 std::size_t KMLNode::getNumFeatures() 
     410std::size_t KMLNode::getNumFeatures() const 
    402411{ 
    403412    std::size_t nNum = 0; 
     
    656665} 
    657666 
    658 void KMLNode::calcExtent(KML *poKMLClass) 
    659 
    660     KMLNode *poTmp; 
    661     Coordinate *psCoors; 
     667void KMLNode::calcExtent(KML *poKML) 
     668
     669    CPLAssert( NULL != poKML ); 
     670 
     671    KMLNode* poTmp = NULL; 
     672    Coordinate* psCoors = NULL; 
    662673     
    663     if(psExtent_ != NULL
     674    if( psExtent_ != NULL
    664675        return; 
     676 
    665677    // Handle Features 
    666     if(poKMLClass->isFeature(sName_)) 
    667     { 
    668         psExtent_ = new Extent
    669         psExtent_->dfX1 = psExtent_->dfX2 = psExtent_->dfY1 = psExtent_->dfY2 = 0.0; 
     678    if(poKML->isFeature(sName_)) 
     679    { 
     680        psExtent_ = new Extent()
     681 
    670682        // Special for Polygons 
    671683        if(sName_.compare("Polygon") == 0) 
     
    735747    // Summarize Containers 
    736748    } 
    737     else if( poKMLClass->isFeatureContainer(sName_) 
    738              || poKMLClass->isContainer(sName_)) 
     749    else if( poKML->isFeatureContainer(sName_) 
     750             || poKML->isContainer(sName_)) 
    739751    { 
    740752        psExtent_ = new Extent; 
     
    742754        for(unsigned short nCount = 0; nCount < pvpoChildren_->size(); nCount++) 
    743755        { 
    744             pvpoChildren_->at(nCount)->calcExtent(poKMLClass); 
     756            pvpoChildren_->at(nCount)->calcExtent(poKML); 
    745757            if(pvpoChildren_->at(nCount)->psExtent_ != NULL) 
    746758            { 
     
    762774} 
    763775 
    764 Extent* KMLNode::getExtents() 
     776Extent const* KMLNode::getExtents() const 
    765777{ 
    766778    return psExtent_; 
  • trunk/gdal/ogr/ogrsf_frmts/kml/kmlnode.h

    r12872 r12873  
    5151    void eliminateEmpty(KML* poKML); 
    5252     
    53     void setType(Nodetype); 
    54     Nodetype getType()
     53    void setType(Nodetype type); 
     54    Nodetype getType() const
    5555     
    56     void setName(std::string const&); 
    57     std::string getName()
     56    void setName(std::string const& name); 
     57    std::string getName() const
    5858     
    59     void setLevel(unsigned int); 
    60     unsigned int getLevel()
     59    void setLevel(std::size_t level); 
     60    std::size_t getLevel() const
    6161     
    62     void addAttribute(Attribute*); 
     62    void addAttribute(Attribute* poAttr); 
    6363     
    6464    void setParent(KMLNode* poNode); 
    65     KMLNode* getParent()
     65    KMLNode* getParent() const
    6666     
    6767    void addChildren(KMLNode* poNode); 
    68     unsigned short countChildren(); 
     68    std::size_t countChildren(); 
    6969     
    70     KMLNode* getChild(unsigned short)
     70    KMLNode* getChild(std::size_t index) const
    7171 
    72     void addContent(std::string const&); 
    73     void appendContent(std::string); 
    74     std::string getContent(unsigned short)
    75     void deleteContent(unsigned short); 
    76     unsigned short numContent(); 
     72    void addContent(std::string const& text); 
     73    void appendContent(std::string const& text); 
     74    std::string getContent(std::size_t index) const
     75    void deleteContent(std::size_t index); 
     76    std::size_t numContent(); 
    7777 
    78     void setLayerNumber(short); 
    79     short getLayerNumber()
     78    void setLayerNumber(int nNum); 
     79    int getLayerNumber() const
    8080 
    81     KMLNode* getLayer(unsigned short); 
     81    KMLNode* getLayer(int); 
    8282 
    83     std::string getNameElement()
    84     std::string getDescriptionElement()
     83    std::string getNameElement() const
     84    std::string getDescriptionElement() const
    8585 
    86     std::size_t getNumFeatures()
     86    std::size_t getNumFeatures() const
    8787    Feature* getFeature(std::size_t nNum); 
    8888 
    89     Extent* getExtents()
     89    Extent const* getExtents() const
    9090 
    9191private: 
     
    101101 
    102102    KMLNode *poParent_; 
    103     unsigned int nLevel_; 
     103    std::size_t nLevel_; 
    104104    std::string sName_; 
    105105 
    106106    Nodetype eType_; 
    107107 
    108     short nLayerNumber_; 
     108    int nLayerNumber_; 
    109109    Extent *psExtent_; 
    110110