ogrlayerpool.h

00001 /******************************************************************************
00002  * $Id: ogrlayerpool.h 27044 2014-03-16 23:41:27Z rouault $
00003  *
00004  * Project:  OpenGIS Simple Features Reference Implementation
00005  * Purpose:  Defines OGRLayerPool and OGRProxiedLayer class
00006  * Author:   Even Rouault, even dot rouault at mines dash paris dot org
00007  *
00008  ******************************************************************************
00009  * Copyright (c) 2012-2013, Even Rouault <even dot rouault at mines-paris dot org>
00010  *
00011  * Permission is hereby granted, free of charge, to any person obtaining a
00012  * copy of this software and associated documentation files (the "Software"),
00013  * to deal in the Software without restriction, including without limitation
00014  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00015  * and/or sell copies of the Software, and to permit persons to whom the
00016  * Software is furnished to do so, subject to the following conditions:
00017  *
00018  * The above copyright notice and this permission notice shall be included
00019  * in all copies or substantial portions of the Software.
00020  *
00021  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00022  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00023  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00024  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00025  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00026  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00027  * DEALINGS IN THE SOFTWARE.
00028  ****************************************************************************/
00029 
00030 #ifndef _OGRLAYERPOOL_H_INCLUDED
00031 #define _OGRLAYERPOOL_H_INCLUDED
00032 
00033 #include "ogrsf_frmts.h"
00034 
00035 typedef OGRLayer* (*OpenLayerFunc)(void* user_data);
00036 typedef void      (*FreeUserDataFunc)(void* user_data);
00037 
00038 class OGRLayerPool;
00039 
00040 /************************************************************************/
00041 /*                      OGRAbstractProxiedLayer                         */
00042 /************************************************************************/
00043 
00044 class OGRAbstractProxiedLayer : public OGRLayer
00045 {
00046         friend class OGRLayerPool;
00047 
00048         OGRAbstractProxiedLayer   *poPrevLayer; /* Chain to a layer that was used more recently */
00049         OGRAbstractProxiedLayer   *poNextLayer; /* Chain to a layer that was used less recently */
00050 
00051     protected:
00052         OGRLayerPool              *poPool;
00053 
00054         virtual void    CloseUnderlyingLayer() = 0;
00055 
00056     public:
00057                         OGRAbstractProxiedLayer(OGRLayerPool* poPool);
00058         virtual        ~OGRAbstractProxiedLayer();
00059 };
00060 
00061 /************************************************************************/
00062 /*                             OGRLayerPool                             */
00063 /************************************************************************/
00064 
00065 class OGRLayerPool
00066 {
00067     protected:
00068         OGRAbstractProxiedLayer *poMRULayer; /* the most recently used layer */
00069         OGRAbstractProxiedLayer *poLRULayer; /* the least recently used layer (still opened) */
00070         int                     nMRUListSize; /* the size of the list */
00071         int                     nMaxSimultaneouslyOpened;
00072 
00073     public:
00074                                 OGRLayerPool(int nMaxSimultaneouslyOpened = 100);
00075                                ~OGRLayerPool();
00076 
00077         void                    SetLastUsedLayer(OGRAbstractProxiedLayer* poProxiedLayer);
00078         void                    UnchainLayer(OGRAbstractProxiedLayer* poProxiedLayer);
00079 
00080         int                     GetMaxSimultaneouslyOpened() const { return nMaxSimultaneouslyOpened; }
00081         int                     GetSize() const { return nMRUListSize; }
00082 };
00083 
00084 /************************************************************************/
00085 /*                           OGRProxiedLayer                            */
00086 /************************************************************************/
00087 
00088 class OGRProxiedLayer : public OGRAbstractProxiedLayer
00089 {
00090     OpenLayerFunc       pfnOpenLayer;
00091     FreeUserDataFunc    pfnFreeUserData;
00092     void               *pUserData;
00093     OGRLayer           *poUnderlyingLayer;
00094     OGRFeatureDefn     *poFeatureDefn;
00095     OGRSpatialReference *poSRS;
00096 
00097     int                 OpenUnderlyingLayer();
00098 
00099   protected:
00100 
00101     virtual void        CloseUnderlyingLayer();
00102 
00103   public:
00104 
00105                         OGRProxiedLayer(OGRLayerPool* poPool,
00106                                         OpenLayerFunc pfnOpenLayer,
00107                                         FreeUserDataFunc pfnFreeUserData,
00108                                         void* pUserData);
00109     virtual            ~OGRProxiedLayer();
00110 
00111     virtual OGRGeometry *GetSpatialFilter();
00112     virtual void        SetSpatialFilter( OGRGeometry * );
00113     virtual void        SetSpatialFilter( int iGeomField, OGRGeometry * );
00114 
00115     virtual OGRErr      SetAttributeFilter( const char * );
00116 
00117     virtual void        ResetReading();
00118     virtual OGRFeature *GetNextFeature();
00119     virtual OGRErr      SetNextByIndex( long nIndex );
00120     virtual OGRFeature *GetFeature( long nFID );
00121     virtual OGRErr      SetFeature( OGRFeature *poFeature );
00122     virtual OGRErr      CreateFeature( OGRFeature *poFeature );
00123     virtual OGRErr      DeleteFeature( long nFID );
00124 
00125     virtual const char *GetName();
00126     virtual OGRwkbGeometryType GetGeomType();
00127     virtual OGRFeatureDefn *GetLayerDefn();
00128 
00129     virtual OGRSpatialReference *GetSpatialRef();
00130 
00131     virtual int         GetFeatureCount( int bForce = TRUE );
00132     virtual OGRErr      GetExtent(int iGeomField, OGREnvelope *psExtent, int bForce = TRUE);
00133     virtual OGRErr      GetExtent(OGREnvelope *psExtent, int bForce = TRUE);
00134 
00135     virtual int         TestCapability( const char * );
00136 
00137     /* Deprecated (and un-implemented method) --> we won't decorate it ! */
00138     /* virtual const char *GetInfo( const char * ); */
00139 
00140     virtual OGRErr      CreateField( OGRFieldDefn *poField,
00141                                      int bApproxOK = TRUE );
00142     virtual OGRErr      DeleteField( int iField );
00143     virtual OGRErr      ReorderFields( int* panMap );
00144     virtual OGRErr      AlterFieldDefn( int iField, OGRFieldDefn* poNewFieldDefn, int nFlags );
00145 
00146     virtual OGRErr      SyncToDisk();
00147 
00148     virtual OGRStyleTable *GetStyleTable();
00149     virtual void        SetStyleTableDirectly( OGRStyleTable *poStyleTable );
00150 
00151     virtual void        SetStyleTable(OGRStyleTable *poStyleTable);
00152 
00153     virtual OGRErr      StartTransaction();
00154     virtual OGRErr      CommitTransaction();
00155     virtual OGRErr      RollbackTransaction();
00156 
00157     virtual const char *GetFIDColumn();
00158     virtual const char *GetGeometryColumn();
00159 
00160     virtual OGRErr      SetIgnoredFields( const char **papszFields );
00161 };
00162 
00163 #endif // _OGRLAYERPOOL_H_INCLUDED

Generated for GDAL by doxygen 1.7.1.