LTP GCOV extension - code coverage report
Current view: directory - ogr - ogrfeaturestyle.cpp
Test: gdal_filtered.info
Date: 2010-07-12 Instrumented lines: 801
Code covered: 36.7 % Executed lines: 294

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

Generated by: LTP GCOV extension version 1.5