1 /****************************************************************************** 2 * Project: Selafin importer 3 * Purpose: Definition of classes for OGR driver for Selafin files. 4 * Author: François Hissel, francois.hissel@gmail.com 5 * 6 ****************************************************************************** 7 * Copyright (c) 2014, François Hissel <francois.hissel@gmail.com> 8 * 9 * Permission is hereby granted, free of charge, to any person obtaining a 10 * copy of this software and associated documentation files (the "Software"), 11 * to deal in the Software without restriction, including without limitation 12 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 * and/or sell copies of the Software, and to permit persons to whom the 14 * Software is furnished to do so, subject to the following conditions: 15 * 16 * The above copyright notice and this permission notice shall be included 17 * in all copies or substantial portions of the Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 * DEALINGS IN THE SOFTWARE. 26 ****************************************************************************/ 27 28 #ifndef _OGR_SELAFIN_H_INCLUDED 29 #define _OGR_SELAFIN_H_INCLUDED 30 31 #include "io_selafin.h" 32 #include "ogrsf_frmts.h" 33 34 class OGRSelafinDataSource; 35 36 typedef enum {POINTS,ELEMENTS,ALL} SelafinTypeDef; 37 38 /************************************************************************/ 39 /* Range */ 40 /************************************************************************/ 41 class Range { 42 private: 43 typedef struct List { 44 SelafinTypeDef eType; 45 long nMin,nMax; 46 List *poNext; ListList47 List():poNext(0) {} ListList48 List(SelafinTypeDef eTypeP,long nMinP,long nMaxP,List *poNextP):eType(eTypeP),nMin(nMinP),nMax(nMaxP),poNext(poNextP) {} 49 } List; 50 List *poVals,*poActual; 51 long nMaxValue; 52 static void sortList(List *&poList,List *poEnd=0); 53 static void deleteList(List *poList); 54 public: Range()55 Range():poVals(0),poActual(0),nMaxValue(0) {} 56 void setRange(const char *pszStr); 57 ~Range(); 58 void setMaxValue(long nMaxValueP); 59 bool contains(SelafinTypeDef eType,long nValue) const; 60 size_t getSize() const; 61 }; 62 63 64 /************************************************************************/ 65 /* OGRSelafinLayer */ 66 /************************************************************************/ 67 68 class OGRSelafinLayer : public OGRLayer { 69 private: 70 SelafinTypeDef eType; 71 int bUpdate; 72 long nStepNumber; 73 Selafin::Header *poHeader; 74 OGRFeatureDefn *poFeatureDefn; 75 OGRSpatialReference *poSpatialRef; 76 GIntBig nCurrentId; 77 public: 78 OGRSelafinLayer( const char *pszLayerNameP, int bUpdateP,OGRSpatialReference *poSpatialRefP,Selafin::Header *poHeaderP,int nStepNumberP,SelafinTypeDef eTypeP); 79 ~OGRSelafinLayer(); GetSpatialRef()80 OGRSpatialReference *GetSpatialRef() {return poSpatialRef;} GetStepNumber()81 long GetStepNumber() {return nStepNumber;} 82 OGRFeature *GetNextFeature(); 83 OGRFeature *GetFeature(GIntBig nFID); 84 void ResetReading(); 85 OGRErr SetNextByIndex(GIntBig nIndex); GetLayerDefn()86 OGRFeatureDefn *GetLayerDefn() {return poFeatureDefn;} 87 int TestCapability(const char *pszCap); 88 GIntBig GetFeatureCount(int bForce=TRUE); 89 OGRErr GetExtent(OGREnvelope *psExtent,int bForce=TRUE); 90 OGRErr ISetFeature(OGRFeature *poFeature); 91 OGRErr ICreateFeature(OGRFeature *poFeature); 92 OGRErr CreateField(OGRFieldDefn *poField,int bApproxOK=TRUE); 93 OGRErr DeleteField(int iField); 94 OGRErr ReorderFields(int *panMap); 95 OGRErr AlterFieldDefn(int iField,OGRFieldDefn *poNewFieldDefn,int nFlags); 96 OGRErr DeleteFeature(GIntBig nFID); 97 }; 98 99 /************************************************************************/ 100 /* OGRSelafinDataSource */ 101 /************************************************************************/ 102 103 class OGRSelafinDataSource : public OGRDataSource { 104 private: 105 char *pszName; 106 char *pszLockName; 107 OGRSelafinLayer **papoLayers; 108 Range poRange; 109 int nLayers; 110 int bUpdate; 111 Selafin::Header *poHeader; 112 CPLString osDefaultSelafinName; 113 OGRSpatialReference *poSpatialRef; 114 int TakeLock(const char *pszFilename); 115 void ReleaseLock(); 116 public: 117 OGRSelafinDataSource(); 118 ~OGRSelafinDataSource(); 119 int Open(const char * pszFilename, int bUpdate, int bCreate); 120 int OpenTable(const char * pszFilename); GetName()121 const char *GetName() { return pszName; } GetLayerCount()122 int GetLayerCount() { return nLayers; } 123 OGRLayer *GetLayer( int ); 124 virtual OGRLayer *ICreateLayer( const char *pszName, OGRSpatialReference *poSpatialRefP = NULL, OGRwkbGeometryType eGType = wkbUnknown, char ** papszOptions = NULL ); 125 virtual OGRErr DeleteLayer(int); 126 int TestCapability( const char * ); SetDefaultSelafinName(const char * pszName)127 void SetDefaultSelafinName( const char *pszName ) { osDefaultSelafinName = pszName; } 128 }; 129 130 #endif /* ndef _OGR_SELAFIN_H_INCLUDED */ 131