Line data Source code
1 : /****************************************************************************** 2 : * $Id$ 3 : * 4 : * Project: OpenGIS Simple Features Reference Implementation 5 : * Purpose: Defines OGRLayerPool and OGRProxiedLayer class 6 : * Author: Even Rouault, even dot rouault at spatialys.com 7 : * 8 : ****************************************************************************** 9 : * Copyright (c) 2012-2013, Even Rouault <even dot rouault at spatialys.com> 10 : * 11 : * SPDX-License-Identifier: MIT 12 : ****************************************************************************/ 13 : 14 : #ifndef OGRLAYERPOOL_H_INCLUDED 15 : #define OGRLAYERPOOL_H_INCLUDED 16 : 17 : #ifndef DOXYGEN_SKIP 18 : 19 : #include "ogrsf_frmts.h" 20 : 21 : typedef OGRLayer *(*OpenLayerFunc)(void *user_data); 22 : typedef void (*FreeUserDataFunc)(void *user_data); 23 : 24 : class OGRLayerPool; 25 : 26 : /************************************************************************/ 27 : /* OGRAbstractProxiedLayer */ 28 : /************************************************************************/ 29 : 30 : class CPL_DLL OGRAbstractProxiedLayer : public OGRLayer 31 : { 32 : CPL_DISALLOW_COPY_ASSIGN(OGRAbstractProxiedLayer) 33 : 34 : friend class OGRLayerPool; 35 : 36 : OGRAbstractProxiedLayer 37 : *poPrevLayer; /* Chain to a layer that was used more recently */ 38 : OGRAbstractProxiedLayer 39 : *poNextLayer; /* Chain to a layer that was used less recently */ 40 : 41 : protected: 42 : OGRLayerPool *poPool; 43 : 44 : virtual void CloseUnderlyingLayer() = 0; 45 : 46 : public: 47 : explicit OGRAbstractProxiedLayer(OGRLayerPool *poPool); 48 : virtual ~OGRAbstractProxiedLayer(); 49 : }; 50 : 51 : /************************************************************************/ 52 : /* OGRLayerPool */ 53 : /************************************************************************/ 54 : 55 : class CPL_DLL OGRLayerPool 56 : { 57 : CPL_DISALLOW_COPY_ASSIGN(OGRLayerPool) 58 : 59 : protected: 60 : OGRAbstractProxiedLayer *poMRULayer; /* the most recently used layer */ 61 : OGRAbstractProxiedLayer 62 : *poLRULayer; /* the least recently used layer (still opened) */ 63 : int nMRUListSize; /* the size of the list */ 64 : int nMaxSimultaneouslyOpened; 65 : 66 : public: 67 : explicit OGRLayerPool(int nMaxSimultaneouslyOpened = 100); 68 : ~OGRLayerPool(); 69 : 70 : void SetLastUsedLayer(OGRAbstractProxiedLayer *poProxiedLayer); 71 : void UnchainLayer(OGRAbstractProxiedLayer *poProxiedLayer); 72 : 73 220044 : int GetMaxSimultaneouslyOpened() const 74 : { 75 220044 : return nMaxSimultaneouslyOpened; 76 : } 77 : 78 5 : int GetSize() const 79 : { 80 5 : return nMRUListSize; 81 : } 82 : }; 83 : 84 : /************************************************************************/ 85 : /* OGRProxiedLayer */ 86 : /************************************************************************/ 87 : 88 : class CPL_DLL OGRProxiedLayer : public OGRAbstractProxiedLayer 89 : { 90 : CPL_DISALLOW_COPY_ASSIGN(OGRProxiedLayer) 91 : 92 : OpenLayerFunc pfnOpenLayer; 93 : FreeUserDataFunc pfnFreeUserData; 94 : void *pUserData; 95 : OGRLayer *poUnderlyingLayer; 96 : OGRFeatureDefn *poFeatureDefn; 97 : OGRSpatialReference *poSRS; 98 : 99 : int OpenUnderlyingLayer(); 100 : 101 : protected: 102 : virtual void CloseUnderlyingLayer() override; 103 : 104 : public: 105 : OGRProxiedLayer(OGRLayerPool *poPool, OpenLayerFunc pfnOpenLayer, 106 : FreeUserDataFunc pfnFreeUserData, void *pUserData); 107 : virtual ~OGRProxiedLayer(); 108 : 109 : OGRLayer *GetUnderlyingLayer(); 110 : 111 : virtual OGRGeometry *GetSpatialFilter() override; 112 : virtual void SetSpatialFilter(OGRGeometry *) override; 113 : virtual void SetSpatialFilter(int iGeomField, OGRGeometry *) override; 114 : 115 : virtual OGRErr SetAttributeFilter(const char *) override; 116 : 117 : virtual void ResetReading() override; 118 : virtual OGRFeature *GetNextFeature() override; 119 : virtual OGRErr SetNextByIndex(GIntBig nIndex) override; 120 : virtual OGRFeature *GetFeature(GIntBig nFID) override; 121 : virtual OGRErr ISetFeature(OGRFeature *poFeature) override; 122 : virtual OGRErr ICreateFeature(OGRFeature *poFeature) override; 123 : virtual OGRErr IUpsertFeature(OGRFeature *poFeature) override; 124 : OGRErr IUpdateFeature(OGRFeature *poFeature, int nUpdatedFieldsCount, 125 : const int *panUpdatedFieldsIdx, 126 : int nUpdatedGeomFieldsCount, 127 : const int *panUpdatedGeomFieldsIdx, 128 : bool bUpdateStyleString) override; 129 : virtual OGRErr DeleteFeature(GIntBig nFID) override; 130 : 131 : virtual GDALDataset *GetDataset() override; 132 : virtual bool GetArrowStream(struct ArrowArrayStream *out_stream, 133 : CSLConstList papszOptions = nullptr) override; 134 : 135 : virtual const char *GetName() override; 136 : virtual OGRwkbGeometryType GetGeomType() override; 137 : virtual OGRFeatureDefn *GetLayerDefn() override; 138 : 139 : virtual OGRSpatialReference *GetSpatialRef() override; 140 : 141 : virtual GIntBig GetFeatureCount(int bForce = TRUE) override; 142 : virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent, 143 : int bForce = TRUE) override; 144 : virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce = TRUE) override; 145 : 146 : virtual int TestCapability(const char *) override; 147 : 148 : virtual OGRErr CreateField(const OGRFieldDefn *poField, 149 : int bApproxOK = TRUE) override; 150 : virtual OGRErr DeleteField(int iField) override; 151 : virtual OGRErr ReorderFields(int *panMap) override; 152 : virtual OGRErr AlterFieldDefn(int iField, OGRFieldDefn *poNewFieldDefn, 153 : int nFlags) override; 154 : virtual OGRErr 155 : AlterGeomFieldDefn(int iGeomField, 156 : const OGRGeomFieldDefn *poNewGeomFieldDefn, 157 : int nFlags) override; 158 : 159 : virtual OGRErr SyncToDisk() override; 160 : 161 : virtual OGRStyleTable *GetStyleTable() override; 162 : virtual void SetStyleTableDirectly(OGRStyleTable *poStyleTable) override; 163 : 164 : virtual void SetStyleTable(OGRStyleTable *poStyleTable) override; 165 : 166 : virtual OGRErr StartTransaction() override; 167 : virtual OGRErr CommitTransaction() override; 168 : virtual OGRErr RollbackTransaction() override; 169 : 170 : virtual const char *GetFIDColumn() override; 171 : virtual const char *GetGeometryColumn() override; 172 : 173 : virtual OGRErr SetIgnoredFields(CSLConstList papszFields) override; 174 : 175 : virtual OGRErr Rename(const char *pszNewName) override; 176 : }; 177 : 178 : #endif /* #ifndef DOXYGEN_SKIP */ 179 : 180 : #endif // OGRLAYERPOOL_H_INCLUDED