LCOV - code coverage report
Current view: directory - ogr - ogrfeaturestyle.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 827 399 48.2 %
Date: 2012-04-28 Functions: 137 62 45.3 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogrfeaturestyle.cpp 23051 2011-09-04 17:59:02Z winkey $
       3                 :  *
       4                 :  * Project:  OpenGIS Simple Features Reference Implementation
       5                 :  * Purpose:  Feature Representation string API
       6                 :  * Author:   Stephane Villeneuve, stephane.v@videotron.ca
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2000-2001, Stephane Villeneuve
      10                 :  *
      11                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      12                 :  * copy of this software and associated documentation files (the "Software"),
      13                 :  * to deal in the Software without restriction, including without limitation
      14                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15                 :  * and/or sell copies of the Software, and to permit persons to whom the
      16                 :  * Software is furnished to do so, subject to the following conditions:
      17                 :  *
      18                 :  * The above copyright notice and this permission notice shall be included
      19                 :  * in all copies or substantial portions of the Software.
      20                 :  *
      21                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27                 :  * DEALINGS IN THE SOFTWARE.
      28                 :  ****************************************************************************/
      29                 : 
      30                 : #include "cpl_conv.h"
      31                 : #include "cpl_string.h"
      32                 : #include "ogr_feature.h"
      33                 : #include "ogr_featurestyle.h"
      34                 : #include "ogr_api.h"
      35                 : 
      36                 : CPL_CVSID("$Id: ogrfeaturestyle.cpp 23051 2011-09-04 17:59:02Z winkey $");
      37                 : 
      38                 : CPL_C_START
      39               0 : void OGRFeatureStylePuller() {}
      40                 : CPL_C_END
      41                 : 
      42                 : /****************************************************************************/
      43                 : /*                Class Parameter (used in the String)                      */
      44                 : /*                                                                          */
      45                 : /*      The order of all parameter MUST be the same than in the definition  */
      46                 : /****************************************************************************/
      47                 : static const OGRStyleParamId asStylePen[] =
      48                 : {
      49                 :     {OGRSTPenColor,"c",FALSE,OGRSTypeString},
      50                 :     {OGRSTPenWidth,"w",TRUE,OGRSTypeDouble},
      51                 :     {OGRSTPenPattern,"p",FALSE,OGRSTypeString}, // georefed,but multiple times.
      52                 :     {OGRSTPenId,"id",FALSE,OGRSTypeString},
      53                 :     {OGRSTPenPerOffset,"dp",TRUE,OGRSTypeDouble},
      54                 :     {OGRSTPenCap,"cap",FALSE,OGRSTypeString},
      55                 :     {OGRSTPenJoin,"j",FALSE,OGRSTypeString},
      56                 :     {OGRSTPenPriority, "l", FALSE, OGRSTypeInteger}
      57                 : };
      58                 : 
      59                 : static const OGRStyleParamId asStyleBrush[] =
      60                 : {
      61                 :     {OGRSTBrushFColor,"fc",FALSE,OGRSTypeString},
      62                 :     {OGRSTBrushBColor,"bc",FALSE,OGRSTypeString},
      63                 :     {OGRSTBrushId,"id",FALSE,OGRSTypeString},
      64                 :     {OGRSTBrushAngle,"a",FALSE,OGRSTypeDouble},
      65                 :     {OGRSTBrushSize,"s",TRUE,OGRSTypeDouble},
      66                 :     {OGRSTBrushDx,"dx",TRUE,OGRSTypeDouble},
      67                 :     {OGRSTBrushDy,"dy",TRUE,OGRSTypeDouble},
      68                 :     {OGRSTBrushPriority,"l",FALSE,OGRSTypeInteger}
      69                 : };
      70                 : 
      71                 : static const OGRStyleParamId asStyleSymbol[] = 
      72                 : {
      73                 :     {OGRSTSymbolId,"id",FALSE,OGRSTypeString},
      74                 :     {OGRSTSymbolAngle,"a",FALSE,OGRSTypeDouble},
      75                 :     {OGRSTSymbolColor,"c",FALSE,OGRSTypeString},
      76                 :     {OGRSTSymbolSize,"s",TRUE,OGRSTypeDouble},
      77                 :     {OGRSTSymbolDx,"dx",TRUE,OGRSTypeDouble},
      78                 :     {OGRSTSymbolDy,"dy",TRUE,OGRSTypeDouble},
      79                 :     {OGRSTSymbolStep,"ds",TRUE,OGRSTypeDouble},
      80                 :     {OGRSTSymbolPerp,"dp",TRUE,OGRSTypeDouble},
      81                 :     {OGRSTSymbolOffset,"di",TRUE,OGRSTypeDouble},
      82                 :     {OGRSTSymbolPriority,"l",FALSE,OGRSTypeInteger},
      83                 :     {OGRSTSymbolFontName,"f",FALSE,OGRSTypeString},
      84                 :     {OGRSTSymbolOColor,"o",FALSE,OGRSTypeString}
      85                 : };
      86                 : 
      87                 : static const OGRStyleParamId asStyleLabel[] =
      88                 : {
      89                 :     {OGRSTLabelFontName,"f",FALSE,OGRSTypeString},
      90                 :     {OGRSTLabelSize,"s",TRUE,OGRSTypeDouble},
      91                 :     {OGRSTLabelTextString,"t",FALSE, OGRSTypeString},
      92                 :     {OGRSTLabelAngle,"a",FALSE,OGRSTypeDouble},
      93                 :     {OGRSTLabelFColor,"c",FALSE,OGRSTypeString},
      94                 :     {OGRSTLabelBColor,"b",FALSE,OGRSTypeString},
      95                 :     {OGRSTLabelPlacement,"m",FALSE, OGRSTypeString},
      96                 :     {OGRSTLabelAnchor,"p",FALSE,OGRSTypeInteger},
      97                 :     {OGRSTLabelDx,"dx",TRUE,OGRSTypeDouble},
      98                 :     {OGRSTLabelDy,"dy",TRUE,OGRSTypeDouble},
      99                 :     {OGRSTLabelPerp,"dp",TRUE,OGRSTypeDouble},
     100                 :     {OGRSTLabelBold,"bo",FALSE,OGRSTypeBoolean},
     101                 :     {OGRSTLabelItalic,"it",FALSE,OGRSTypeBoolean},
     102                 :     {OGRSTLabelUnderline,"un",FALSE, OGRSTypeBoolean},
     103                 :     {OGRSTLabelPriority,"l",FALSE, OGRSTypeInteger},
     104                 :     {OGRSTLabelStrikeout,"st",FALSE, OGRSTypeBoolean},
     105                 :     {OGRSTLabelStretch,"w",FALSE, OGRSTypeDouble},
     106                 :     {OGRSTLabelAdjHor,"ah",FALSE, OGRSTypeString},
     107                 :     {OGRSTLabelAdjVert,"av",FALSE, OGRSTypeString},
     108                 :     {OGRSTLabelHColor,"h",FALSE,OGRSTypeString},
     109                 :     {OGRSTLabelOColor,"o",FALSE,OGRSTypeString}
     110                 : };
     111                 : 
     112                 : /* ======================================================================== */
     113                 : /* OGRStyleMgr                                                              */
     114                 : /* ======================================================================== */
     115                 : 
     116                 : /****************************************************************************/
     117                 : /*             OGRStyleMgr::OGRStyleMgr(OGRStyleTable *poDataSetStyleTable) */
     118                 : /*                                                                          */
     119                 : /****************************************************************************/
     120                 : /**
     121                 :  * \brief Constructor.
     122                 :  *
     123                 :  * This method is the same as the C function OGR_SM_Create()
     124                 :  * 
     125                 :  * @param poDataSetStyleTable (currently unused, reserved for future use), pointer 
     126                 :  * to OGRStyleTable. Pass NULL for now.
     127                 :  */
     128             210 : OGRStyleMgr::OGRStyleMgr(OGRStyleTable *poDataSetStyleTable)
     129                 : {
     130             210 :     m_poDataSetStyleTable = poDataSetStyleTable;
     131             210 :     m_pszStyleString = NULL;
     132             210 : }
     133                 : 
     134                 : /************************************************************************/
     135                 : /*                            OGR_SM_Create()                           */
     136                 : /************************************************************************/
     137                 : /**
     138                 :  * \brief OGRStyleMgr factory.
     139                 :  *
     140                 :  * This function is the same as the C++ method OGRStyleMgr::OGRStyleMgr().
     141                 :  * 
     142                 :  * @param hStyleTable pointer to OGRStyleTable or NULL if not working with
     143                 :  *  a style table.
     144                 :  * 
     145                 :  * @return an handle to the new style manager object.
     146                 :  */
     147                 : 
     148              14 : OGRStyleMgrH OGR_SM_Create( OGRStyleTableH hStyleTable )
     149                 : 
     150                 : {
     151              14 :     return (OGRStyleMgrH) new OGRStyleMgr( (OGRStyleTable *) hStyleTable );
     152                 : }
     153                 : 
     154                 : 
     155                 : /****************************************************************************/
     156                 : /*             OGRStyleMgr::~OGRStyleMgr()                                  */
     157                 : /*                                                                          */
     158                 : /****************************************************************************/
     159                 : /**
     160                 :  * \brief Destructor.
     161                 :  *
     162                 :  * This method is the same as the C function OGR_SM_Destroy()
     163                 :  */
     164             210 : OGRStyleMgr::~OGRStyleMgr()
     165                 : {
     166             210 :     if ( m_pszStyleString )
     167             170 :         CPLFree(m_pszStyleString);
     168             210 : }
     169                 : 
     170                 : /************************************************************************/
     171                 : /*                           OGR_SM_Destroy()                            */
     172                 : /************************************************************************/
     173                 : /**
     174                 :  * \brief Destroy Style Manager
     175                 :  *
     176                 :  * This function is the same as the C++ method OGRStyleMgr::~OGRStyleMgr().
     177                 :  *
     178                 :  * @param hSM handle to the style manager to destroy.
     179                 :  */
     180                 : 
     181              14 : void OGR_SM_Destroy( OGRStyleMgrH hSM )
     182                 : 
     183                 : {
     184              14 :     delete (OGRStyleMgr *) hSM;
     185              14 : }
     186                 : 
     187                 : 
     188                 : /****************************************************************************/
     189                 : /*      GBool OGRStyleMgr::SetFeatureStyleString(OGRFeature *poFeature,     */
     190                 : /*                                       char *pszStyleString,              */
     191                 : /*                                       GBool bNoMatching)                 */
     192                 : /*      Set the gived representation to the feature,                        */
     193                 : /*      if bNoMatching == TRUE, don't try to find it in the styletable      */
     194                 : /*      otherwize, we will use the name defined in the styletable           */
     195                 : /****************************************************************************/
     196                 : 
     197                 : /**
     198                 :  * \brief Set a style in a feature
     199                 :  *
     200                 :  * @param poFeature       the feature object to store the style in
     201                 :  * @param pszStyleString  the style to store
     202                 :  * @param bNoMatching     TRUE to lookup the style in the style table and 
     203                 :  *  add the name to the feature
     204                 :  *
     205                 :  * @return TRUE on success, FALSE on error.
     206                 :  */
     207                 :  
     208               0 : GBool OGRStyleMgr::SetFeatureStyleString(OGRFeature *poFeature, 
     209                 :                                          const char *pszStyleString,
     210                 :                                          GBool bNoMatching)
     211                 : {
     212                 :     const char *pszName;
     213               0 :     if (poFeature == FALSE)
     214               0 :       return FALSE;
     215                 :     
     216               0 :     if (pszStyleString == NULL)
     217               0 :       poFeature->SetStyleString("");
     218               0 :     else if (bNoMatching == TRUE)
     219               0 :       poFeature->SetStyleString(pszStyleString);
     220               0 :     else if ((pszName = GetStyleName(pszStyleString)) != NULL)
     221               0 :       poFeature->SetStyleString(pszName);
     222                 :     else
     223               0 :       poFeature->SetStyleString(pszStyleString);
     224                 : 
     225               0 :     return TRUE;
     226                 : }
     227                 : 
     228                 : /****************************************************************************/
     229                 : /*            const char *OGRStyleMgr::InitFromFeature(OGRFeature *)        */
     230                 : /*                                                                          */
     231                 : /****************************************************************************/
     232                 : 
     233                 : /**
     234                 :  * \brief Initialize style manager from the style string of a feature.
     235                 :  *
     236                 :  * This method is the same as the C function OGR_SM_InitFromFeature().
     237                 :  *
     238                 :  * @param poFeature feature object from which to read the style.
     239                 :  *
     240                 :  * @return a reference to the style string read from the feature, or NULL
     241                 :  * in case of error.. 
     242                 :  */
     243                 : 
     244              22 : const char *OGRStyleMgr::InitFromFeature(OGRFeature *poFeature)
     245                 : {
     246              22 :     CPLFree(m_pszStyleString);
     247              22 :     m_pszStyleString = NULL;
     248                 : 
     249              22 :     if (poFeature)
     250              22 :       InitStyleString(poFeature->GetStyleString());
     251                 :     else
     252               0 :       m_pszStyleString = NULL;
     253                 : 
     254              22 :     return m_pszStyleString;
     255                 : 
     256                 : }
     257                 : 
     258                 : /************************************************************************/
     259                 : /*                     OGR_SM_InitFromFeature()                         */
     260                 : /************************************************************************/
     261                 : 
     262                 : /**
     263                 :  * \brief Initialize style manager from the style string of a feature.
     264                 :  *
     265                 :  * This function is the same as the C++ method 
     266                 :  * OGRStyleMgr::InitFromFeature().
     267                 :  *
     268                 :  * @param hSM handle to the style manager.
     269                 :  * @param hFeat handle to the new feature from which to read the style.
     270                 :  *
     271                 :  * @return a reference to the style string read from the feature, or NULL
     272                 :  * in case of error.
     273                 :  */ 
     274                 : 
     275              14 : const char *OGR_SM_InitFromFeature(OGRStyleMgrH hSM, 
     276                 :                                            OGRFeatureH hFeat)
     277                 : 
     278                 : {
     279              14 :     VALIDATE_POINTER1( hSM, "OGR_SM_InitFromFeature", NULL );
     280              14 :     VALIDATE_POINTER1( hFeat, "OGR_SM_InitFromFeature", NULL );
     281                 : 
     282              14 :     return ((OGRStyleMgr *) hSM)->InitFromFeature((OGRFeature *)hFeat);
     283                 : }
     284                 : 
     285                 : /****************************************************************************/
     286                 : /*            GBool OGRStyleMgr::InitStyleString(char *pszStyleString)      */
     287                 : /*                                                                          */
     288                 : /****************************************************************************/
     289                 : 
     290                 : /**
     291                 :  * \brief Initialize style manager from the style string.
     292                 :  *
     293                 :  * This method is the same as the C function OGR_SM_InitStyleString().
     294                 :  *
     295                 :  * @param pszStyleString the style string to use (can be NULL).
     296                 :  *
     297                 :  * @return TRUE on success, FALSE on errors. 
     298                 :  */
     299             370 : GBool OGRStyleMgr::InitStyleString(const char *pszStyleString)
     300                 : {
     301             370 :     CPLFree(m_pszStyleString);
     302             370 :     m_pszStyleString = NULL;
     303                 : 
     304             370 :     if (pszStyleString && pszStyleString[0] == '@')
     305               0 :       m_pszStyleString = CPLStrdup(GetStyleByName(pszStyleString));
     306                 :     else
     307             370 :       m_pszStyleString = NULL;
     308                 : 
     309             370 :     if (m_pszStyleString == NULL && pszStyleString)
     310             146 :       m_pszStyleString = CPLStrdup(pszStyleString);
     311                 :    
     312                 : 
     313                 :     
     314             370 :     return TRUE;
     315                 : }    
     316                 : 
     317                 : /************************************************************************/
     318                 : /*                     OGR_SM_InitStyleString()                         */
     319                 : /************************************************************************/
     320                 : 
     321                 : /**
     322                 :  * \brief Initialize style manager from the style string.
     323                 :  *
     324                 :  * This function is the same as the C++ method OGRStyleMgr::InitStyleString().
     325                 :  *
     326                 :  * @param hSM handle to the style manager.
     327                 :  * @param pszStyleString the style string to use (can be NULL).
     328                 :  *
     329                 :  * @return TRUE on success, FALSE on errors. 
     330                 :  */ 
     331                 : 
     332               0 : int OGR_SM_InitStyleString(OGRStyleMgrH hSM, const char *pszStyleString)
     333                 : 
     334                 : {
     335               0 :     VALIDATE_POINTER1( hSM, "OGR_SM_InitStyleString", FALSE );
     336                 : 
     337               0 :     return ((OGRStyleMgr *) hSM)->InitStyleString(pszStyleString);
     338                 : }
     339                 : 
     340                 : 
     341                 : /****************************************************************************/
     342                 : /*      const char *OGRStyleMgr::GetStyleName(const char *pszStyleString)   */
     343                 : /*                                                                          */
     344                 : /****************************************************************************/
     345                 : 
     346                 : /**
     347                 :  * \brief Get the name of a style from the style table.
     348                 :  *
     349                 :  * @param pszStyleString  the style to search for, or NULL to use the style
     350                 :  *   currently stored in the manager.
     351                 :  *
     352                 :  * @return The name if found, or NULL on error.
     353                 :  */
     354                 : 
     355               0 : const char *OGRStyleMgr::GetStyleName(const char *pszStyleString)
     356                 : {
     357                 : 
     358                 :     // SECURITY:  the unit and the value for all parameter should be the same,
     359                 :     // a text comparaison is executed .
     360                 : 
     361                 :     const char *pszStyle;
     362                 : 
     363               0 :     if (pszStyleString)
     364               0 :       pszStyle = pszStyleString;
     365                 :     else
     366               0 :       pszStyle = m_pszStyleString;
     367                 : 
     368               0 :     if (pszStyle)
     369                 :     {
     370               0 :         if (m_poDataSetStyleTable)
     371               0 :           return  m_poDataSetStyleTable->GetStyleName(pszStyle);
     372                 :     }
     373               0 :     return NULL;
     374                 : }
     375                 : /****************************************************************************/
     376                 : /*      const char *OGRStyleMgr::GetStyleByName(const char *pszStyleName)   */
     377                 : /*                                                                          */
     378                 : /****************************************************************************/
     379                 : 
     380                 : /**
     381                 :  * \brief find a style in the current style table.
     382                 :  *
     383                 :  *
     384                 :  * @param pszStyleName the name of the style to add.
     385                 :  *
     386                 :  * @return the style string matching the name or NULL if not found or error.
     387                 :  */
     388               0 : const char *OGRStyleMgr::GetStyleByName(const char *pszStyleName)
     389                 : {    
     390               0 :     if (m_poDataSetStyleTable)
     391                 :     {
     392               0 :         return  m_poDataSetStyleTable->Find(pszStyleName);
     393                 :     }
     394               0 :     return NULL;
     395                 : }
     396                 :     
     397                 : /****************************************************************************/
     398                 : /*            GBool OGRStyleMgr::AddStyle(char *pszStyleName,               */
     399                 : /*                                   char *pszStyleString)                  */
     400                 : /*                                                                          */
     401                 : /****************************************************************************/
     402                 : 
     403                 : /**
     404                 :  * \brief Add a style to the current style table.
     405                 :  *
     406                 :  * This method is the same as the C function OGR_SM_AddStyle().
     407                 :  *
     408                 :  * @param pszStyleName the name of the style to add.
     409                 :  * @param pszStyleString the style string to use, or NULL to use the style 
     410                 :  *                       stored in the manager.
     411                 :  *
     412                 :  * @return TRUE on success, FALSE on errors. 
     413                 :  */
     414                 : 
     415              84 : GBool OGRStyleMgr::AddStyle(const char *pszStyleName, 
     416                 :                             const char *pszStyleString)
     417                 : {
     418                 :     const char *pszStyle;
     419                 : 
     420              84 :     if (pszStyleString)
     421               0 :       pszStyle = pszStyleString;
     422                 :     else
     423              84 :       pszStyle = m_pszStyleString;
     424                 : 
     425              84 :     if (m_poDataSetStyleTable)
     426                 :     {
     427              84 :         return m_poDataSetStyleTable->AddStyle(pszStyleName, pszStyle);
     428                 :     }
     429               0 :     return FALSE;
     430                 : }
     431                 : 
     432                 : 
     433                 : /************************************************************************/
     434                 : /*                     OGR_SM_AddStyle()                         */
     435                 : /************************************************************************/
     436                 : 
     437                 : /**
     438                 :  * \brief Add a style to the current style table.
     439                 :  *
     440                 :  * This function is the same as the C++ method OGRStyleMgr::AddStyle().
     441                 :  *
     442                 :  * @param hSM handle to the style manager.
     443                 :  * @param pszStyleName the name of the style to add.
     444                 :  * @param pszStyleString the style string to use, or NULL to use the style 
     445                 :  *                       stored in the manager.
     446                 :  *
     447                 :  * @return TRUE on success, FALSE on errors. 
     448                 :  */ 
     449                 : 
     450               0 : int OGR_SM_AddStyle(OGRStyleMgrH hSM, const char *pszStyleName, 
     451                 :                     const char *pszStyleString)
     452                 : {
     453               0 :     VALIDATE_POINTER1( hSM, "OGR_SM_AddStyle", FALSE );
     454               0 :     VALIDATE_POINTER1( pszStyleName, "OGR_SM_AddStyle", FALSE );
     455                 :     
     456               0 :     return ((OGRStyleMgr *) hSM)->AddStyle( pszStyleName, pszStyleString);
     457                 : }
     458                 : 
     459                 : 
     460                 : /****************************************************************************/
     461                 : /*            const char *OGRStyleMgr::GetStyleString(OGRFeature *)         */
     462                 : /*                                                                          */
     463                 : /****************************************************************************/
     464                 : 
     465                 : /**
     466                 :  * \brief Get the style string from the style manager.
     467                 :  *
     468                 :  * @param poFeature feature object from which to read the style or NULL to
     469                 :  *                  get the style string stored in the manager.
     470                 :  *
     471                 :  * @return the style string stored in the feature or the style string stored
     472                 :  *          in the style manager if poFeature is NULL
     473                 :  *
     474                 :  * NOTE: this method will call OGRStyleMgr::InitFromFeature() if poFeature is
     475                 :  *       not NULL and replace the style string stored in the style manager
     476                 :  */
     477                 : 
     478             132 : const char *OGRStyleMgr::GetStyleString(OGRFeature *poFeature)
     479                 : {
     480             132 :     if (poFeature == NULL)
     481             132 :       return m_pszStyleString;
     482                 :     else
     483               0 :       return InitFromFeature(poFeature);
     484                 : }
     485                 : 
     486                 : /****************************************************************************/
     487                 : /*            GBool OGRStyleMgr::AddPart(const char *pszPart)               */
     488                 : /*            Add a new part in the current style                           */
     489                 : /****************************************************************************/
     490                 : 
     491                 : /**
     492                 :  * \brief Add a part (style string) to the current style.
     493                 :  *
     494                 :  * @param pszPart the style string defining the part to add.
     495                 :  *
     496                 :  * @return TRUE on success, FALSE on errors. 
     497                 :  */
     498                 : 
     499               0 : GBool OGRStyleMgr::AddPart(const char *pszPart)
     500                 : {
     501                 :     char *pszTmp; 
     502               0 :     if (pszPart)
     503                 :     {
     504               0 :         if (m_pszStyleString)
     505                 :         {
     506                 :             pszTmp = CPLStrdup(CPLString().Printf("%s;%s",m_pszStyleString,
     507               0 :                                           pszPart));
     508               0 :             CPLFree(m_pszStyleString);
     509               0 :             m_pszStyleString = pszTmp;
     510                 :         }
     511                 :         else
     512                 :         {
     513               0 :               pszTmp= CPLStrdup(CPLString().Printf("%s",pszPart));
     514               0 :               CPLFree(m_pszStyleString);
     515               0 :               m_pszStyleString = pszTmp;
     516                 :         }
     517               0 :         return TRUE;
     518                 :     }
     519                 : 
     520               0 :     return FALSE;
     521                 : }
     522                 : 
     523                 : /****************************************************************************/
     524                 : /*            GBool OGRStyleMgr::AddPart(OGRStyleTool *)                    */
     525                 : /*            Add a new part in the current style                           */
     526                 : /****************************************************************************/
     527                 : 
     528                 : /**
     529                 :  * \brief Add a part (style tool) to the current style.
     530                 :  *
     531                 :  * This method is the same as the C function OGR_SM_AddPart().
     532                 :  *
     533                 :  * @param poStyleTool the style tool defining the part to add.
     534                 :  *
     535                 :  * @return TRUE on success, FALSE on errors. 
     536                 :  */ 
     537                 : 
     538             186 : GBool OGRStyleMgr::AddPart(OGRStyleTool *poStyleTool)
     539                 : {
     540                 :     char *pszTmp;
     541             186 :     if (poStyleTool && poStyleTool->GetStyleString())
     542                 :     {
     543             186 :         if (m_pszStyleString)
     544                 :         {
     545                 :             pszTmp = CPLStrdup(CPLString().Printf("%s;%s",m_pszStyleString,
     546              54 :                                         poStyleTool->GetStyleString()));
     547              54 :             CPLFree(m_pszStyleString);
     548              54 :             m_pszStyleString = pszTmp;
     549                 :         }
     550                 :         else
     551                 :         {
     552                 :               pszTmp= CPLStrdup(CPLString().Printf("%s",
     553             132 :                                         poStyleTool->GetStyleString()));
     554             132 :               CPLFree(m_pszStyleString);
     555             132 :               m_pszStyleString = pszTmp;
     556                 :         }
     557             186 :         return TRUE;
     558                 :     }
     559                 : 
     560               0 :     return FALSE;
     561                 : }
     562                 :     
     563                 : /************************************************************************/
     564                 : /*                     OGR_SM_AddPart()                                 */
     565                 : /************************************************************************/
     566                 : 
     567                 : /**
     568                 :  * \brief Add a part (style tool) to the current style.
     569                 :  *
     570                 :  * This function is the same as the C++ method OGRStyleMgr::AddPart().
     571                 :  *
     572                 :  * @param hSM handle to the style manager.
     573                 :  * @param hST the style tool defining the part to add.
     574                 :  *
     575                 :  * @return TRUE on success, FALSE on errors. 
     576                 :  */ 
     577                 : 
     578               0 : int OGR_SM_AddPart(OGRStyleMgrH hSM, OGRStyleToolH hST)
     579                 : 
     580                 : {
     581               0 :     VALIDATE_POINTER1( hSM, "OGR_SM_InitStyleString", FALSE );
     582               0 :     VALIDATE_POINTER1( hST, "OGR_SM_InitStyleString", FALSE );
     583                 : 
     584               0 :     return ((OGRStyleMgr *) hSM)->AddPart((OGRStyleTool *)hST);
     585                 : }
     586                 : 
     587                 : 
     588                 : /****************************************************************************/
     589                 : /*            int OGRStyleMgr::GetPartCount(const char *pszStyleString)     */
     590                 : /*            return the number of part in the stylestring                  */
     591                 : /* FIXME: this function should actually parse style string instead of simple*/
     592                 : /*        semicolon counting, we should not count broken and empty parts.   */
     593                 : /****************************************************************************/
     594                 : 
     595                 : /**
     596                 :  * \brief Get the number of parts in a style.
     597                 :  *
     598                 :  * This method is the same as the C function OGR_SM_GetPartCount().
     599                 :  *
     600                 :  * @param pszStyleString (optional) the style string on which to operate.
     601                 :  * If NULL then the current style string stored in the style manager is used.
     602                 :  *
     603                 :  * @return the number of parts (style tools) in the style. 
     604                 :  */ 
     605                 : 
     606             206 : int OGRStyleMgr::GetPartCount(const char *pszStyleString)
     607                 : {
     608                 :     const char *pszPart;
     609             206 :     int nPartCount = 1;
     610                 :     const char *pszString;
     611                 :     const char *pszStrTmp;
     612                 : 
     613             206 :     if (pszStyleString != NULL)
     614               0 :       pszString = pszStyleString;
     615                 :     else
     616             206 :       pszString = m_pszStyleString;
     617                 : 
     618             206 :     if (pszString == NULL)
     619              86 :       return 0;
     620                 : 
     621             120 :     pszStrTmp = pszString;
     622                 :     // Search for parts separated by semicolons not counting the possible
     623                 :     // semicolon at the and of string.
     624             244 :     while ((pszPart = strstr(pszStrTmp, ";")) != NULL && pszPart[1] != '\0')
     625                 :     {
     626               4 :         pszStrTmp = &pszPart[1];
     627               4 :         nPartCount++;
     628                 :     }
     629             120 :     return nPartCount;
     630                 : }
     631                 : 
     632                 : /************************************************************************/
     633                 : /*                     OGR_SM_GetPartCount()                            */
     634                 : /************************************************************************/
     635                 : 
     636                 : /**
     637                 :  * \brief Get the number of parts in a style.
     638                 :  *
     639                 :  * This function is the same as the C++ method OGRStyleMgr::GetPartCount().
     640                 :  *
     641                 :  * @param hSM handle to the style manager.
     642                 :  * @param pszStyleString (optional) the style string on which to operate.
     643                 :  * If NULL then the current style string stored in the style manager is used.
     644                 :  *
     645                 :  * @return the number of parts (style tools) in the style. 
     646                 :  */ 
     647                 : 
     648              14 : int OGR_SM_GetPartCount(OGRStyleMgrH hSM, const char *pszStyleString)
     649                 : 
     650                 : {
     651              14 :     VALIDATE_POINTER1( hSM, "OGR_SM_InitStyleString", FALSE );
     652                 : 
     653              14 :     return ((OGRStyleMgr *) hSM)->GetPartCount(pszStyleString);
     654                 : }
     655                 : 
     656                 : 
     657                 : /****************************************************************************/
     658                 : /*            OGRStyleTool *OGRStyleMgr::GetPart(int nPartId,               */
     659                 : /*                                 const char *pszStyleString)              */
     660                 : /*                                                                          */
     661                 : /*     Return a StyleTool of the type of the wanted part, could return NULL */
     662                 : /****************************************************************************/
     663                 : 
     664                 : /**
     665                 :  * \brief Fetch a part (style tool) from the current style.
     666                 :  *
     667                 :  * This method is the same as the C function OGR_SM_GetPart().
     668                 :  *
     669                 :  * This method instanciates a new object that should be freed with OGR_ST_Destroy().
     670                 :  *
     671                 :  * @param nPartId the part number (0-based index).
     672                 :  * @param pszStyleString (optional) the style string on which to operate.
     673                 :  * If NULL then the current style string stored in the style manager is used.
     674                 :  *
     675                 :  * @return OGRStyleTool of the requested part (style tools) or NULL on error.
     676                 :  */ 
     677                 : 
     678              72 : OGRStyleTool *OGRStyleMgr::GetPart(int nPartId, 
     679                 :                                    const char *pszStyleString)
     680                 : {
     681                 :     char **papszStyleString;
     682                 :     const char *pszStyle;
     683                 :     const char *pszString;
     684              72 :     OGRStyleTool    *poStyleTool = NULL;
     685                 : 
     686              72 :     if (pszStyleString)
     687               0 :       pszStyle = pszStyleString; 
     688                 :     else
     689              72 :       pszStyle = m_pszStyleString;
     690                 : 
     691              72 :     if (pszStyle == NULL)
     692               0 :       return NULL;
     693                 : 
     694                 :     papszStyleString = CSLTokenizeString2(pszStyle, ";",
     695                 :                                           CSLT_HONOURSTRINGS
     696                 :                                           | CSLT_PRESERVEQUOTES
     697              72 :                                           | CSLT_PRESERVEESCAPES );
     698                 : 
     699              72 :     pszString = CSLGetField( papszStyleString, nPartId );
     700                 :     
     701              72 :     if ( strlen(pszString) > 0 )
     702                 :     {
     703              70 :         poStyleTool = CreateStyleToolFromStyleString(pszString);
     704              70 :         if ( poStyleTool )
     705              70 :             poStyleTool->SetStyleString(pszString);
     706                 :     }
     707                 : 
     708              72 :     CSLDestroy( papszStyleString );
     709                 : 
     710              72 :     return poStyleTool;
     711                 : } 
     712                 : 
     713                 : /************************************************************************/
     714                 : /*                     OGR_SM_GetPart()                                 */
     715                 : /************************************************************************/
     716                 : 
     717                 : /**
     718                 :  * \brief Fetch a part (style tool) from the current style.
     719                 :  *
     720                 :  * This function is the same as the C++ method OGRStyleMgr::GetPart().
     721                 :  *
     722                 :  * This function instanciates a new object that should be freed with OGR_ST_Destroy().
     723                 :  *
     724                 :  * @param hSM handle to the style manager.
     725                 :  * @param nPartId the part number (0-based index).
     726                 :  * @param pszStyleString (optional) the style string on which to operate.
     727                 :  * If NULL then the current style string stored in the style manager is used.
     728                 :  *
     729                 :  * @return OGRStyleToolH of the requested part (style tools) or NULL on error.
     730                 :  */ 
     731                 : 
     732              10 : OGRStyleToolH OGR_SM_GetPart(OGRStyleMgrH hSM, int nPartId, 
     733                 :                              const char *pszStyleString)
     734                 : 
     735                 : {
     736              10 :     VALIDATE_POINTER1( hSM, "OGR_SM_InitStyleString", NULL );
     737                 : 
     738              10 :     return (OGRStyleToolH) ((OGRStyleMgr *) hSM)->GetPart(nPartId, pszStyleString);
     739                 : }
     740                 : 
     741                 : 
     742                 : /****************************************************************************/
     743                 : /* OGRStyleTool *CreateStyleToolFromStyleString(const char *pszStyleString) */
     744                 : /*                                                                          */
     745                 : /* create a Style tool from the gived StyleString, it should contain only a */
     746                 : /* part of a StyleString                                                    */
     747                 : /****************************************************************************/
     748              70 : OGRStyleTool *OGRStyleMgr::CreateStyleToolFromStyleString(const char *
     749                 :                                                           pszStyleString)
     750                 : {
     751                 :     char **papszToken = CSLTokenizeString2(pszStyleString,"();",
     752                 :                                            CSLT_HONOURSTRINGS
     753                 :                                            | CSLT_PRESERVEQUOTES
     754              70 :                                            | CSLT_PRESERVEESCAPES );
     755                 :     OGRStyleTool   *poStyleTool;
     756                 :         
     757              70 :     if (CSLCount(papszToken) <2)
     758               0 :         poStyleTool = NULL;
     759              70 :     else if (EQUAL(papszToken[0],"PEN"))
     760              64 :         poStyleTool = new OGRStylePen();
     761               6 :     else if (EQUAL(papszToken[0],"BRUSH"))
     762               2 :         poStyleTool = new OGRStyleBrush();
     763               4 :     else if (EQUAL(papszToken[0],"SYMBOL"))
     764               0 :         poStyleTool = new OGRStyleSymbol();
     765               4 :     else if (EQUAL(papszToken[0],"LABEL"))
     766               4 :         poStyleTool = new OGRStyleLabel();
     767                 :     else 
     768               0 :         poStyleTool = NULL;
     769                 : 
     770              70 :     CSLDestroy( papszToken );
     771                 : 
     772              70 :     return poStyleTool;
     773                 : }
     774                 : 
     775                 : /* ======================================================================== */
     776                 : /*                OGRStyleTable                                             */
     777                 : /*     Object Used to manage and store a styletable                         */
     778                 : /* ======================================================================== */
     779                 : 
     780                 : 
     781                 : /****************************************************************************/
     782                 : /*              OGRStyleTable::OGRStyleTable()                              */
     783                 : /*                                                                          */
     784                 : /****************************************************************************/
     785              12 : OGRStyleTable::OGRStyleTable()
     786                 : {
     787              12 :     m_papszStyleTable = NULL;
     788              12 : }
     789                 : 
     790                 : /************************************************************************/
     791                 : /*                            OGR_STBL_Create()                           */
     792                 : /************************************************************************/
     793                 : /**
     794                 :  * \brief OGRStyleTable factory.
     795                 :  *
     796                 :  * This function is the same as the C++ method OGRStyleTable::OGRStyleTable().
     797                 :  * 
     798                 :  * 
     799                 :  * @return an handle to the new style table object.
     800                 :  */
     801                 : 
     802               0 : OGRStyleTableH OGR_STBL_Create( void )
     803                 : 
     804                 : {
     805               0 :     return (OGRStyleTableH) new OGRStyleTable( );
     806                 : }
     807                 : 
     808                 : /****************************************************************************/
     809                 : /*                void OGRStyleTable::Clear()                               */
     810                 : /*                                                                          */
     811                 : /****************************************************************************/
     812                 : 
     813                 : /** 
     814                 :  * \brief Clear a style table. 
     815                 :  * 
     816                 :  */  
     817                 : 
     818              12 : void OGRStyleTable::Clear()
     819                 : {
     820              12 :     if (m_papszStyleTable)
     821              12 :       CSLDestroy(m_papszStyleTable);
     822              12 :     m_papszStyleTable = NULL;
     823              12 : }
     824                 : 
     825                 : /****************************************************************************/
     826                 : /*          OGRStyleTable::~OGRStyleTable()                                 */
     827                 : /*                                                                          */
     828                 : /****************************************************************************/
     829              12 : OGRStyleTable::~OGRStyleTable()
     830                 : {
     831              12 :     Clear();
     832              12 : }
     833                 : 
     834                 : 
     835                 : /************************************************************************/
     836                 : /*                           OGR_STBL_Destroy()                            */
     837                 : /************************************************************************/
     838                 : /**
     839                 :  * \brief Destroy Style Table
     840                 :  *
     841                 :  * @param hSTBL handle to the style table to destroy.
     842                 :  */
     843                 : 
     844               0 : void OGR_STBL_Destroy( OGRStyleTableH hSTBL )
     845                 : 
     846                 : {
     847               0 :     delete (OGRStyleTable *) hSTBL;
     848               0 : }
     849                 : 
     850                 : /****************************************************************************/
     851                 : /*    const char *OGRStyleTable::GetStyleName(const char *pszStyleString)   */
     852                 : /*                                                                          */
     853                 : /*    return the Name of a gived stylestring otherwise NULL                 */
     854                 : /****************************************************************************/
     855                 : 
     856                 : /**
     857                 :  * \brief Get style name by style string.
     858                 :  *
     859                 :  * @param pszStyleString the style string to look up.
     860                 :  *
     861                 :  * @return the Name of the matching style string or NULL on error.
     862                 :  */
     863                 : 
     864               0 : const char *OGRStyleTable::GetStyleName(const char *pszStyleString)
     865                 : {
     866                 :     int i;
     867                 :     const char *pszStyleStringBegin;
     868                 : 
     869               0 :     for (i=0;i<CSLCount(m_papszStyleTable);i++)
     870                 :     {
     871               0 :         pszStyleStringBegin = strstr(m_papszStyleTable[i],":");
     872                 : 
     873               0 :         if (pszStyleStringBegin && EQUAL(&pszStyleStringBegin[1],
     874                 :                                          pszStyleString))
     875                 :         {
     876                 :             int nColon;
     877                 : 
     878               0 :             osLastRequestedStyleName = m_papszStyleTable[i];
     879               0 :             nColon = osLastRequestedStyleName.find( ':' );
     880               0 :             if( nColon != -1 )
     881                 :                 osLastRequestedStyleName = 
     882               0 :                     osLastRequestedStyleName.substr(0,nColon);
     883                 : 
     884               0 :             return osLastRequestedStyleName;
     885                 :         }
     886                 :     }
     887                 :         
     888               0 :     return NULL;
     889                 : }
     890                 : 
     891                 : /****************************************************************************/
     892                 : /*            GBool OGRStyleTable::AddStyle(char *pszName,                  */
     893                 : /*                                          char *pszStyleString)           */
     894                 : /*                                                                          */
     895                 : /*   Add a new style in the table, no comparison will be done on the       */
     896                 : /*   Style string, only on the name, TRUE success, FALSE error              */
     897                 : /****************************************************************************/
     898                 : 
     899                 : /**
     900                 :  * \brief Add a new style in the table.
     901                 :  * No comparison will be done on the
     902                 :  * Style string, only on the name.
     903                 :  *
     904                 :  * @param pszName the name the style to add.
     905                 :  * @param pszStyleString the style string to add.
     906                 :  *
     907                 :  * @return TRUE on success, FALSE on error
     908                 :  */
     909                 : 
     910              90 : GBool OGRStyleTable::AddStyle(const char *pszName, const char *pszStyleString)
     911                 : {
     912                 :     int nPos;
     913                 :     
     914              90 :     if (pszName && pszStyleString)
     915                 :     {
     916              84 :         if ((nPos = IsExist(pszName)) != -1)
     917               0 :           return FALSE;
     918                 : 
     919                 :         m_papszStyleTable = CSLAddString(m_papszStyleTable,
     920              84 :                               CPLString().Printf("%s:%s",pszName,pszStyleString));
     921              84 :         return TRUE;
     922                 :     }
     923               6 :     return FALSE;
     924                 : }
     925                 : 
     926                 : /****************************************************************************/
     927                 : /*            GBool OGRStyleTable::RemoveStyle(char *pszName)               */
     928                 : /*                                                                          */
     929                 : /*    Remove the gived style in the table based on the name, return TRUE    */
     930                 : /*    on success otherwise FALSE                                            */
     931                 : /****************************************************************************/
     932                 : 
     933                 : /**
     934                 :  * \brief Remove a style in the table by its name.
     935                 :  *
     936                 :  * @param pszName the name of the style to remove.
     937                 :  *
     938                 :  * @return TRUE on success, FALSE on error
     939                 :  */
     940                 : 
     941               0 : GBool OGRStyleTable::RemoveStyle(const char *pszName)
     942                 : {
     943                 :     int nPos;
     944               0 :     if ((nPos = IsExist(pszName)) != -1)
     945                 :     {
     946               0 :         m_papszStyleTable = CSLRemoveStrings(m_papszStyleTable,nPos,1,NULL);
     947               0 :         return TRUE;
     948                 :     }
     949               0 :     return FALSE;
     950                 : }
     951                 : 
     952                 : /****************************************************************************/
     953                 : /*            GBool OGRStyleTable::ModifyStyle(char *pszName,               */
     954                 : /*                                             char *pszStyleString)        */
     955                 : /*                                                                          */
     956                 : /*    Modify the gived style, if the style doesn't exist, it will be added  */
     957                 : /*    return TRUE on success otherwise return FALSE                         */
     958                 : /****************************************************************************/
     959                 : 
     960                 : /**
     961                 :  * \brief Modify a style in the table by its name
     962                 :  * If the style does not exist, it will be added.
     963                 :  *
     964                 :  * @param pszName the name of the style to modify.
     965                 :  * @param pszStyleString the style string.
     966                 :  *
     967                 :  * @return TRUE on success, FALSE on error
     968                 :  */
     969                 : 
     970               0 : GBool OGRStyleTable::ModifyStyle(const char *pszName, 
     971                 :                                  const char * pszStyleString)
     972                 : {
     973               0 :     if (pszName == NULL || pszStyleString == NULL)
     974               0 :       return FALSE;
     975                 : 
     976               0 :     RemoveStyle(pszName);
     977               0 :     return AddStyle(pszName, pszStyleString);
     978                 : 
     979                 : }    
     980                 : 
     981                 : /****************************************************************************/
     982                 : /*            GBool OGRStyleTable::SaveStyleTable(char *)                   */
     983                 : /*                                                                          */
     984                 : /*    Save the StyleTable in the gived file, return TRUE on success         */
     985                 : /*    otherwise return FALSE                                                */
     986                 : /****************************************************************************/
     987                 : 
     988                 : /**
     989                 :  * \brief Save a style table to a file.
     990                 :  *
     991                 :  * @param pszFilename the name of the file to save to.
     992                 :  *
     993                 :  * @return TRUE on success, FALSE on error
     994                 :  */
     995                 : 
     996               0 : GBool OGRStyleTable::SaveStyleTable(const char *pszFilename)
     997                 : {
     998               0 :     if (pszFilename == NULL)
     999               0 :       return FALSE;
    1000                 : 
    1001               0 :     if (CSLSave(m_papszStyleTable,pszFilename) == 0)
    1002               0 :       return FALSE;
    1003                 :     else
    1004               0 :       return TRUE;
    1005                 : }
    1006                 : 
    1007                 : /************************************************************************/
    1008                 : /*                     OGR_STBL_SaveStyleTable()                        */
    1009                 : /************************************************************************/
    1010                 : 
    1011                 : /**
    1012                 :  * \brief Save a style table to a file.
    1013                 :  *
    1014                 :  * This function is the same as the C++ method OGRStyleTable::SaveStyleTable().
    1015                 :  *
    1016                 :  * @param hStyleTable handle to the style table.
    1017                 :  * @param pszFilename the name of the file to save to.
    1018                 :  *
    1019                 :  * @return TRUE on success, FALSE on error
    1020                 :  */
    1021                 : 
    1022               0 : int OGR_STBL_SaveStyleTable( OGRStyleTableH hStyleTable,
    1023                 :                              const char *pszFilename )
    1024                 : {
    1025               0 :     VALIDATE_POINTER1( hStyleTable, "OGR_STBL_SaveStyleTable", FALSE );
    1026               0 :     VALIDATE_POINTER1( pszFilename, "OGR_STBL_SaveStyleTable", FALSE );
    1027                 :     
    1028               0 :     return ((OGRStyleTable *) hStyleTable)->SaveStyleTable( pszFilename );
    1029                 : }
    1030                 : 
    1031                 : /****************************************************************************/
    1032                 : /*            GBool OGRStyleTable::LoadStyleTable(char *)                   */
    1033                 : /*                                                                          */
    1034                 : /*            Read the Style table from a file, return TRUE on success      */
    1035                 : /*            otherwise return FALSE                                        */
    1036                 : /****************************************************************************/
    1037                 : 
    1038                 : /**
    1039                 :  * \brief Load a style table from a file.
    1040                 :  *
    1041                 :  * @param pszFilename the name of the file to load from.
    1042                 :  *
    1043                 :  * @return TRUE on success, FALSE on error
    1044                 :  */
    1045                 : 
    1046               0 : GBool OGRStyleTable::LoadStyleTable(const char *pszFilename)
    1047                 : {
    1048               0 :     if (pszFilename == NULL)
    1049               0 :       return FALSE;
    1050                 : 
    1051               0 :     CSLDestroy(m_papszStyleTable);
    1052                 :         
    1053               0 :     m_papszStyleTable = CSLLoad(pszFilename);
    1054                 :    
    1055               0 :     if (m_papszStyleTable == NULL)
    1056               0 :       return FALSE;
    1057                 :     else
    1058               0 :       return TRUE;
    1059                 : }
    1060                 : 
    1061                 : /************************************************************************/
    1062                 : /*                     OGR_STBL_LoadStyleTable()                        */
    1063                 : /************************************************************************/
    1064                 : 
    1065                 : /**
    1066                 :  * \brief Load a style table from a file.
    1067                 :  *
    1068                 :  * This function is the same as the C++ method OGRStyleTable::LoadStyleTable().
    1069                 :  *
    1070                 :  * @param hStyleTable handle to the style table.
    1071                 :  * @param pszFilename the name of the file to load from.
    1072                 :  *
    1073                 :  * @return TRUE on success, FALSE on error
    1074                 :  */
    1075                 : 
    1076               0 : int OGR_STBL_LoadStyleTable( OGRStyleTableH hStyleTable,
    1077                 :                              const char *pszFilename )
    1078                 : {
    1079               0 :     VALIDATE_POINTER1( hStyleTable, "OGR_STBL_LoadStyleTable", FALSE );
    1080               0 :     VALIDATE_POINTER1( pszFilename, "OGR_STBL_LoadStyleTable", FALSE );
    1081                 :     
    1082               0 :     return ((OGRStyleTable *) hStyleTable)->LoadStyleTable( pszFilename );
    1083                 : }
    1084                 : 
    1085                 : /****************************************************************************/
    1086                 : /*             const char *OGRStyleTable::Find(const char *pszName)         */
    1087                 : /*                                                                          */
    1088                 : /*             return the StyleString based on the gived name,              */
    1089                 : /*             otherwise return NULL                                        */
    1090                 : /****************************************************************************/
    1091                 : 
    1092                 : /**
    1093                 :  * \brief Get a style string by name.
    1094                 :  *
    1095                 :  * @param pszName the name of the style string to find.
    1096                 :  *
    1097                 :  * @return the style string matching the name, NULL if not found or error.
    1098                 :  */
    1099                 : 
    1100              34 : const char *OGRStyleTable::Find(const char *pszName)
    1101                 : {
    1102              34 :     const char *pszDash = NULL;
    1103              34 :     const char *pszOutput = NULL;
    1104                 : 
    1105                 :     int nPos;
    1106              34 :     if ((nPos = IsExist(pszName)) != -1)
    1107                 :     {
    1108                 : 
    1109              34 :         pszOutput = CSLGetField(m_papszStyleTable,nPos);
    1110                 :          
    1111              34 :         pszDash = strstr(pszOutput,":");
    1112                 :         
    1113              34 :         if (pszDash)
    1114              34 :           return &pszDash[1];
    1115                 :     }
    1116               0 :     return NULL;
    1117                 : }   
    1118                 : 
    1119                 : /************************************************************************/
    1120                 : /*                     OGR_STBL_Find()                                  */
    1121                 : /************************************************************************/
    1122                 : 
    1123                 : /**
    1124                 :  * \brief Get a style string by name.
    1125                 :  *
    1126                 :  * This function is the same as the C++ method OGRStyleTable::Find().
    1127                 :  *
    1128                 :  * @param hStyleTable handle to the style table.
    1129                 :  * @param pszName the name of the style string to find.
    1130                 :  *
    1131                 :  * @return the style string matching the name or NULL if not found or error.
    1132                 :  */
    1133                 : 
    1134               0 : const char *OGR_STBL_Find( OGRStyleTableH hStyleTable, const char *pszName )
    1135                 : {
    1136               0 :     VALIDATE_POINTER1( hStyleTable, "OGR_STBL_Find", FALSE );
    1137               0 :     VALIDATE_POINTER1( pszName, "OGR_STBL_Find", FALSE );
    1138                 :     
    1139               0 :     return ((OGRStyleTable *) hStyleTable)->Find( pszName );
    1140                 : }
    1141                 : 
    1142                 : /****************************************************************************/
    1143                 : /*              OGRStyleTable::Print(FILE *fpOut)                           */
    1144                 : /*                                                                          */
    1145                 : /****************************************************************************/
    1146                 : 
    1147                 : /**
    1148                 :  * \brief Print a style table to a FILE pointer.
    1149                 :  *
    1150                 :  * @param fpOut the FILE pointer to print to.
    1151                 :  *
    1152                 :  */
    1153                 : 
    1154               0 : void OGRStyleTable::Print(FILE *fpOut)
    1155                 : {
    1156                 :     
    1157               0 :     VSIFPrintf(fpOut,"#OFS-Version: 1.0\n");
    1158               0 :     VSIFPrintf(fpOut,"#StyleField: style\n");
    1159               0 :     if (m_papszStyleTable)
    1160                 :     {
    1161               0 :         CSLPrint(m_papszStyleTable,fpOut);
    1162                 :     }
    1163               0 : }
    1164                 : 
    1165                 : /****************************************************************************/
    1166                 : /*             int OGRStyleTable::IsExist(const char *pszName)            */
    1167                 : /*                                                                          */
    1168                 : /*   return a index of the style in the table otherwise return -1           */
    1169                 : /****************************************************************************/
    1170                 : 
    1171                 : /**
    1172                 :  * \brief Get the index of a style in the table by its name.
    1173                 :  *
    1174                 :  * @param pszName the name to look for.
    1175                 :  *
    1176                 :  * @return The index of the style if found, -1 if not found or error.
    1177                 :  */
    1178                 : 
    1179             118 : int OGRStyleTable::IsExist(const char *pszName)
    1180                 : {
    1181                 :     int i;
    1182                 :     int nCount;
    1183                 :     const char *pszNewString;
    1184                 : 
    1185             118 :     if (pszName == NULL)
    1186               0 :       return -1;
    1187                 : 
    1188             118 :     nCount = CSLCount(m_papszStyleTable);
    1189             118 :     pszNewString = CPLSPrintf("%s:",pszName);
    1190                 : 
    1191             528 :     for (i=0;i<nCount;i++)
    1192                 :     {
    1193             444 :         if (strstr(m_papszStyleTable[i],pszNewString) != NULL)
    1194                 :         {
    1195              34 :             return i;
    1196                 :             
    1197                 :         }
    1198                 :     }
    1199                 : 
    1200              84 :     return -1;
    1201                 : }    
    1202                 : 
    1203                 : /************************************************************************/
    1204                 : /*                               Clone()                                */
    1205                 : /************************************************************************/
    1206                 : 
    1207                 : /**
    1208                 :  * \brief Duplicate style table.
    1209                 :  *
    1210                 :  * The newly created style table is owned by the caller, and will have it's
    1211                 :  * own reference to the OGRStyleTable.
    1212                 :  *
    1213                 :  * @return new style table, exactly matching this style table.
    1214                 :  */
    1215                 : 
    1216               0 : OGRStyleTable *OGRStyleTable::Clone()
    1217                 : 
    1218                 : {
    1219               0 :     OGRStyleTable *poNew = new OGRStyleTable();
    1220                 : 
    1221               0 :     poNew->m_papszStyleTable = CSLDuplicate( m_papszStyleTable );
    1222                 : 
    1223               0 :     return poNew;
    1224                 : }
    1225                 : 
    1226                 : /************************************************************************/
    1227                 : /*                            ResetStyleStringReading()                 */
    1228                 : /************************************************************************/
    1229                 : 
    1230               0 : void OGRStyleTable::ResetStyleStringReading()
    1231                 : 
    1232                 : {
    1233               0 :     iNextStyle = 0;
    1234               0 : }
    1235                 : 
    1236                 : /************************************************************************/
    1237                 : /*                     OGR_STBL_ResetStyleStringReading()               */
    1238                 : /************************************************************************/
    1239                 : 
    1240                 : /**
    1241                 :  * \brief Reset the next style pointer to 0
    1242                 :  *
    1243                 :  * This function is the same as the C++ method
    1244                 :  * OGRStyleTable::ResetStyleStringReading().
    1245                 :  *
    1246                 :  * @param hStyleTable handle to the style table.
    1247                 :  *
    1248                 :  */
    1249                 : 
    1250               0 : void OGR_STBL_ResetStyleStringReading( OGRStyleTableH hStyleTable )
    1251                 : {
    1252               0 :     VALIDATE_POINTER0( hStyleTable, "OGR_STBL_ResetStyleStringReading" );
    1253                 : 
    1254               0 :     ((OGRStyleTable *) hStyleTable)->ResetStyleStringReading();
    1255                 : }
    1256                 : 
    1257                 : /************************************************************************/
    1258                 : /*                           GetNextStyle()                             */
    1259                 : /************************************************************************/
    1260                 : 
    1261               0 : const char *OGRStyleTable::GetNextStyle()
    1262                 : {
    1263               0 :     const char *pszDash = NULL;
    1264               0 :     const char *pszOutput = NULL;
    1265                 : 
    1266               0 :     while( iNextStyle < CSLCount(m_papszStyleTable) )
    1267                 :     {
    1268                 : 
    1269               0 :         if ( NULL == (pszOutput = CSLGetField(m_papszStyleTable,iNextStyle++)))
    1270               0 :             continue;
    1271                 : 
    1272               0 :         pszDash = strstr(pszOutput,":");
    1273                 : 
    1274                 :         int nColon;
    1275                 : 
    1276               0 :         osLastRequestedStyleName = pszOutput;
    1277               0 :         nColon = osLastRequestedStyleName.find( ':' );
    1278               0 :         if( nColon != -1 )
    1279                 :             osLastRequestedStyleName = 
    1280               0 :                 osLastRequestedStyleName.substr(0,nColon);
    1281                 : 
    1282               0 :         if (pszDash)
    1283               0 :             return pszDash + 1;
    1284                 :     }
    1285               0 :     return NULL;
    1286                 : }
    1287                 : 
    1288                 : /************************************************************************/
    1289                 : /*                     OGR_STBL_GetNextStyle()                          */
    1290                 : /************************************************************************/
    1291                 : 
    1292                 : /**
    1293                 :  * \brief Get the next style string from the table.
    1294                 :  *
    1295                 :  * This function is the same as the C++ method OGRStyleTable::GetNextStyle().
    1296                 :  *
    1297                 :  * @param hStyleTable handle to the style table.
    1298                 :  *
    1299                 :  * @return the next style string or NULL on error.
    1300                 :  */
    1301                 : 
    1302               0 : const char *OGR_STBL_GetNextStyle( OGRStyleTableH hStyleTable)
    1303                 : {
    1304               0 :     VALIDATE_POINTER1( hStyleTable, "OGR_STBL_GetNextStyle", NULL );
    1305                 :     
    1306               0 :     return ((OGRStyleTable *) hStyleTable)->GetNextStyle();
    1307                 : }
    1308                 : 
    1309                 : /************************************************************************/
    1310                 : /*                           GetLastStyleName()                         */
    1311                 : /************************************************************************/
    1312                 : 
    1313               0 : const char *OGRStyleTable::GetLastStyleName()
    1314                 : {
    1315               0 :     return osLastRequestedStyleName;
    1316                 : }
    1317                 : 
    1318                 : /************************************************************************/
    1319                 : /*                     OGR_STBL_GetLastStyleName()                      */
    1320                 : /************************************************************************/
    1321                 : 
    1322                 : /**
    1323                 :  * Get the style name of the last style string fetched with
    1324                 :  * OGR_STBL_GetNextStyle.
    1325                 :  *
    1326                 :  * This function is the same as the C++ method OGRStyleTable::GetStyleName().
    1327                 :  *
    1328                 :  * @param hStyleTable handle to the style table.
    1329                 :  *
    1330                 :  * @return the Name of the last style string or NULL on error.
    1331                 :  */
    1332                 : 
    1333               0 : const char *OGR_STBL_GetLastStyleName( OGRStyleTableH hStyleTable)
    1334                 : {
    1335               0 :     VALIDATE_POINTER1( hStyleTable, "OGR_STBL_GetLastStyleName", NULL );
    1336                 :     
    1337               0 :     return ((OGRStyleTable *) hStyleTable)->GetLastStyleName();
    1338                 : }
    1339                 : 
    1340                 : 
    1341                 : /****************************************************************************/
    1342                 : /*                          OGRStyleTool::OGRStyleTool()                    */
    1343                 : /*                                                                          */
    1344                 : /****************************************************************************/
    1345             202 : OGRStyleTool::OGRStyleTool(OGRSTClassId eClassId)
    1346                 : {
    1347             202 :     m_eClassId = eClassId; 
    1348             202 :     m_dfScale = 1.0; 
    1349             202 :     m_eUnit = OGRSTUMM;
    1350             202 :     m_pszStyleString = NULL;
    1351             202 :     m_bModified = FALSE;
    1352             202 :     m_bParsed = FALSE;
    1353             202 : }
    1354                 : 
    1355                 : /************************************************************************/
    1356                 : /*                            OGR_ST_Create()                           */
    1357                 : /************************************************************************/
    1358                 : /**
    1359                 :  * \brief OGRStyleTool factory.
    1360                 :  *
    1361                 :  * This function is a constructor for OGRStyleTool derived classes.
    1362                 :  * 
    1363                 :  * @param eClassId subclass of style tool to create. One of OGRSTCPen (1),
    1364                 :  * OGRSTCBrush (2), OGRSTCSymbol (3) or OGRSTCLabel (4).
    1365                 :  * 
    1366                 :  * @return an handle to the new style tool object or NULL if the creation 
    1367                 :  * failed.
    1368                 :  */
    1369                 : 
    1370               0 : OGRStyleToolH OGR_ST_Create( OGRSTClassId eClassId )
    1371                 : 
    1372                 : {
    1373               0 :     switch( eClassId )
    1374                 :     {
    1375                 :       case OGRSTCPen:
    1376               0 :         return (OGRStyleToolH) new OGRStylePen();
    1377                 :       case OGRSTCBrush:
    1378               0 :         return (OGRStyleToolH) new OGRStyleBrush();
    1379                 :       case OGRSTCSymbol:
    1380               0 :         return (OGRStyleToolH) new OGRStyleSymbol();
    1381                 :       case OGRSTCLabel:
    1382               0 :         return (OGRStyleToolH) new OGRStyleLabel();
    1383                 :       default:
    1384               0 :         return NULL;
    1385                 :     }
    1386                 : }
    1387                 : 
    1388                 : /****************************************************************************/
    1389                 : /*                       OGRStyleTool::~OGRStyleTool()                      */
    1390                 : /*                                                                          */
    1391                 : /****************************************************************************/
    1392             202 : OGRStyleTool::~OGRStyleTool()
    1393                 : {
    1394             202 :     CPLFree(m_pszStyleString);
    1395             202 : }
    1396                 : 
    1397                 : /************************************************************************/
    1398                 : /*                           OGR_ST_Destroy()                            */
    1399                 : /************************************************************************/
    1400                 : /**
    1401                 :  * \brief Destroy Style Tool
    1402                 :  *
    1403                 :  * @param hST handle to the style tool to destroy.
    1404                 :  */
    1405                 : 
    1406               8 : void OGR_ST_Destroy( OGRStyleToolH hST )
    1407                 : 
    1408                 : {
    1409               8 :     delete (OGRStyleTool *) hST; 
    1410               8 : }
    1411                 : 
    1412                 : 
    1413                 : /****************************************************************************/
    1414                 : /*      void OGRStyleTool::SetStyleString(const char *pszStyleString)       */
    1415                 : /*                                                                          */
    1416                 : /****************************************************************************/
    1417              70 : void OGRStyleTool::SetStyleString(const char *pszStyleString)
    1418                 : {
    1419              70 :     m_pszStyleString = CPLStrdup(pszStyleString);
    1420              70 : }
    1421                 : 
    1422                 : /****************************************************************************/
    1423                 : /*const char *OGRStyleTool::GetStyleString( OGRStyleParamId *pasStyleParam ,*/
    1424                 : /*                          OGRStyleValue *pasStyleValue, int nSize)        */
    1425                 : /*                                                                          */
    1426                 : /****************************************************************************/
    1427             372 : const char *OGRStyleTool::GetStyleString(const OGRStyleParamId *pasStyleParam,
    1428                 :                                          OGRStyleValue *pasStyleValue,
    1429                 :                                          int nSize)
    1430                 : {
    1431             372 :     if (IsStyleModified())
    1432                 :     {
    1433                 :         int i;
    1434                 :         GBool bFound;
    1435                 :         const char *pszClass;
    1436                 :         // FIXME: we should use CPLString instead of static buffer:
    1437                 :         char szCurrent[8192];
    1438             132 :         szCurrent[0] = '\0';
    1439                 :     
    1440             132 :         CPLFree(m_pszStyleString);
    1441                 :         
    1442             132 :         switch (GetType())
    1443                 :         {
    1444                 :           case OGRSTCPen:
    1445              60 :             pszClass = "PEN(";
    1446              60 :             break;
    1447                 :           case OGRSTCBrush:
    1448              48 :             pszClass = "BRUSH(";
    1449              48 :             break;
    1450                 :           case OGRSTCSymbol:
    1451              24 :             pszClass = "SYMBOL(";
    1452              24 :             break;
    1453                 :           case OGRSTCLabel:
    1454               0 :             pszClass = "LABEL(";
    1455               0 :             break;
    1456                 :           default:
    1457               0 :             pszClass = "UNKNOWN(";
    1458                 :         }
    1459                 : 
    1460             132 :         strcat(szCurrent,pszClass);
    1461                 : 
    1462             132 :         bFound = FALSE;
    1463            1284 :         for (i=0;i< nSize;i++)
    1464                 :         {
    1465            1152 :             if (pasStyleValue[i].bValid == FALSE)
    1466            1002 :               continue;
    1467                 : 
    1468             150 :             if (bFound)
    1469              18 :               strcat(szCurrent,",");
    1470             150 :             bFound = TRUE;
    1471                 :             
    1472             150 :             strcat(szCurrent,pasStyleParam[i].pszToken);
    1473             150 :             switch (pasStyleParam[i].eType)
    1474                 :             {
    1475                 :               case OGRSTypeString:
    1476             102 :                 strcat(szCurrent,":");
    1477             102 :                 strcat(szCurrent,pasStyleValue[i].pszValue);
    1478             102 :                 break;
    1479                 :               case OGRSTypeDouble:
    1480              48 :                 strcat(szCurrent,CPLString().Printf(":%f",pasStyleValue[i].dfValue));
    1481              48 :                 break;
    1482                 :               case OGRSTypeInteger:
    1483               0 :                 strcat(szCurrent,CPLString().Printf(":%d",pasStyleValue[i].nValue));
    1484                 :                 break;
    1485                 :               default:
    1486                 :                 break;
    1487                 :             }       
    1488             150 :             if (pasStyleParam[i].bGeoref)
    1489              48 :               switch (pasStyleValue[i].eUnit)
    1490                 :               {
    1491                 :                 case OGRSTUGround:
    1492               0 :                   strcat(szCurrent,"g");
    1493               0 :                   break;
    1494                 :                 case OGRSTUPixel:
    1495              48 :                   strcat(szCurrent,"px");
    1496              48 :                   break;
    1497                 :                 case OGRSTUPoints:
    1498               0 :                   strcat(szCurrent,"pt");
    1499               0 :                   break;
    1500                 :                 case OGRSTUCM:
    1501               0 :                   strcat(szCurrent,"cm");
    1502               0 :                   break;
    1503                 :                 case OGRSTUInches:
    1504               0 :                   strcat(szCurrent,"in");
    1505                 :                   break;
    1506                 :                 case OGRSTUMM:
    1507                 :                   //strcat(szCurrent,"mm");
    1508                 :                 default:
    1509                 :                   break;    //imp
    1510                 :               }
    1511                 :         }
    1512             132 :         strcat(szCurrent,")");
    1513                 : 
    1514             132 :         m_pszStyleString = CPLStrdup(szCurrent);
    1515                 : 
    1516             132 :         m_bModified = FALSE;
    1517                 :     }
    1518                 :     
    1519             372 :     return m_pszStyleString;
    1520                 : }   
    1521                 : 
    1522                 : /************************************************************************/
    1523                 : /*                          GetRGBFromString()                          */
    1524                 : /************************************************************************/
    1525                 : 
    1526               0 : GBool OGRStyleTool::GetRGBFromString(const char *pszColor, int &nRed, 
    1527                 :                                      int &nGreen ,int & nBlue, 
    1528                 :                                      int &nTransparance)
    1529                 : {
    1530               0 :    int nCount=0;
    1531                 :    
    1532               0 :    nTransparance = 255;
    1533                 : 
    1534                 :    // FIXME: should we really use sscanf here?
    1535               0 :    if (pszColor)
    1536                 :        nCount  = sscanf(pszColor,"#%2x%2x%2x%2x",&nRed,&nGreen,&nBlue, 
    1537               0 :                         &nTransparance);
    1538                 :    
    1539               0 :    if (nCount >=3)
    1540               0 :      return TRUE;
    1541                 :    else
    1542               0 :      return FALSE;
    1543                 : }
    1544                 : 
    1545                 : /************************************************************************/
    1546                 : /*                           GetSpecificId()                            */
    1547                 : /*                                                                      */
    1548                 : /*      return -1, if the wanted type is not found, ex:                 */
    1549                 : /*      if you want ogr-pen value, pszWanted should be ogr-pen(case     */
    1550                 : /*      sensitive)                                                      */
    1551                 : /************************************************************************/
    1552                 : 
    1553               0 : int OGRStyleTool::GetSpecificId(const char *pszId, const char *pszWanted)
    1554                 : {
    1555               0 :     const char *pszRealWanted = pszWanted;
    1556                 :     const char *pszFound;
    1557               0 :     int nValue  = -1;
    1558                 : 
    1559               0 :     if (pszWanted == NULL || strlen(pszWanted) == 0)
    1560               0 :       pszRealWanted = "ogr-pen";
    1561                 : 
    1562               0 :     if (pszId == NULL)
    1563               0 :       return -1;
    1564                 :     
    1565               0 :     if ((pszFound = strstr(pszId, pszRealWanted)) != NULL)
    1566                 :     {
    1567                 :         // We found the string, it could be no value after it, use default one
    1568               0 :         nValue = 0;
    1569                 :         
    1570               0 :         if (pszFound[strlen(pszRealWanted)] == '-' )
    1571               0 :           nValue =atoi(&pszFound[strlen(pszRealWanted)+1]);
    1572                 :     }
    1573                 :     
    1574               0 :     return nValue;
    1575                 : 
    1576                 : }
    1577                 : 
    1578                 : /************************************************************************/
    1579                 : /*                              GetType()                               */
    1580                 : /************************************************************************/
    1581             250 : OGRSTClassId OGRStyleTool::GetType()
    1582                 : {
    1583             250 :     return m_eClassId;
    1584                 : }
    1585                 : 
    1586                 : /************************************************************************/
    1587                 : /*                           OGR_ST_GetType()                           */
    1588                 : /************************************************************************/
    1589                 : /**
    1590                 :  * \brief Determine type of Style Tool
    1591                 :  *
    1592                 :  * @param hST handle to the style tool.
    1593                 :  *
    1594                 :  * @return the style tool type, one of OGRSTCPen (1), OGRSTCBrush (2), 
    1595                 :  * OGRSTCSymbol (3) or OGRSTCLabel (4). Returns OGRSTCNone (0) if the 
    1596                 :  * OGRStyleToolH is invalid.
    1597                 :  */
    1598                 : 
    1599              14 : OGRSTClassId OGR_ST_GetType( OGRStyleToolH hST )
    1600                 : 
    1601                 : {
    1602              14 :     VALIDATE_POINTER1( hST, "OGR_ST_GetType", OGRSTCNone );
    1603              14 :     return ((OGRStyleTool *) hST)->GetType();
    1604                 : }
    1605                 : 
    1606                 : 
    1607                 : /************************************************************************/
    1608                 : /*                           OGR_ST_GetUnit()                           */
    1609                 : /************************************************************************/
    1610                 : /**
    1611                 :  * \brief Get Style Tool units
    1612                 :  *
    1613                 :  * @param hST handle to the style tool.
    1614                 :  *
    1615                 :  * @return the style tool units.
    1616                 :  */
    1617                 : 
    1618               0 : OGRSTUnitId OGR_ST_GetUnit( OGRStyleToolH hST )
    1619                 : 
    1620                 : {
    1621               0 :     VALIDATE_POINTER1( hST, "OGR_ST_GetUnit", OGRSTUGround );
    1622               0 :     return ((OGRStyleTool *) hST)->GetUnit();
    1623                 : }
    1624                 : 
    1625                 : 
    1626                 : /************************************************************************/
    1627                 : /*                              SetUnit()                               */
    1628                 : /************************************************************************/
    1629              80 : void OGRStyleTool::SetUnit(OGRSTUnitId eUnit,double dfScale)
    1630                 : {
    1631              80 :     m_dfScale = dfScale;
    1632              80 :     m_eUnit = eUnit;
    1633              80 : }
    1634                 : 
    1635                 : /************************************************************************/
    1636                 : /*                           OGR_ST_SetUnit()                           */
    1637                 : /************************************************************************/
    1638                 : /**
    1639                 :  * \brief Set Style Tool units
    1640                 :  *
    1641                 :  * This function is the same as OGRStyleTool::SetUnit()
    1642                 :  *
    1643                 :  * @param hST handle to the style tool. 
    1644                 :  * @param eUnit the new unit.
    1645                 :  * @param dfGroundPaperScale ground to paper scale factor.
    1646                 :  *
    1647                 :  */
    1648                 : 
    1649               0 : void OGR_ST_SetUnit( OGRStyleToolH hST, OGRSTUnitId eUnit,
    1650                 :                      double dfGroundPaperScale )
    1651                 : 
    1652                 : {
    1653               0 :     VALIDATE_POINTER0( hST, "OGR_ST_SetUnit" );
    1654               0 :     ((OGRStyleTool *) hST)->SetUnit(eUnit, dfGroundPaperScale);
    1655                 : }
    1656                 : 
    1657                 : /************************************************************************/
    1658                 : /*                               Parse()                                */
    1659                 : /************************************************************************/
    1660             254 : GBool OGRStyleTool::Parse(const OGRStyleParamId *pasStyle,
    1661                 :                           OGRStyleValue *pasValue,
    1662                 :                           int nCount)
    1663                 : {
    1664                 :     char **papszToken; // Token to contains StyleString Type and content
    1665                 :     char **papszToken2; // Token that will contains StyleString elements
    1666                 : 
    1667                 : 
    1668                 :     OGRSTUnitId  eLastUnit;
    1669                 :     
    1670             254 :     if (IsStyleParsed() == TRUE)
    1671             106 :       return TRUE;
    1672                 : 
    1673             148 :     StyleParsed();
    1674                 : 
    1675             148 :     if (m_pszStyleString == NULL)
    1676             132 :       return FALSE;
    1677                 :     
    1678                 :     // Tokenize the String to get the Type and the content
    1679                 :     // Example: Type(elem1:val2,elem2:val2)
    1680                 :     papszToken  = CSLTokenizeString2(m_pszStyleString,"()",
    1681                 :                                      CSLT_HONOURSTRINGS
    1682                 :                                      | CSLT_PRESERVEQUOTES
    1683              16 :                                      | CSLT_PRESERVEESCAPES );
    1684                 : 
    1685              16 :     if (CSLCount(papszToken) > 2 || CSLCount(papszToken) == 0)
    1686                 :     {
    1687               0 :         CSLDestroy( papszToken );
    1688                 :         CPLError(CE_Failure, CPLE_AppDefined, 
    1689               0 :                  "Error in the format of the StyleTool %s\n",m_pszStyleString);
    1690               0 :         return FALSE;
    1691                 :     }
    1692                 :     
    1693                 :     // Tokenize the content of the StyleString to get paired components in it.
    1694              16 :     papszToken2 = CSLTokenizeString2( papszToken[1], ",",
    1695                 :                                       CSLT_HONOURSTRINGS
    1696                 :                                       | CSLT_PRESERVEQUOTES
    1697              32 :                                       | CSLT_PRESERVEESCAPES );
    1698                 :     
    1699                 :     // Valid that we have the right StyleString for this feature type.
    1700              16 :     switch (GetType())
    1701                 :     {
    1702                 :       case OGRSTCPen:
    1703              10 :         if (!EQUAL(papszToken[0],"PEN"))
    1704                 :         {
    1705                 :             CPLError(CE_Failure, CPLE_AppDefined, 
    1706                 :                      "Error in the Type of StyleTool %s should be a PEN Type\n",
    1707               0 :                      papszToken[0]);
    1708               0 :             CSLDestroy( papszToken );
    1709               0 :             CSLDestroy( papszToken2 );
    1710               0 :             return FALSE;
    1711                 :         }
    1712              10 :         break;
    1713                 :       case OGRSTCBrush:
    1714               2 :         if (!EQUAL(papszToken[0],"BRUSH"))
    1715                 :         {
    1716                 :             CPLError(CE_Failure, CPLE_AppDefined, 
    1717                 :                      "Error in the Type of StyleTool %s should be a BRUSH Type\n",
    1718               0 :                      papszToken[0]);
    1719               0 :             CSLDestroy( papszToken );
    1720               0 :             CSLDestroy( papszToken2 );
    1721               0 :             return FALSE;
    1722                 :         }
    1723               2 :         break;
    1724                 :       case OGRSTCSymbol:
    1725               0 :         if (!EQUAL(papszToken[0],"SYMBOL"))
    1726                 :         {
    1727                 :             CPLError(CE_Failure, CPLE_AppDefined, 
    1728                 :                      "Error in the Type of StyleTool %s should be a SYMBOL Type\n",
    1729               0 :                      papszToken[0]);
    1730               0 :             CSLDestroy( papszToken );
    1731               0 :             CSLDestroy( papszToken2 );
    1732               0 :             return FALSE;
    1733                 :         }
    1734               0 :         break;
    1735                 :       case OGRSTCLabel:
    1736               4 :         if (!EQUAL(papszToken[0],"LABEL"))
    1737                 :         {
    1738                 :             CPLError(CE_Failure, CPLE_AppDefined, 
    1739                 :                      "Error in the Type of StyleTool %s should be a LABEL Type\n",
    1740               0 :                      papszToken[0]);
    1741               0 :             CSLDestroy( papszToken );
    1742               0 :             CSLDestroy( papszToken2 );
    1743               0 :             return FALSE;
    1744                 :         }
    1745               4 :         break;
    1746                 :       default:
    1747                 :         CPLError(CE_Failure, CPLE_AppDefined, 
    1748               0 :                  "Error in the Type of StyleTool, Type undetermined\n");
    1749               0 :         CSLDestroy( papszToken );
    1750               0 :         CSLDestroy( papszToken2 );
    1751               0 :         return FALSE;
    1752                 :         break;
    1753                 :     }
    1754                 :     
    1755                 :     ////////////////////////////////////////////////////////////////////////
    1756                 :     // Here we will loop on each element in the StyleString. If it's 
    1757                 :     // a valid element, we will add it in the StyleTool with 
    1758                 :     // SetParamStr().
    1759                 :     //
    1760                 :     // It's important to note that the SetInternalUnit...() is use to update 
    1761                 :     // the unit of the StyleTool param (m_eUnit). 
    1762                 :     // See OGRStyleTool::SetParamStr().
    1763                 :     // There's a StyleTool unit (m_eUnit), which is the output unit, and each 
    1764                 :     // parameter of the style have its own unit value (the input unit). Here we
    1765                 :     // set m_eUnit to the input unit and in SetParamStr(), we will use this
    1766                 :     // value to set the input unit. Then after the loop we will reset m_eUnit 
    1767                 :     // to it's original value. (Yes it's a side effect / black magic)
    1768                 :     //
    1769                 :     // The pasStyle variable is a global variable passed in argument to the
    1770                 :     // function. See at the top of this file the four OGRStyleParamId 
    1771                 :     // variable. They are used to register the valid parameter of each 
    1772                 :     // StyleTool.
    1773                 :     ////////////////////////////////////////////////////////////////////////
    1774                 : 
    1775                 :     // Save Scale and output Units because the parsing code will alter 
    1776                 :     // the values
    1777              16 :     eLastUnit = m_eUnit;
    1778              16 :     double  dSavedScale = m_dfScale;
    1779              16 :     int     i, nElements = CSLCount(papszToken2);
    1780                 : 
    1781              64 :     for ( i = 0; i < nElements; i++ )
    1782                 :     {
    1783                 :         char    **papszStylePair =
    1784              48 :             CSLTokenizeString2( papszToken2[i], ":", 
    1785                 :                                 CSLT_HONOURSTRINGS 
    1786                 :                                 | CSLT_STRIPLEADSPACES
    1787                 :                                 | CSLT_STRIPENDSPACES 
    1788              96 :                                 | CSLT_ALLOWEMPTYTOKENS );
    1789                 : 
    1790              48 :         int     j, nTokens = CSLCount(papszStylePair);
    1791                 : 
    1792              48 :         if ( nTokens < 1 || nTokens > 2 )
    1793                 :         {
    1794                 :             CPLError( CE_Warning, CPLE_AppDefined,
    1795               0 :                       "Error in the StyleTool String %s", m_pszStyleString );
    1796                 :             CPLError( CE_Warning, CPLE_AppDefined,
    1797                 :                       "Malformed element #%d (\"%s\") skipped",
    1798               0 :                       i, papszToken2[i] );
    1799               0 :             CSLDestroy(papszStylePair);
    1800               0 :             continue;
    1801                 :         }
    1802                 :         
    1803             108 :         for ( j = 0; j < nCount; j++ )
    1804                 :         {
    1805             108 :             if ( EQUAL(pasStyle[j].pszToken, papszStylePair[0]) )
    1806                 :             {
    1807              48 :                 if (nTokens == 2 && pasStyle[j].bGeoref == TRUE)
    1808              14 :                     SetInternalInputUnitFromParam(papszStylePair[1]);
    1809                 : 
    1810                 :                 // Set either the actual value of style parameter or "1"
    1811                 :                 // for boolean parameters which do not have values.
    1812                 :                 // "1" means that boolean parameter is present in the style
    1813                 :                 // string.
    1814                 :                 OGRStyleTool::SetParamStr( pasStyle[j], pasValue[j],
    1815              48 :                                     (nTokens == 2) ? papszStylePair[1] : "1" );
    1816                 : 
    1817              48 :                 break;
    1818                 :             }
    1819                 :         }
    1820                 : 
    1821              48 :         CSLDestroy( papszStylePair );
    1822                 :     }
    1823                 : 
    1824              16 :     m_eUnit = eLastUnit;
    1825              16 :     m_dfScale = dSavedScale;
    1826                 : 
    1827              16 :     CSLDestroy(papszToken2);
    1828              16 :     CSLDestroy(papszToken);
    1829                 : 
    1830              16 :     return TRUE;
    1831                 : }
    1832                 : 
    1833                 : /************************************************************************/
    1834                 : /*                   SetInternalInputUnitFromParam()                    */
    1835                 : /************************************************************************/
    1836                 : 
    1837              14 : void OGRStyleTool::SetInternalInputUnitFromParam(char *pszString)
    1838                 : {
    1839                 : 
    1840                 :     char *pszUnit;
    1841                 : 
    1842              14 :     if (pszString == NULL)
    1843               0 :       return;
    1844              14 :     pszUnit = strstr(pszString,"g");
    1845              14 :     if (pszUnit)
    1846                 :     {
    1847               8 :         SetUnit(OGRSTUGround);
    1848               8 :         pszUnit[0]= '\0';
    1849               8 :         return;
    1850                 :     }
    1851               6 :     pszUnit = strstr(pszString,"px");
    1852               6 :     if (pszUnit)
    1853                 :     {
    1854               2 :         SetUnit(OGRSTUPixel);
    1855               2 :         pszUnit[0]= '\0';
    1856               2 :         return;
    1857                 :     }
    1858               4 :     pszUnit = strstr(pszString,"pt");
    1859               4 :     if (pszUnit)
    1860                 :     {
    1861               4 :         SetUnit(OGRSTUPoints);
    1862               4 :         pszUnit[0]= '\0';
    1863               4 :         return;
    1864                 :     }
    1865               0 :     pszUnit = strstr(pszString,"mm");
    1866               0 :     if (pszUnit)
    1867                 :     {
    1868               0 :         SetUnit(OGRSTUMM);
    1869               0 :         pszUnit[0]= '\0';
    1870               0 :         return;
    1871                 :     }
    1872               0 :     pszUnit = strstr(pszString,"cm");
    1873               0 :     if (pszUnit)
    1874                 :     {
    1875               0 :         SetUnit(OGRSTUCM);
    1876               0 :         pszUnit[0]= '\0';
    1877               0 :         return;
    1878                 :     }
    1879               0 :     pszUnit = strstr(pszString,"in");
    1880               0 :     if (pszUnit)
    1881                 :     {
    1882               0 :         SetUnit(OGRSTUInches);
    1883               0 :         pszUnit[0]= '\0';
    1884               0 :         return;
    1885                 :     }
    1886                 :     
    1887               0 :     SetUnit(OGRSTUMM);
    1888                 : }
    1889                 : 
    1890                 : /************************************************************************/
    1891                 : /*                          ComputeWithUnit()                           */
    1892                 : /************************************************************************/
    1893              16 : double OGRStyleTool::ComputeWithUnit(double dfValue, OGRSTUnitId eInputUnit)
    1894                 : {
    1895              16 :     OGRSTUnitId eOutputUnit = GetUnit();
    1896                 : 
    1897              16 :     double dfNewValue = dfValue;        // dfValue in  Meter;
    1898                 : 
    1899                 : 
    1900              16 :     if (eOutputUnit == eInputUnit)
    1901               6 :       return dfValue;
    1902                 : 
    1903              10 :     switch (eInputUnit)
    1904                 :     {
    1905                 :       case OGRSTUGround:
    1906               4 :         dfNewValue = dfValue / m_dfScale;
    1907               4 :         break;
    1908                 :       case OGRSTUPixel:
    1909               2 :         dfNewValue = dfValue / (72.0 * 39.37);
    1910               2 :         break;
    1911                 :       case OGRSTUPoints:
    1912               4 :         dfNewValue =dfValue / (72.0 * 39.37);
    1913               4 :         break;
    1914                 :       case OGRSTUMM:
    1915               0 :         dfNewValue = 0.001 * dfValue;
    1916               0 :         break;
    1917                 :       case OGRSTUCM:
    1918               0 :         dfNewValue = 0.01 * dfValue;
    1919               0 :         break;
    1920                 :       case OGRSTUInches:
    1921               0 :         dfNewValue = dfValue / 39.37;
    1922                 :         break;
    1923                 :       default:
    1924                 :         break;    //imp
    1925                 :     }
    1926                 : 
    1927              10 :     switch (eOutputUnit)
    1928                 :     {
    1929                 :       case OGRSTUGround:
    1930               0 :         dfNewValue *= m_dfScale;
    1931               0 :         break;
    1932                 :       case OGRSTUPixel:
    1933               0 :         dfNewValue *= (72.0 * 39.37);
    1934               0 :         break;
    1935                 :       case OGRSTUPoints:
    1936               0 :         dfNewValue *= (72.0 * 39.37);
    1937               0 :         break;
    1938                 :       case OGRSTUMM:
    1939              10 :         dfNewValue *= 1000.0;
    1940              10 :         break;
    1941                 :       case OGRSTUCM:
    1942               0 :         dfNewValue *= 100.0;
    1943               0 :         break;
    1944                 :       case OGRSTUInches:
    1945               0 :         dfNewValue *= 39.37;
    1946                 :         break;
    1947                 :       default:
    1948                 :         break;  // imp
    1949                 :     }
    1950              10 :     return dfNewValue;
    1951                 : }
    1952                 : 
    1953                 : /************************************************************************/
    1954                 : /*                          ComputeWithUnit()                           */
    1955                 : /************************************************************************/
    1956               0 : int   OGRStyleTool::ComputeWithUnit(int nValue, OGRSTUnitId eUnit)
    1957                 : {
    1958               0 :     return (int) ComputeWithUnit((double )nValue, eUnit);
    1959                 : }
    1960                 : 
    1961                 : /************************************************************************/
    1962                 : /*                            GetParamStr()                             */
    1963                 : /************************************************************************/
    1964              36 : const char *OGRStyleTool::GetParamStr(const OGRStyleParamId &sStyleParam ,
    1965                 :                                       OGRStyleValue &sStyleValue,
    1966                 :                                       GBool &bValueIsNull)
    1967                 : {
    1968                 : 
    1969              36 :     if (!Parse())
    1970                 :     {
    1971               0 :         bValueIsNull = TRUE;
    1972               0 :         return NULL;
    1973                 :     }
    1974                 : 
    1975              36 :     bValueIsNull = !sStyleValue.bValid;
    1976                 :     
    1977              36 :     if (bValueIsNull == TRUE)
    1978               2 :       return NULL;
    1979                 : 
    1980              34 :     switch (sStyleParam.eType)
    1981                 :     {
    1982                 :       
    1983                 :         // if sStyleParam.bGeoref == TRUE , need to convert to output value;
    1984                 :       case OGRSTypeString:
    1985              34 :         return sStyleValue.pszValue;
    1986                 :       case OGRSTypeDouble:
    1987               0 :         if (sStyleParam.bGeoref)
    1988                 :           return CPLSPrintf("%f",ComputeWithUnit(sStyleValue.dfValue,
    1989               0 :                                                  sStyleValue.eUnit));
    1990                 :         else
    1991               0 :           return CPLSPrintf("%f",sStyleValue.dfValue);
    1992                 :                             
    1993                 :       case OGRSTypeInteger:
    1994               0 :         if (sStyleParam.bGeoref)
    1995                 :           return CPLSPrintf("%d",ComputeWithUnit(sStyleValue.nValue,
    1996               0 :                                                  sStyleValue.eUnit));
    1997                 :         else
    1998               0 :           return CPLSPrintf("%d",sStyleValue.nValue);
    1999                 :       case OGRSTypeBoolean:
    2000               0 :         return CPLSPrintf("%d",sStyleValue.nValue);
    2001                 :       default:
    2002               0 :         bValueIsNull = TRUE;
    2003               0 :         return NULL;
    2004                 :     }
    2005                 : }
    2006                 : 
    2007                 : /****************************************************************************/
    2008                 : /*    int OGRStyleTool::GetParamNum(OGRStyleParamId sStyleParam ,           */
    2009                 : /*                               OGRStyleValue sStyleValue,                 */
    2010                 : /*                               GBool &bValueIsNull)                       */
    2011                 : /*                                                                          */
    2012                 : /****************************************************************************/
    2013               0 : int OGRStyleTool::GetParamNum(const OGRStyleParamId &sStyleParam ,
    2014                 :                               OGRStyleValue &sStyleValue,
    2015                 :                               GBool &bValueIsNull)
    2016                 : {
    2017               0 :     return (int)GetParamDbl(sStyleParam,sStyleValue,bValueIsNull);
    2018                 : }
    2019                 : 
    2020                 : /****************************************************************************/
    2021                 : /*       double OGRStyleTool::GetParamDbl(OGRStyleParamId sStyleParam ,     */
    2022                 : /*                               OGRStyleValue sStyleValue,                 */
    2023                 : /*                               GBool &bValueIsNull)                       */
    2024                 : /*                                                                          */
    2025                 : /****************************************************************************/
    2026              20 : double OGRStyleTool::GetParamDbl(const OGRStyleParamId &sStyleParam ,
    2027                 :                                  OGRStyleValue &sStyleValue,
    2028                 :                                  GBool &bValueIsNull)
    2029                 : {
    2030              20 :     if (!Parse())
    2031                 :     {
    2032               0 :         bValueIsNull = TRUE;
    2033               0 :         return 0;
    2034                 :     }
    2035                 : 
    2036              20 :     bValueIsNull = !sStyleValue.bValid;
    2037                 :     
    2038              20 :     if (bValueIsNull == TRUE)
    2039               2 :       return 0;
    2040                 : 
    2041              18 :     switch (sStyleParam.eType)
    2042                 :     {
    2043                 :       
    2044                 :         // if sStyleParam.bGeoref == TRUE , need to convert to output value;
    2045                 :       case OGRSTypeString:
    2046               0 :         if (sStyleParam.bGeoref)
    2047                 :           return ComputeWithUnit(atof(sStyleValue.pszValue),
    2048               0 :                                  sStyleValue.eUnit);
    2049                 :         else
    2050               0 :           return atof(sStyleValue.pszValue);
    2051                 :       case OGRSTypeDouble:
    2052              18 :         if (sStyleParam.bGeoref)
    2053                 :           return ComputeWithUnit(sStyleValue.dfValue,
    2054              16 :                                       sStyleValue.eUnit);
    2055                 :         else
    2056               2 :           return sStyleValue.dfValue;
    2057                 :       case OGRSTypeInteger:
    2058               0 :         if (sStyleParam.bGeoref)
    2059                 :           return (double)ComputeWithUnit(sStyleValue.nValue,
    2060               0 :                                          sStyleValue.eUnit);
    2061                 :         else    
    2062               0 :           return (double)sStyleValue.nValue;
    2063                 :       case OGRSTypeBoolean:
    2064               0 :         return (double)sStyleValue.nValue;
    2065                 :       default:
    2066               0 :         bValueIsNull = TRUE;
    2067               0 :         return 0;
    2068                 :     }
    2069                 : }
    2070                 : 
    2071                 : /****************************************************************************/
    2072                 : /*      void OGRStyleTool::SetParamStr(OGRStyleParamId &sStyleParam ,       */
    2073                 : /*                             OGRStyleValue &sStyleValue,                  */
    2074                 : /*                             const char *pszParamString)                  */
    2075                 : /*                                                                          */
    2076                 : /****************************************************************************/
    2077             150 : void OGRStyleTool::SetParamStr(const OGRStyleParamId &sStyleParam ,
    2078                 :                                OGRStyleValue &sStyleValue,
    2079                 :                                const char *pszParamString)
    2080                 : {
    2081             150 :     Parse();
    2082             150 :     StyleModified();
    2083             150 :     sStyleValue.bValid = TRUE;
    2084             150 :     sStyleValue.eUnit = GetUnit();
    2085             150 :     switch (sStyleParam.eType)
    2086                 :     {
    2087                 :       
    2088                 :         // if sStyleParam.bGeoref == TRUE , need to convert to output value;
    2089                 :       case OGRSTypeString:
    2090             134 :         sStyleValue.pszValue = CPLStrdup(pszParamString);
    2091             134 :         break;
    2092                 :       case OGRSTypeDouble:
    2093              16 :         sStyleValue.dfValue = atof(pszParamString);
    2094              16 :         break;
    2095                 :       case OGRSTypeInteger:
    2096                 :       case OGRSTypeBoolean:
    2097               0 :         sStyleValue.nValue  = atoi(pszParamString);
    2098               0 :         break;
    2099                 :       default:
    2100               0 :         sStyleValue.bValid = FALSE;
    2101                 :         break;
    2102                 :     }
    2103             150 : }
    2104                 : 
    2105                 : /****************************************************************************/
    2106                 : /*    void OGRStyleTool::SetParamNum(OGRStyleParamId &sStyleParam ,         */
    2107                 : /*                             OGRStyleValue &sStyleValue,                  */
    2108                 : /*                             int nParam)                                  */
    2109                 : /*                                                                          */
    2110                 : /****************************************************************************/
    2111               0 : void OGRStyleTool::SetParamNum(const OGRStyleParamId &sStyleParam ,
    2112                 :                                OGRStyleValue &sStyleValue,
    2113                 :                                int nParam)
    2114                 : {
    2115               0 :     Parse();
    2116               0 :     StyleModified();
    2117               0 :     sStyleValue.bValid = TRUE;
    2118               0 :     sStyleValue.eUnit = GetUnit();
    2119               0 :     switch (sStyleParam.eType)
    2120                 :     {
    2121                 :         
    2122                 :         // if sStyleParam.bGeoref == TRUE , need to convert to output value;
    2123                 :       case OGRSTypeString:
    2124               0 :         sStyleValue.pszValue = CPLStrdup(CPLString().Printf("%d",nParam));
    2125               0 :         break;
    2126                 :       case OGRSTypeDouble:
    2127               0 :         sStyleValue.dfValue = (double)nParam;
    2128               0 :         break;
    2129                 :       case OGRSTypeInteger:
    2130                 :       case OGRSTypeBoolean:
    2131               0 :         sStyleValue.nValue  = nParam;
    2132               0 :         break;
    2133                 :       default:
    2134               0 :         sStyleValue.bValid = FALSE;
    2135                 :         break;
    2136                 :     }
    2137               0 : }
    2138                 : 
    2139                 : /****************************************************************************/
    2140                 : /*      void OGRStyleTool::SetParamDbl(OGRStyleParamId &sStyleParam ,       */
    2141                 : /*                             OGRStyleValue &sStyleValue,                  */
    2142                 : /*                             double dfParam)                              */
    2143                 : /*                                                                          */
    2144                 : /****************************************************************************/
    2145              48 : void OGRStyleTool::SetParamDbl(const OGRStyleParamId &sStyleParam ,
    2146                 :                                OGRStyleValue &sStyleValue,
    2147                 :                                double dfParam)
    2148                 : { 
    2149              48 :     Parse();
    2150              48 :     StyleModified();
    2151              48 :     sStyleValue.bValid = TRUE;
    2152              48 :     sStyleValue.eUnit = GetUnit();
    2153              48 :     switch (sStyleParam.eType)
    2154                 :     {
    2155                 :         
    2156                 :         // if sStyleParam.bGeoref == TRUE , need to convert to output value;
    2157                 :       case OGRSTypeString:
    2158               0 :         sStyleValue.pszValue = CPLStrdup(CPLString().Printf("%f",dfParam));
    2159               0 :         break;
    2160                 :       case OGRSTypeDouble:
    2161              48 :         sStyleValue.dfValue = dfParam;
    2162              48 :         break;
    2163                 :       case OGRSTypeInteger:
    2164                 :       case OGRSTypeBoolean:
    2165               0 :         sStyleValue.nValue  = (int)dfParam;
    2166               0 :         break;
    2167                 :       default:
    2168               0 :         sStyleValue.bValid = FALSE;
    2169                 :         break;
    2170                 :     }
    2171              48 : }
    2172                 : 
    2173                 : /************************************************************************/
    2174                 : /*                           OGR_ST_GetParamStr()                       */
    2175                 : /************************************************************************/
    2176                 : /**
    2177                 :  * \brief Get Style Tool parameter value as string
    2178                 :  *
    2179                 :  * Maps to the OGRStyleTool subclasses' GetParamStr() methods.
    2180                 :  * 
    2181                 :  * @param hST handle to the style tool.
    2182                 :  * @param eParam the parameter id from the enumeration corresponding to the
    2183                 :  * type of this style tool (one of the OGRSTPenParam, OGRSTBrushParam, 
    2184                 :  * OGRSTSymbolParam or OGRSTLabelParam enumerations)
    2185                 :  * @param bValueIsNull pointer to an integer that will be set to TRUE or FALSE
    2186                 :  * to indicate whether the parameter value is NULL.
    2187                 :  *
    2188                 :  * @return the parameter value as string and sets bValueIsNull.
    2189                 :  */
    2190                 : 
    2191              14 : const char *OGR_ST_GetParamStr( OGRStyleToolH hST, int eParam, int *bValueIsNull )
    2192                 : {
    2193              14 :     GBool bIsNull = TRUE;
    2194              14 :     const char *pszVal = "";
    2195                 : 
    2196              14 :     VALIDATE_POINTER1( hST, "OGR_ST_GetParamStr", "" );
    2197              14 :     VALIDATE_POINTER1( bValueIsNull, "OGR_ST_GetParamStr", "" );
    2198                 : 
    2199              14 :     switch( ((OGRStyleTool *) hST)->GetType() )
    2200                 :     {
    2201                 :       case OGRSTCPen:
    2202                 :         pszVal = ((OGRStylePen *) hST)->GetParamStr((OGRSTPenParam)eParam, 
    2203               8 :                                                     bIsNull);
    2204               8 :         break;
    2205                 :       case OGRSTCBrush:
    2206                 :         pszVal = ((OGRStyleBrush *) hST)->GetParamStr((OGRSTBrushParam)eParam, 
    2207               2 :                                                       bIsNull);
    2208               2 :         break;
    2209                 :       case OGRSTCSymbol:
    2210                 :         pszVal = ((OGRStyleSymbol *) hST)->GetParamStr((OGRSTSymbolParam)eParam,
    2211               0 :                                                        bIsNull);
    2212               0 :         break;
    2213                 :       case OGRSTCLabel:
    2214                 :         pszVal = ((OGRStyleLabel *) hST)->GetParamStr((OGRSTLabelParam)eParam, 
    2215               4 :                                                       bIsNull);
    2216                 :         break;
    2217                 :       default:
    2218                 :         break;
    2219                 :     }
    2220                 : 
    2221              14 :     *bValueIsNull = bIsNull;
    2222              14 :     return pszVal;
    2223                 : }
    2224                 : 
    2225                 : /************************************************************************/
    2226                 : /*                           OGR_ST_GetParamNum()                       */
    2227                 : /************************************************************************/
    2228                 : /**
    2229                 :  * \brief Get Style Tool parameter value as an integer
    2230                 :  *
    2231                 :  * Maps to the OGRStyleTool subclasses' GetParamNum() methods.
    2232                 :  * 
    2233                 :  * @param hST handle to the style tool.
    2234                 :  * @param eParam the parameter id from the enumeration corresponding to the
    2235                 :  * type of this style tool (one of the OGRSTPenParam, OGRSTBrushParam, 
    2236                 :  * OGRSTSymbolParam or OGRSTLabelParam enumerations)
    2237                 :  * @param bValueIsNull pointer to an integer that will be set to TRUE or FALSE
    2238                 :  * to indicate whether the parameter value is NULL.
    2239                 :  *
    2240                 :  * @return the parameter value as integer and sets bValueIsNull.
    2241                 :  */
    2242                 : 
    2243               0 : int OGR_ST_GetParamNum( OGRStyleToolH hST, int eParam, int *bValueIsNull )
    2244                 : {
    2245               0 :     GBool bIsNull = TRUE;
    2246               0 :     int nVal = 0;
    2247                 : 
    2248               0 :     VALIDATE_POINTER1( hST, "OGR_ST_GetParamNum", 0 );
    2249               0 :     VALIDATE_POINTER1( bValueIsNull, "OGR_ST_GetParamNum", 0 );
    2250                 : 
    2251               0 :     switch( ((OGRStyleTool *) hST)->GetType() )
    2252                 :     {
    2253                 :       case OGRSTCPen:
    2254                 :         nVal = ((OGRStylePen *) hST)->GetParamNum((OGRSTPenParam)eParam, 
    2255               0 :                                                     bIsNull);
    2256               0 :         break;
    2257                 :       case OGRSTCBrush:
    2258                 :         nVal = ((OGRStyleBrush *) hST)->GetParamNum((OGRSTBrushParam)eParam, 
    2259               0 :                                                       bIsNull);
    2260               0 :         break;
    2261                 :       case OGRSTCSymbol:
    2262                 :         nVal = ((OGRStyleSymbol *) hST)->GetParamNum((OGRSTSymbolParam)eParam,
    2263               0 :                                                        bIsNull);
    2264               0 :         break;
    2265                 :       case OGRSTCLabel:
    2266                 :         nVal = ((OGRStyleLabel *) hST)->GetParamNum((OGRSTLabelParam)eParam, 
    2267               0 :                                                       bIsNull);
    2268                 :         break;
    2269                 :       default:
    2270                 :         break;
    2271                 :     }
    2272                 : 
    2273               0 :     *bValueIsNull = bIsNull;
    2274               0 :     return nVal;
    2275                 : }
    2276                 : 
    2277                 : /************************************************************************/
    2278                 : /*                           OGR_ST_GetParamDbl()                       */
    2279                 : /************************************************************************/
    2280                 : /**
    2281                 :  * \brief Get Style Tool parameter value as a double
    2282                 :  *
    2283                 :  * Maps to the OGRStyleTool subclasses' GetParamDbl() methods.
    2284                 :  * 
    2285                 :  * @param hST handle to the style tool.
    2286                 :  * @param eParam the parameter id from the enumeration corresponding to the
    2287                 :  * type of this style tool (one of the OGRSTPenParam, OGRSTBrushParam, 
    2288                 :  * OGRSTSymbolParam or OGRSTLabelParam enumerations)
    2289                 :  * @param bValueIsNull pointer to an integer that will be set to TRUE or FALSE
    2290                 :  * to indicate whether the parameter value is NULL.
    2291                 :  *
    2292                 :  * @return the parameter value as double and sets bValueIsNull.
    2293                 :  */
    2294                 : 
    2295               8 : double OGR_ST_GetParamDbl( OGRStyleToolH hST, int eParam, int *bValueIsNull )
    2296                 : {
    2297               8 :     GBool bIsNull = TRUE;
    2298               8 :     double dfVal = 0.0;
    2299                 : 
    2300               8 :     VALIDATE_POINTER1( hST, "OGR_ST_GetParamDbl", 0.0 );
    2301               8 :     VALIDATE_POINTER1( bValueIsNull, "OGR_ST_GetParamDbl", 0.0 );
    2302                 : 
    2303               8 :     switch( ((OGRStyleTool *) hST)->GetType() )
    2304                 :     {
    2305                 :       case OGRSTCPen:
    2306                 :         dfVal = ((OGRStylePen *) hST)->GetParamDbl((OGRSTPenParam)eParam, 
    2307               4 :                                                   bIsNull);
    2308               4 :         break;
    2309                 :       case OGRSTCBrush:
    2310                 :         dfVal = ((OGRStyleBrush *) hST)->GetParamDbl((OGRSTBrushParam)eParam, 
    2311               0 :                                                     bIsNull);
    2312               0 :         break;
    2313                 :       case OGRSTCSymbol:
    2314                 :         dfVal = ((OGRStyleSymbol *) hST)->GetParamDbl((OGRSTSymbolParam)eParam,
    2315               0 :                                                      bIsNull);
    2316               0 :         break;
    2317                 :       case OGRSTCLabel:
    2318                 :         dfVal = ((OGRStyleLabel *) hST)->GetParamDbl((OGRSTLabelParam)eParam, 
    2319               4 :                                                     bIsNull);
    2320                 :         break;
    2321                 :       default:
    2322                 :         break;
    2323                 :     }
    2324                 : 
    2325               8 :     *bValueIsNull = bIsNull;
    2326               8 :     return dfVal;
    2327                 : }
    2328                 : 
    2329                 : 
    2330                 : /************************************************************************/
    2331                 : /*                           OGR_ST_SetParamStr()                       */
    2332                 : /************************************************************************/
    2333                 : /**
    2334                 :  * \brief Set Style Tool parameter value from a string
    2335                 :  *
    2336                 :  * Maps to the OGRStyleTool subclasses' SetParamStr() methods.
    2337                 :  * 
    2338                 :  * @param hST handle to the style tool.
    2339                 :  * @param eParam the parameter id from the enumeration corresponding to the
    2340                 :  * type of this style tool (one of the OGRSTPenParam, OGRSTBrushParam, 
    2341                 :  * OGRSTSymbolParam or OGRSTLabelParam enumerations)
    2342                 :  * @param pszValue the new parameter value
    2343                 :  *
    2344                 :  */
    2345                 : 
    2346               0 : void OGR_ST_SetParamStr( OGRStyleToolH hST, int eParam, const char *pszValue )
    2347                 : {
    2348               0 :     VALIDATE_POINTER0( hST, "OGR_ST_SetParamStr" );
    2349               0 :     VALIDATE_POINTER0( pszValue, "OGR_ST_SetParamStr" );
    2350                 : 
    2351               0 :     switch( ((OGRStyleTool *) hST)->GetType() )
    2352                 :     {
    2353                 :       case OGRSTCPen:
    2354                 :         ((OGRStylePen *) hST)->SetParamStr((OGRSTPenParam)eParam, 
    2355               0 :                                            pszValue);
    2356               0 :         break;
    2357                 :       case OGRSTCBrush:
    2358                 :         ((OGRStyleBrush *) hST)->SetParamStr((OGRSTBrushParam)eParam, 
    2359               0 :                                              pszValue);
    2360               0 :         break;
    2361                 :       case OGRSTCSymbol:
    2362                 :         ((OGRStyleSymbol *) hST)->SetParamStr((OGRSTSymbolParam)eParam,
    2363               0 :                                               pszValue);
    2364               0 :         break;
    2365                 :       case OGRSTCLabel:
    2366                 :         ((OGRStyleLabel *) hST)->SetParamStr((OGRSTLabelParam)eParam, 
    2367               0 :                                              pszValue);
    2368                 :         break;
    2369                 :       default:
    2370                 :         break;
    2371                 :     }
    2372                 : }
    2373                 : 
    2374                 : 
    2375                 : /************************************************************************/
    2376                 : /*                           OGR_ST_SetParamNum()                       */
    2377                 : /************************************************************************/
    2378                 : /**
    2379                 :  * \brief Set Style Tool parameter value from an integer
    2380                 :  *
    2381                 :  * Maps to the OGRStyleTool subclasses' SetParamNum() methods.
    2382                 :  * 
    2383                 :  * @param hST handle to the style tool.
    2384                 :  * @param eParam the parameter id from the enumeration corresponding to the
    2385                 :  * type of this style tool (one of the OGRSTPenParam, OGRSTBrushParam, 
    2386                 :  * OGRSTSymbolParam or OGRSTLabelParam enumerations)
    2387                 :  * @param nValue the new parameter value
    2388                 :  *
    2389                 :  */
    2390                 : 
    2391               0 : void OGR_ST_SetParamNum( OGRStyleToolH hST, int eParam, int nValue )
    2392                 : {
    2393               0 :     VALIDATE_POINTER0( hST, "OGR_ST_SetParamNum" );
    2394                 : 
    2395               0 :     switch( ((OGRStyleTool *) hST)->GetType() )
    2396                 :     {
    2397                 :       case OGRSTCPen:
    2398                 :         ((OGRStylePen *) hST)->SetParamNum((OGRSTPenParam)eParam, 
    2399               0 :                                            nValue);
    2400               0 :         break;
    2401                 :       case OGRSTCBrush:
    2402                 :         ((OGRStyleBrush *) hST)->SetParamNum((OGRSTBrushParam)eParam, 
    2403               0 :                                              nValue);
    2404               0 :         break;
    2405                 :       case OGRSTCSymbol:
    2406                 :         ((OGRStyleSymbol *) hST)->SetParamNum((OGRSTSymbolParam)eParam,
    2407               0 :                                               nValue);
    2408               0 :         break;
    2409                 :       case OGRSTCLabel:
    2410                 :         ((OGRStyleLabel *) hST)->SetParamNum((OGRSTLabelParam)eParam, 
    2411               0 :                                              nValue);
    2412                 :         break;
    2413                 :       default:
    2414                 :         break;
    2415                 :     }
    2416                 : }
    2417                 : 
    2418                 : /************************************************************************/
    2419                 : /*                           OGR_ST_SetParamDbl()                       */
    2420                 : /************************************************************************/
    2421                 : /**
    2422                 :  * \brief Set Style Tool parameter value from a double
    2423                 :  *
    2424                 :  * Maps to the OGRStyleTool subclasses' SetParamDbl() methods.
    2425                 :  * 
    2426                 :  * @param hST handle to the style tool.
    2427                 :  * @param eParam the parameter id from the enumeration corresponding to the
    2428                 :  * type of this style tool (one of the OGRSTPenParam, OGRSTBrushParam, 
    2429                 :  * OGRSTSymbolParam or OGRSTLabelParam enumerations)
    2430                 :  * @param dfValue the new parameter value
    2431                 :  *
    2432                 :  */
    2433                 : 
    2434               0 : void OGR_ST_SetParamDbl( OGRStyleToolH hST, int eParam, double dfValue )
    2435                 : {
    2436               0 :     VALIDATE_POINTER0( hST, "OGR_ST_SetParamDbl" );
    2437                 : 
    2438               0 :     switch( ((OGRStyleTool *) hST)->GetType() )
    2439                 :     {
    2440                 :       case OGRSTCPen:
    2441                 :         ((OGRStylePen *) hST)->SetParamDbl((OGRSTPenParam)eParam, 
    2442               0 :                                            dfValue);
    2443               0 :         break;
    2444                 :       case OGRSTCBrush:
    2445                 :         ((OGRStyleBrush *) hST)->SetParamDbl((OGRSTBrushParam)eParam, 
    2446               0 :                                              dfValue);
    2447               0 :         break;
    2448                 :       case OGRSTCSymbol:
    2449                 :         ((OGRStyleSymbol *) hST)->SetParamDbl((OGRSTSymbolParam)eParam,
    2450               0 :                                               dfValue);
    2451               0 :         break;
    2452                 :       case OGRSTCLabel:
    2453                 :         ((OGRStyleLabel *) hST)->SetParamDbl((OGRSTLabelParam)eParam, 
    2454               0 :                                              dfValue);
    2455                 :         break;
    2456                 :       default:
    2457                 :         break;
    2458                 :     }
    2459                 : }
    2460                 : 
    2461                 : 
    2462                 : /************************************************************************/
    2463                 : /*                           OGR_ST_GetStyleString()                    */
    2464                 : /************************************************************************/
    2465                 : /**
    2466                 :  * \brief Get the style string for this Style Tool
    2467                 :  *
    2468                 :  * Maps to the OGRStyleTool subclasses' GetStyleString() methods.
    2469                 :  * 
    2470                 :  * @param hST handle to the style tool.
    2471                 :  *
    2472                 :  * @return the style string for this style tool or "" if the hST is invalid.
    2473                 :  */
    2474                 : 
    2475               0 : const char *OGR_ST_GetStyleString( OGRStyleToolH hST )
    2476                 : {
    2477               0 :     const char *pszVal = "";
    2478                 : 
    2479               0 :     VALIDATE_POINTER1( hST, "OGR_ST_GetStyleString", "" );
    2480                 : 
    2481               0 :     switch( ((OGRStyleTool *) hST)->GetType() )
    2482                 :     {
    2483                 :       case OGRSTCPen:
    2484               0 :         pszVal = ((OGRStylePen *) hST)->GetStyleString();
    2485               0 :         break;
    2486                 :       case OGRSTCBrush:
    2487               0 :         pszVal = ((OGRStyleBrush *) hST)->GetStyleString();
    2488               0 :         break;
    2489                 :       case OGRSTCSymbol:
    2490               0 :         pszVal = ((OGRStyleSymbol *) hST)->GetStyleString();
    2491               0 :         break;
    2492                 :       case OGRSTCLabel:
    2493               0 :         pszVal = ((OGRStyleLabel *) hST)->GetStyleString();
    2494                 :         break;
    2495                 :       default:
    2496                 :         break;
    2497                 :     }
    2498                 : 
    2499               0 :     return pszVal;
    2500                 : }
    2501                 : 
    2502                 : /************************************************************************/
    2503                 : /*                           OGR_ST_GetRGBFromString()                  */
    2504                 : /************************************************************************/
    2505                 : /**
    2506                 :  * \brief Return the r,g,b,a components of a color encoded in \#RRGGBB[AA] format
    2507                 :  *
    2508                 :  * Maps to OGRStyleTool::GetRGBFromString().
    2509                 :  * 
    2510                 :  * @param hST handle to the style tool.
    2511                 :  * @param pszColor the color to parse
    2512                 :  * @param pnRed pointer to an int in which the red value will be returned
    2513                 :  * @param pnGreen pointer to an int in which the green value will be returned
    2514                 :  * @param pnBlue pointer to an int in which the blue value will be returned
    2515                 :  * @param pnAlpha pointer to an int in which the (optional) alpha value will
    2516                 :  * be returned
    2517                 :  *
    2518                 :  * @return TRUE if the color could be succesfully parsed, or FALSE in case of
    2519                 :  * errors.
    2520                 :  */
    2521                 : 
    2522               0 : int OGR_ST_GetRGBFromString( OGRStyleToolH hST, const char *pszColor, 
    2523                 :                              int *pnRed, int *pnGreen, int *pnBlue,
    2524                 :                              int *pnAlpha )
    2525                 : {
    2526                 : 
    2527               0 :     VALIDATE_POINTER1( hST, "OGR_ST_GetRGBFromString", FALSE );
    2528               0 :     VALIDATE_POINTER1( pnRed, "OGR_ST_GetRGBFromString", FALSE );
    2529               0 :     VALIDATE_POINTER1( pnGreen, "OGR_ST_GetRGBFromString", FALSE );
    2530               0 :     VALIDATE_POINTER1( pnBlue, "OGR_ST_GetRGBFromString", FALSE );
    2531               0 :     VALIDATE_POINTER1( pnAlpha, "OGR_ST_GetRGBFromString", FALSE );
    2532                 : 
    2533                 :     return ((OGRStyleTool *) hST)->GetRGBFromString(pszColor, *pnRed, *pnGreen,
    2534               0 :                                                     *pnBlue, *pnAlpha );
    2535                 : }
    2536                 : 
    2537                 : 
    2538                 : /* ======================================================================== */
    2539                 : /*                OGRStylePen                                               */
    2540                 : /*       Specific parameter (Set/Get) for the StylePen                      */
    2541                 : /* ======================================================================== */
    2542                 : 
    2543                 : 
    2544                 : /****************************************************************************/
    2545                 : /*                      OGRStylePen::OGRStylePen()                          */
    2546                 : /*                                                                          */
    2547                 : /****************************************************************************/
    2548             124 : OGRStylePen::OGRStylePen() : OGRStyleTool(OGRSTCPen)
    2549                 : {
    2550                 :     m_pasStyleValue = (OGRStyleValue *)CPLCalloc(OGRSTPenLast, 
    2551             124 :                                                  sizeof(OGRStyleValue));
    2552             124 : }
    2553                 : 
    2554                 : 
    2555                 : 
    2556                 : 
    2557                 : /****************************************************************************/
    2558                 : /*                      OGRStylePen::~OGRStylePen()                         */
    2559                 : /*                                                                          */
    2560                 : /****************************************************************************/
    2561             124 : OGRStylePen::~OGRStylePen()
    2562                 : {
    2563            1116 :     for (int i = 0; i < OGRSTPenLast; i++)
    2564                 :     {
    2565             992 :         if (m_pasStyleValue[i].pszValue != NULL)
    2566                 :         {
    2567              48 :             CPLFree(m_pasStyleValue[i].pszValue);
    2568              48 :             m_pasStyleValue[i].pszValue = NULL;
    2569                 :         }
    2570                 :     }
    2571                 : 
    2572             124 :     CPLFree(m_pasStyleValue);
    2573             124 : }
    2574                 : 
    2575                 : /************************************************************************/
    2576                 : /*                         OGRStylePen::Parse()                         */
    2577                 : /************************************************************************/
    2578             140 : GBool OGRStylePen::Parse()
    2579                 : 
    2580                 : { 
    2581             140 :     return OGRStyleTool::Parse(asStylePen,m_pasStyleValue,(int)OGRSTPenLast);
    2582                 : }
    2583                 : 
    2584                 : /************************************************************************/
    2585                 : /*                            GetParamStr()                             */
    2586                 : /************************************************************************/
    2587              24 : const char *OGRStylePen::GetParamStr(OGRSTPenParam eParam, GBool &bValueIsNull)
    2588                 : {   
    2589              24 :     return OGRStyleTool::GetParamStr(asStylePen[eParam],
    2590                 :                                      m_pasStyleValue[eParam],
    2591              48 :                                      bValueIsNull);
    2592                 : }
    2593                 : 
    2594                 : /************************************************************************/
    2595                 : /*                            GetParamNum()                             */
    2596                 : /************************************************************************/
    2597               0 : int OGRStylePen::GetParamNum(OGRSTPenParam eParam,GBool &bValueIsNull)
    2598                 : {  
    2599               0 :     return OGRStyleTool::GetParamNum(asStylePen[eParam],
    2600               0 :                                      m_pasStyleValue[eParam],bValueIsNull);
    2601                 : }
    2602                 : 
    2603                 : /************************************************************************/
    2604                 : /*                            GetParamDbl()                             */
    2605                 : /************************************************************************/
    2606              10 : double OGRStylePen::GetParamDbl(OGRSTPenParam eParam,GBool &bValueIsNull)
    2607                 : {  
    2608              10 :     return OGRStyleTool::GetParamDbl(asStylePen[eParam],
    2609              20 :                                      m_pasStyleValue[eParam],bValueIsNull);
    2610                 : }
    2611                 : 
    2612                 : /************************************************************************/
    2613                 : /*                            SetParamStr()                             */
    2614                 : /************************************************************************/
    2615                 : 
    2616              30 : void OGRStylePen::SetParamStr(OGRSTPenParam eParam, const char *pszParamString)
    2617                 : {   
    2618              30 :     OGRStyleTool::SetParamStr(asStylePen[eParam],m_pasStyleValue[eParam],
    2619              60 :                               pszParamString);
    2620              30 : }
    2621                 : 
    2622                 : /************************************************************************/
    2623                 : /*                            SetParamNum()                             */
    2624                 : /************************************************************************/
    2625               0 : void OGRStylePen::SetParamNum(OGRSTPenParam eParam, int nParam)
    2626                 : {  
    2627               0 :     OGRStyleTool::SetParamNum(asStylePen[eParam],
    2628               0 :                               m_pasStyleValue[eParam],nParam);
    2629               0 : }
    2630                 :     
    2631                 : /************************************************************************/
    2632                 : /*                            SetParamDbl()                             */
    2633                 : /************************************************************************/
    2634              48 : void OGRStylePen::SetParamDbl(OGRSTPenParam eParam, double dfParam)
    2635                 : {   
    2636              48 :     OGRStyleTool::SetParamDbl(asStylePen[eParam],
    2637              96 :                               m_pasStyleValue[eParam],dfParam);
    2638              48 : }
    2639                 : 
    2640                 : /************************************************************************/
    2641                 : /*                           GetStyleString()                           */
    2642                 : /************************************************************************/
    2643             228 : const char *OGRStylePen::GetStyleString()
    2644                 : {   
    2645                 :     return OGRStyleTool::GetStyleString(asStylePen,m_pasStyleValue,
    2646             228 :                                         (int)OGRSTPenLast);
    2647                 : }
    2648                 : 
    2649                 : /****************************************************************************/
    2650                 : /*                      OGRStyleBrush::OGRStyleBrush()                      */
    2651                 : /*                                                                          */
    2652                 : /****************************************************************************/
    2653              50 : OGRStyleBrush::OGRStyleBrush() : OGRStyleTool(OGRSTCBrush)
    2654                 : {
    2655                 :     m_pasStyleValue = (OGRStyleValue *)CPLCalloc(OGRSTBrushLast, 
    2656              50 :                                                  sizeof(OGRStyleValue));
    2657              50 : }
    2658                 : 
    2659                 : /****************************************************************************/
    2660                 : /*                      OGRStyleBrush::~OGRStyleBrush()                     */
    2661                 : /*                                                                          */
    2662                 : /****************************************************************************/
    2663              50 : OGRStyleBrush::~OGRStyleBrush() 
    2664                 : {
    2665             450 :     for (int i = 0; i < OGRSTBrushLast; i++)
    2666                 :     {
    2667             400 :         if (m_pasStyleValue[i].pszValue != NULL)
    2668                 :         {
    2669              50 :             CPLFree(m_pasStyleValue[i].pszValue);
    2670              50 :             m_pasStyleValue[i].pszValue = NULL;
    2671                 :         }
    2672                 :     }
    2673                 : 
    2674              50 :     CPLFree(m_pasStyleValue);
    2675              50 : }
    2676                 : 
    2677                 : /************************************************************************/
    2678                 : /*                               Parse()                                */
    2679                 : /************************************************************************/
    2680              52 : GBool OGRStyleBrush::Parse()
    2681                 : { 
    2682                 :     return OGRStyleTool::Parse(asStyleBrush,m_pasStyleValue,
    2683              52 :                                (int)OGRSTBrushLast);
    2684                 : }
    2685                 : 
    2686                 : /************************************************************************/
    2687                 : /*                            GetParamStr()                             */
    2688                 : /************************************************************************/
    2689               2 : const char *OGRStyleBrush::GetParamStr(OGRSTBrushParam eParam, GBool &bValueIsNull)
    2690                 : {  
    2691               2 :     return OGRStyleTool::GetParamStr(asStyleBrush[eParam],
    2692                 :                                      m_pasStyleValue[eParam],
    2693               4 :                                      bValueIsNull);
    2694                 : }
    2695                 : 
    2696                 : /************************************************************************/
    2697                 : /*                            GetParamNum()                             */
    2698                 : /************************************************************************/
    2699               0 : int OGRStyleBrush::GetParamNum(OGRSTBrushParam eParam,GBool &bValueIsNull)
    2700                 : {  
    2701               0 :     return OGRStyleTool::GetParamNum(asStyleBrush[eParam],
    2702               0 :                                      m_pasStyleValue[eParam],bValueIsNull);
    2703                 : }
    2704                 : 
    2705                 : /************************************************************************/
    2706                 : /*                            GetParamDbl()                             */
    2707                 : /************************************************************************/
    2708               0 : double OGRStyleBrush::GetParamDbl(OGRSTBrushParam eParam,GBool &bValueIsNull)
    2709                 : {  
    2710               0 :     return OGRStyleTool::GetParamDbl(asStyleBrush[eParam],
    2711               0 :                                      m_pasStyleValue[eParam],bValueIsNull);
    2712                 : }
    2713                 : 
    2714                 : /************************************************************************/
    2715                 : /*                            SetParamStr()                             */
    2716                 : /************************************************************************/
    2717              48 : void OGRStyleBrush::SetParamStr(OGRSTBrushParam eParam, const char *pszParamString)
    2718                 : {   
    2719              48 :     OGRStyleTool::SetParamStr(asStyleBrush[eParam],m_pasStyleValue[eParam],
    2720              96 :                               pszParamString);
    2721              48 : }
    2722                 : 
    2723                 : /************************************************************************/
    2724                 : /*                            SetParamNum()                             */
    2725                 : /************************************************************************/
    2726               0 : void OGRStyleBrush::SetParamNum(OGRSTBrushParam eParam, int nParam)
    2727                 : {  
    2728               0 :     OGRStyleTool::SetParamNum(asStyleBrush[eParam],
    2729               0 :                               m_pasStyleValue[eParam],nParam);
    2730               0 : }
    2731                 :     
    2732                 : /************************************************************************/
    2733                 : /*                            SetParamDbl()                             */
    2734                 : /************************************************************************/
    2735               0 : void OGRStyleBrush::SetParamDbl(OGRSTBrushParam eParam, double dfParam)
    2736                 : {   
    2737               0 :     OGRStyleTool::SetParamDbl(asStyleBrush[eParam],
    2738               0 :                               m_pasStyleValue[eParam],dfParam);
    2739               0 : }
    2740                 : 
    2741                 : /************************************************************************/
    2742                 : /*                           GetStyleString()                           */
    2743                 : /************************************************************************/
    2744              96 : const char *OGRStyleBrush::GetStyleString()
    2745                 : {   
    2746                 :     return OGRStyleTool::GetStyleString(asStyleBrush,m_pasStyleValue,
    2747              96 :                                         (int)OGRSTBrushLast);
    2748                 : }
    2749                 : 
    2750                 : /****************************************************************************/
    2751                 : /*                      OGRStyleSymbol::OGRStyleSymbol()                    */
    2752                 : /****************************************************************************/
    2753              24 : OGRStyleSymbol::OGRStyleSymbol() : OGRStyleTool(OGRSTCSymbol)
    2754                 : {
    2755                 :     m_pasStyleValue = (OGRStyleValue *)CPLCalloc(OGRSTSymbolLast, 
    2756              24 :                                                  sizeof(OGRStyleValue));
    2757              24 : }
    2758                 : 
    2759                 : /****************************************************************************/
    2760                 : /*                      OGRStyleSymbol::~OGRStyleSymbol()                   */
    2761                 : /*                                                                          */
    2762                 : /****************************************************************************/
    2763              24 : OGRStyleSymbol::~OGRStyleSymbol()
    2764                 : {
    2765             312 :     for (int i = 0; i < OGRSTSymbolLast; i++)
    2766                 :     {
    2767             288 :         if (m_pasStyleValue[i].pszValue != NULL)
    2768                 :         {
    2769              24 :             CPLFree(m_pasStyleValue[i].pszValue);
    2770              24 :             m_pasStyleValue[i].pszValue = NULL;
    2771                 :         }
    2772                 :     }
    2773                 : 
    2774              24 :     CPLFree(m_pasStyleValue);
    2775              24 : }
    2776                 : 
    2777                 : /************************************************************************/
    2778                 : /*                               Parse()                                */
    2779                 : /************************************************************************/
    2780              24 : GBool OGRStyleSymbol::Parse()
    2781                 : { 
    2782                 :     return OGRStyleTool::Parse(asStyleSymbol,m_pasStyleValue,
    2783              24 :                                (int)OGRSTSymbolLast);
    2784                 : }
    2785                 : 
    2786                 : /************************************************************************/
    2787                 : /*                            GetParamStr()                             */
    2788                 : /************************************************************************/
    2789               0 : const char *OGRStyleSymbol::GetParamStr(OGRSTSymbolParam eParam, GBool &bValueIsNull)
    2790               0 : {   return OGRStyleTool::GetParamStr(asStyleSymbol[eParam],
    2791                 :                                      m_pasStyleValue[eParam],
    2792               0 :                                      bValueIsNull);
    2793                 : }
    2794                 : /************************************************************************/
    2795                 : /*                            GetParamNum()                             */
    2796                 : /************************************************************************/
    2797               0 : int OGRStyleSymbol::GetParamNum(OGRSTSymbolParam eParam,GBool &bValueIsNull)
    2798               0 : {  return OGRStyleTool::GetParamNum(asStyleSymbol[eParam],
    2799               0 :                                     m_pasStyleValue[eParam],bValueIsNull);
    2800                 : }
    2801                 : /************************************************************************/
    2802                 : /*                            GetParamDbl()                             */
    2803                 : /************************************************************************/
    2804               0 : double OGRStyleSymbol::GetParamDbl(OGRSTSymbolParam eParam,GBool &bValueIsNull)
    2805               0 : {  return OGRStyleTool::GetParamDbl(asStyleSymbol[eParam],
    2806               0 :                                     m_pasStyleValue[eParam],bValueIsNull);
    2807                 : }
    2808                 : 
    2809                 : /************************************************************************/
    2810                 : /*                            SetParamStr()                             */
    2811                 : /************************************************************************/
    2812              24 : void OGRStyleSymbol::SetParamStr(OGRSTSymbolParam eParam, const char *pszParamString)
    2813              24 : {   OGRStyleTool::SetParamStr(asStyleSymbol[eParam],m_pasStyleValue[eParam],
    2814              48 :                               pszParamString);
    2815              24 : }
    2816                 : 
    2817                 : /************************************************************************/
    2818                 : /*                            SetParamNum()                             */
    2819                 : /************************************************************************/
    2820               0 : void OGRStyleSymbol::SetParamNum(OGRSTSymbolParam eParam, int nParam)
    2821               0 : {  OGRStyleTool::SetParamNum(asStyleSymbol[eParam],
    2822               0 :                              m_pasStyleValue[eParam],nParam);
    2823               0 : }
    2824                 : 
    2825                 : /************************************************************************/
    2826                 : /*                            SetParamDbl()                             */
    2827                 : /************************************************************************/
    2828               0 : void OGRStyleSymbol::SetParamDbl(OGRSTSymbolParam eParam, double dfParam)
    2829               0 :         {   OGRStyleTool::SetParamDbl(asStyleSymbol[eParam],
    2830               0 :                                       m_pasStyleValue[eParam],dfParam);
    2831               0 :         }
    2832                 : /************************************************************************/
    2833                 : /*                           GetStyleString()                           */
    2834                 : /************************************************************************/
    2835              48 : const char *OGRStyleSymbol::GetStyleString()
    2836                 : {   
    2837                 :     return OGRStyleTool::GetStyleString(asStyleSymbol,m_pasStyleValue,
    2838              48 :                                         (int)OGRSTSymbolLast);
    2839                 : }
    2840                 : 
    2841                 : 
    2842                 : /****************************************************************************/
    2843                 : /*                      OGRStyleLabel::OGRStyleLabel()                      */
    2844                 : /*                                                                          */
    2845                 : /****************************************************************************/
    2846               4 : OGRStyleLabel::OGRStyleLabel() : OGRStyleTool(OGRSTCLabel)
    2847                 : {
    2848                 :     m_pasStyleValue = (OGRStyleValue *)CPLCalloc(OGRSTLabelLast, 
    2849               4 :                                                  sizeof(OGRStyleValue));
    2850               4 : }
    2851                 : 
    2852                 : /****************************************************************************/
    2853                 : /*                      OGRStyleLabel::~OGRStyleLabel()                     */
    2854                 : /*                                                                          */
    2855                 : /****************************************************************************/
    2856               4 : OGRStyleLabel::~OGRStyleLabel()
    2857                 : {
    2858              88 :     for (int i = 0; i < OGRSTLabelLast; i++)
    2859                 :     {
    2860              84 :         if (m_pasStyleValue[i].pszValue != NULL)
    2861                 :         {
    2862              12 :             CPLFree(m_pasStyleValue[i].pszValue);
    2863              12 :             m_pasStyleValue[i].pszValue = NULL;
    2864                 :         }
    2865                 :     }
    2866                 : 
    2867               4 :     CPLFree(m_pasStyleValue);
    2868               4 : }
    2869                 : 
    2870                 : /************************************************************************/
    2871                 : /*                               Parse()                                */
    2872                 : /************************************************************************/
    2873              38 : GBool OGRStyleLabel::Parse()
    2874                 : { return OGRStyleTool::Parse(asStyleLabel,m_pasStyleValue,
    2875              38 :                              (int)OGRSTLabelLast);
    2876                 : }
    2877                 : 
    2878                 : /************************************************************************/
    2879                 : /*                            GetParamStr()                             */
    2880                 : /************************************************************************/
    2881              10 : const char *OGRStyleLabel::GetParamStr(OGRSTLabelParam eParam, GBool &bValueIsNull)
    2882              10 : {   return OGRStyleTool::GetParamStr(asStyleLabel[eParam],
    2883                 :                                      m_pasStyleValue[eParam],
    2884              20 :                                      bValueIsNull);
    2885                 : }
    2886                 : /************************************************************************/
    2887                 : /*                            GetParamNum()                             */
    2888                 : /************************************************************************/
    2889               0 : int OGRStyleLabel::GetParamNum(OGRSTLabelParam eParam,GBool &bValueIsNull)
    2890               0 : {  return OGRStyleTool::GetParamNum(asStyleLabel[eParam],
    2891               0 :                                     m_pasStyleValue[eParam],bValueIsNull);
    2892                 : }
    2893                 : /************************************************************************/
    2894                 : /*                            GetParamDbl()                             */
    2895                 : /************************************************************************/
    2896              10 : double OGRStyleLabel::GetParamDbl(OGRSTLabelParam eParam,GBool &bValueIsNull)
    2897              10 : {  return OGRStyleTool::GetParamDbl(asStyleLabel[eParam],
    2898              20 :                                     m_pasStyleValue[eParam],bValueIsNull);
    2899                 : }
    2900                 : /************************************************************************/
    2901                 : /*                            SetParamStr()                             */
    2902                 : /************************************************************************/
    2903               0 : void OGRStyleLabel::SetParamStr(OGRSTLabelParam eParam, const char *pszParamString)
    2904               0 : {   OGRStyleTool::SetParamStr(asStyleLabel[eParam],m_pasStyleValue[eParam],
    2905               0 :                               pszParamString);
    2906               0 : }
    2907                 : /************************************************************************/
    2908                 : /*                            SetParamNum()                             */
    2909                 : /************************************************************************/
    2910               0 : void OGRStyleLabel::SetParamNum(OGRSTLabelParam eParam, int nParam)
    2911               0 : {  OGRStyleTool::SetParamNum(asStyleLabel[eParam],
    2912               0 :                              m_pasStyleValue[eParam],nParam);
    2913               0 : }
    2914                 : 
    2915                 : /************************************************************************/
    2916                 : /*                            SetParamDbl()                             */
    2917                 : /************************************************************************/
    2918               0 : void OGRStyleLabel::SetParamDbl(OGRSTLabelParam eParam, double dfParam)
    2919               0 : {   OGRStyleTool::SetParamDbl(asStyleLabel[eParam],
    2920               0 :                               m_pasStyleValue[eParam],dfParam);
    2921               0 : }
    2922                 : /************************************************************************/
    2923                 : /*                           GetStyleString()                           */
    2924                 : /************************************************************************/
    2925               0 : const char *OGRStyleLabel::GetStyleString()
    2926                 : {   return OGRStyleTool::GetStyleString(asStyleLabel,m_pasStyleValue,
    2927               0 :                                         (int)OGRSTLabelLast);
    2928                 : }
    2929                 : 

Generated by: LCOV version 1.7