LCOV - code coverage report
Current view: directory - ogr - ogrfeaturestyle.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 827 158 19.1 %
Date: 2010-01-09 Functions: 123 23 18.7 %

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

Generated by: LCOV version 1.7