GDAL
|
00001 /****************************************************************************** 00002 * $Id: ogrlayerpool.h 28375 2015-01-30 12:06:11Z 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 OGRLayer *GetUnderlyingLayer(); 00112 00113 virtual OGRGeometry *GetSpatialFilter(); 00114 virtual void SetSpatialFilter( OGRGeometry * ); 00115 virtual void SetSpatialFilter( int iGeomField, OGRGeometry * ); 00116 00117 virtual OGRErr SetAttributeFilter( const char * ); 00118 00119 virtual void ResetReading(); 00120 virtual OGRFeature *GetNextFeature(); 00121 virtual OGRErr SetNextByIndex( GIntBig nIndex ); 00122 virtual OGRFeature *GetFeature( GIntBig nFID ); 00123 virtual OGRErr ISetFeature( OGRFeature *poFeature ); 00124 virtual OGRErr ICreateFeature( OGRFeature *poFeature ); 00125 virtual OGRErr DeleteFeature( GIntBig nFID ); 00126 00127 virtual const char *GetName(); 00128 virtual OGRwkbGeometryType GetGeomType(); 00129 virtual OGRFeatureDefn *GetLayerDefn(); 00130 00131 virtual OGRSpatialReference *GetSpatialRef(); 00132 00133 virtual GIntBig GetFeatureCount( int bForce = TRUE ); 00134 virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent, int bForce = TRUE); 00135 virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce = TRUE); 00136 00137 virtual int TestCapability( const char * ); 00138 00139 virtual OGRErr CreateField( OGRFieldDefn *poField, 00140 int bApproxOK = TRUE ); 00141 virtual OGRErr DeleteField( int iField ); 00142 virtual OGRErr ReorderFields( int* panMap ); 00143 virtual OGRErr AlterFieldDefn( int iField, OGRFieldDefn* poNewFieldDefn, int nFlags ); 00144 00145 virtual OGRErr SyncToDisk(); 00146 00147 virtual OGRStyleTable *GetStyleTable(); 00148 virtual void SetStyleTableDirectly( OGRStyleTable *poStyleTable ); 00149 00150 virtual void SetStyleTable(OGRStyleTable *poStyleTable); 00151 00152 virtual OGRErr StartTransaction(); 00153 virtual OGRErr CommitTransaction(); 00154 virtual OGRErr RollbackTransaction(); 00155 00156 virtual const char *GetFIDColumn(); 00157 virtual const char *GetGeometryColumn(); 00158 00159 virtual OGRErr SetIgnoredFields( const char **papszFields ); 00160 }; 00161 00162 #endif // _OGRLAYERPOOL_H_INCLUDED