LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/gft - ogr_gft.h (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 12 9 75.0 %
Date: 2011-12-18 Functions: 12 9 75.0 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogr_gft.h 22268 2011-04-30 13:10:40Z rouault $
       3                 :  *
       4                 :  * Project:  GFT Translator
       5                 :  * Purpose:  Definition of classes for OGR Google Fusion Tables driver.
       6                 :  * Author:   Even Rouault, even dot rouault at mines dash paris dot org
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2011, Even Rouault <even dot rouault at mines dash paris dot org>
      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                 : #ifndef _OGR_GFT_H_INCLUDED
      31                 : #define _OGR_GFT_H_INCLUDED
      32                 : 
      33                 : #include "ogrsf_frmts.h"
      34                 : #include "cpl_http.h"
      35                 : 
      36                 : #include <vector>
      37                 : 
      38                 : /************************************************************************/
      39                 : /*                             OGRGFTLayer                              */
      40                 : /************************************************************************/
      41                 : class OGRGFTDataSource;
      42                 : 
      43                 : class OGRGFTLayer : public OGRLayer
      44                 : {
      45                 : protected:
      46                 :     OGRGFTDataSource* poDS;
      47                 : 
      48                 :     OGRFeatureDefn*    poFeatureDefn;
      49                 :     OGRSpatialReference *poSRS;
      50                 : 
      51                 :     int                nNextInSeq;
      52                 : 
      53                 :     int                iGeometryField;
      54                 :     int                iLatitudeField;
      55                 :     int                iLongitudeField;
      56                 :     int                bHiddenGeometryField;
      57                 : 
      58                 :     OGRFeature *       GetNextRawFeature();
      59                 : 
      60                 :     int                nOffset;
      61                 :     int                bEOF;
      62                 :     virtual int                FetchNextRows() = 0;
      63                 : 
      64                 :     std::vector<CPLString> aosRows;
      65                 : 
      66                 :     int                 bFirstTokenIsFID;
      67                 :     OGRFeature*         BuildFeatureFromSQL(const char* pszLine);
      68                 : 
      69                 :     static CPLString    LaunderColName(const char* pszColName);
      70                 : 
      71                 :   public:
      72                 :                          OGRGFTLayer(OGRGFTDataSource* poDS);
      73                 :                         ~OGRGFTLayer();
      74                 : 
      75                 :     virtual void                ResetReading();
      76                 :     virtual OGRFeature *        GetNextFeature();
      77                 : 
      78                 :     virtual OGRFeatureDefn *    GetLayerDefn();
      79                 : 
      80                 :     virtual int                 TestCapability( const char * );
      81                 : 
      82                 :     virtual OGRSpatialReference*GetSpatialRef();
      83                 : 
      84                 :     virtual const char *        GetGeometryColumn();
      85                 : 
      86                 :     virtual OGRErr              SetNextByIndex( long nIndex );
      87                 : 
      88              12 :     const char *        GetDefaultGeometryColumnName() { return "geometry"; }
      89                 : 
      90                 :     static int                  ParseCSVResponse(char* pszLine,
      91                 :                                                  std::vector<CPLString>& aosRes);
      92                 :     static CPLString            PatchSQL(const char* pszSQL);
      93                 : 
      94               0 :     int                         GetGeometryFieldIndex() { return iGeometryField; }
      95               0 :     int                         GetLatitudeFieldIndex() { return iLatitudeField; }
      96               0 :     int                         GetLongitudeFieldIndex() { return iLongitudeField; }
      97                 : 
      98               8 :     int                         GetFeaturesToFetch() { return atoi(CPLGetConfigOption("GFT_PAGE_SIZE", "500")); }
      99                 : };
     100                 : 
     101                 : /************************************************************************/
     102                 : /*                         OGRGFTTableLayer                             */
     103                 : /************************************************************************/
     104                 : 
     105                 : class OGRGFTTableLayer : public OGRGFTLayer
     106                 : {
     107                 :     CPLString         osTableName;
     108                 :     CPLString         osTableId;
     109                 :     CPLString         osGeomColumnName;
     110                 : 
     111                 :     int                bHasTriedCreateTable;
     112                 :     void               CreateTableIfNecessary();
     113                 : 
     114                 :     CPLString           osWHERE;
     115                 :     CPLString           osQuery;
     116                 : 
     117                 :     void                BuildWhere(void);
     118                 : 
     119                 :     CPLString          osTransaction;
     120                 :     int                bInTransaction;
     121                 :     int                nFeaturesInTransaction;
     122                 : 
     123                 :     int                FetchDescribe();
     124                 :     virtual int                FetchNextRows();
     125                 : 
     126                 :     OGRwkbGeometryType eGTypeForCreation;
     127                 : 
     128                 :     std::vector<CPLString>  aosColumnInternalName;
     129                 : 
     130                 :     public:
     131                 :             OGRGFTTableLayer(OGRGFTDataSource* poDS,
     132                 :                              const char* pszTableName,
     133                 :                              const char* pszTableId = "",
     134                 :                              const char* pszGeomColumnName = "");
     135                 :             ~OGRGFTTableLayer();
     136                 : 
     137                 :     virtual void                ResetReading();
     138                 : 
     139                 :     virtual OGRFeatureDefn *    GetLayerDefn();
     140                 : 
     141             709 :     virtual const char *        GetName() { return osTableName.c_str(); }
     142                 :     virtual int         GetFeatureCount( int bForce = TRUE );
     143                 : 
     144                 :     virtual OGRFeature *        GetFeature( long nFID );
     145                 : 
     146                 :     virtual void        SetSpatialFilter( OGRGeometry * );
     147                 :     virtual OGRErr      SetAttributeFilter( const char * );
     148                 : 
     149                 :     virtual OGRErr      CreateField( OGRFieldDefn *poField,
     150                 :                                      int bApproxOK = TRUE );
     151                 :     virtual OGRErr      CreateFeature( OGRFeature *poFeature );
     152                 :     virtual OGRErr      SetFeature( OGRFeature *poFeature );
     153                 :     virtual OGRErr      DeleteFeature( long nFID );
     154                 : 
     155                 :     virtual OGRErr      StartTransaction();
     156                 :     virtual OGRErr      CommitTransaction();
     157                 :     virtual OGRErr      RollbackTransaction();
     158                 : 
     159               4 :     const CPLString&            GetTableId() const { return osTableId; }
     160                 : 
     161                 :     virtual int                 TestCapability( const char * );
     162                 : 
     163                 :     void                SetGeometryType(OGRwkbGeometryType eGType);
     164                 : };
     165                 : 
     166                 : /************************************************************************/
     167                 : /*                        OGRGFTResultLayer                             */
     168                 : /************************************************************************/
     169                 : 
     170                 : class OGRGFTResultLayer : public OGRGFTLayer
     171                 : {
     172                 :     CPLString   osSQL;
     173                 :     int         bGotAllRows;
     174                 : 
     175                 :     virtual int                FetchNextRows();
     176                 : 
     177                 :     public:
     178                 :             OGRGFTResultLayer(OGRGFTDataSource* poDS,
     179                 :                               const char* pszSQL);
     180                 :             ~OGRGFTResultLayer();
     181                 : 
     182                 :     virtual void                ResetReading();
     183                 : 
     184                 :     int     RunSQL();
     185                 : };
     186                 : 
     187                 : /************************************************************************/
     188                 : /*                           OGRGFTDataSource                           */
     189                 : /************************************************************************/
     190                 : 
     191                 : class OGRGFTDataSource : public OGRDataSource
     192                 : {
     193                 :     char*               pszName;
     194                 : 
     195                 :     OGRLayer**          papoLayers;
     196                 :     int                 nLayers;
     197                 : 
     198                 :     int                 bReadWrite;
     199                 : 
     200                 :     int                 bUseHTTPS;
     201                 :     CPLString           osAuth;
     202                 :     int                 FetchAuth(const char* pszEmail, const char* pszPassword);
     203                 : 
     204                 :     void                DeleteLayer( const char *pszLayerName );
     205                 : 
     206                 :     int                 bMustCleanPersistant;
     207                 : 
     208                 :   public:
     209                 :                         OGRGFTDataSource();
     210                 :                         ~OGRGFTDataSource();
     211                 : 
     212                 :     int                 Open( const char * pszFilename,
     213                 :                               int bUpdate );
     214                 : 
     215               4 :     virtual const char* GetName() { return pszName; }
     216                 : 
     217              85 :     virtual int         GetLayerCount() { return nLayers; }
     218                 :     virtual OGRLayer*   GetLayer( int );
     219                 :     virtual OGRLayer    *GetLayerByName(const char *);
     220                 : 
     221                 :     virtual int         TestCapability( const char * );
     222                 : 
     223                 :     virtual OGRLayer   *CreateLayer( const char *pszName,
     224                 :                                      OGRSpatialReference *poSpatialRef = NULL,
     225                 :                                      OGRwkbGeometryType eGType = wkbUnknown,
     226                 :                                      char ** papszOptions = NULL );
     227                 :     virtual OGRErr      DeleteLayer(int);
     228                 : 
     229                 :     virtual OGRLayer*  ExecuteSQL( const char *pszSQLCommand,
     230                 :                                    OGRGeometry *poSpatialFilter,
     231                 :                                    const char *pszDialect );
     232                 :     virtual void       ReleaseResultSet( OGRLayer * poLayer );
     233                 : 
     234              32 :     const CPLString&            GetAuth() const { return osAuth; }
     235                 :     const char*                 GetAPIURL() const;
     236              24 :     int                         IsReadWrite() const { return bReadWrite; }
     237                 :     char**                      AddHTTPOptions(char** papszOptions = NULL);
     238                 :     CPLHTTPResult*              RunSQL(const char* pszUnescapedSQL);
     239                 : };
     240                 : 
     241                 : /************************************************************************/
     242                 : /*                             OGRGFTDriver                             */
     243                 : /************************************************************************/
     244                 : 
     245                 : class OGRGFTDriver : public OGRSFDriver
     246             178 : {
     247                 :   public:
     248                 :                 ~OGRGFTDriver();
     249                 : 
     250                 :     virtual const char*         GetName();
     251                 :     virtual OGRDataSource*      Open( const char *, int );
     252                 :     virtual OGRDataSource*      CreateDataSource( const char * pszName,
     253                 :                                                   char **papszOptions );
     254                 :     virtual int                 TestCapability( const char * );
     255                 : };
     256                 : 
     257                 : char **OGRGFTCSVSplitLine( const char *pszString, char chDelimiter );
     258                 : char* OGRGFTGotoNextLine(char* pszData);
     259                 : 
     260                 : #endif /* ndef _OGR_GFT_H_INCLUDED */

Generated by: LCOV version 1.7