1 /******************************************************************************
2  * $Id: ogreditablelayer.h 07880b5ca268a13af619c6a1774f9696cd7f6992 2019-03-28 00:41:48 +0100 Even Rouault $
3  *
4  * Project:  OpenGIS Simple Features Reference Implementation
5  * Purpose:  Defines OGREditableLayer class
6  * Author:   Even Rouault <even.rouault at spatialys.com>
7  *
8  ******************************************************************************
9  * Copyright (c) 2015, Even Rouault <even.rouault at spatialys.com>
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 OGREDITABLELAYER_H_INCLUDED
31 #define OGREDITABLELAYER_H_INCLUDED
32 
33 //! @cond Doxygen_Suppress
34 #include "ogrlayerdecorator.h"
35 #include <set>
36 #include <map>
37 
38 class CPL_DLL IOGREditableLayerSynchronizer
39 {
40     public:
41         virtual ~IOGREditableLayerSynchronizer();
42 
43         virtual OGRErr EditableSyncToDisk(OGRLayer* poEditableLayer,
44                                           OGRLayer** ppoDecoratedLayer) = 0;
45 };
46 
47 class CPL_DLL OGREditableLayer : public OGRLayerDecorator
48 {
49     CPL_DISALLOW_COPY_ASSIGN(OGREditableLayer)
50 
51   protected:
52 
53     IOGREditableLayerSynchronizer *m_poSynchronizer;
54     bool                           m_bTakeOwnershipSynchronizer;
55     OGRFeatureDefn                *m_poEditableFeatureDefn;
56     GIntBig                        m_nNextFID;
57     std::set<GIntBig>              m_oSetCreated{};
58     std::set<GIntBig>              m_oSetEdited{};
59     std::set<GIntBig>              m_oSetDeleted{};
60     std::set<GIntBig>::iterator    m_oIter{};
61     std::set<CPLString>            m_oSetDeletedFields{};
62     OGRLayer                      *m_poMemLayer;
63     bool                           m_bStructureModified;
64     bool                           m_bSupportsCreateGeomField;
65     bool                           m_bSupportsCurveGeometries;
66     std::map<CPLString, int>       m_oMapEditableFDefnFieldNameToIdx{};
67 
68     OGRFeature                    *Translate(OGRFeatureDefn* poTargetDefn,
69                                              OGRFeature* poSrcFeature,
70                                              bool bCanStealSrcFeature,
71                                              bool bHideDeletedFields);
72     void                           DetectNextFID();
73     int                            GetSrcGeomFieldIndex(int iGeomField);
74 
75   public:
76 
77                        OGREditableLayer(OGRLayer* poDecoratedLayer,
78                                         bool bTakeOwnershipDecoratedLayer,
79                                         IOGREditableLayerSynchronizer* poSynchronizer,
80                                         bool bTakeOwnershipSynchronizer);
81     virtual           ~OGREditableLayer();
82 
83     void                SetNextFID(GIntBig nNextFID);
84     void                SetSupportsCreateGeomField(bool SupportsCreateGeomField);
85     void                SetSupportsCurveGeometries(bool bSupportsCurveGeometries);
86 
87     virtual OGRGeometry *GetSpatialFilter() override;
88     virtual void        SetSpatialFilter( OGRGeometry * ) override;
89     virtual void        SetSpatialFilterRect( double dfMinX, double dfMinY,
90                                               double dfMaxX, double dfMaxY ) override;
91     virtual void        SetSpatialFilter( int iGeomField, OGRGeometry * ) override;
92     virtual void        SetSpatialFilterRect( int iGeomField, double dfMinX, double dfMinY,
93                                               double dfMaxX, double dfMaxY ) override;
94 
95     virtual OGRErr      SetAttributeFilter( const char * ) override;
96 
97     virtual void        ResetReading() override;
98     virtual OGRFeature *GetNextFeature() override;
99     virtual OGRErr      SetNextByIndex( GIntBig nIndex ) override;
100     virtual OGRFeature *GetFeature( GIntBig nFID ) override;
101     virtual OGRErr      ISetFeature( OGRFeature *poFeature ) override;
102     virtual OGRErr      ICreateFeature( OGRFeature *poFeature ) override;
103     virtual OGRErr      DeleteFeature( GIntBig nFID ) override;
104 
105     virtual OGRwkbGeometryType GetGeomType() override;
106     virtual OGRFeatureDefn *GetLayerDefn() override;
107 
108     virtual OGRSpatialReference *GetSpatialRef() override;
109 
110     virtual GIntBig     GetFeatureCount( int bForce = TRUE ) override;
111     virtual OGRErr      GetExtent(int iGeomField, OGREnvelope *psExtent, int bForce = TRUE) override;
112     virtual OGRErr      GetExtent(OGREnvelope *psExtent, int bForce = TRUE) override;
113 
114     virtual int         TestCapability( const char * ) override;
115 
116     virtual OGRErr      CreateField( OGRFieldDefn *poField,
117                                      int bApproxOK = TRUE ) override;
118     virtual OGRErr      DeleteField( int iField ) override;
119     virtual OGRErr      ReorderFields( int* panMap ) override;
120     virtual OGRErr      AlterFieldDefn( int iField, OGRFieldDefn* poNewFieldDefn, int nFlags ) override;
121 
122     virtual OGRErr      CreateGeomField( OGRGeomFieldDefn *poField,
123                                          int bApproxOK = TRUE ) override;
124 
125     virtual OGRErr      SyncToDisk() override;
126 
127     virtual OGRErr      StartTransaction() override;
128     virtual OGRErr      CommitTransaction() override;
129     virtual OGRErr      RollbackTransaction() override;
130 
131     virtual const char *GetGeometryColumn() override;
132 };
133 //! @endcond
134 
135 #endif // OGREDITABLELAYER_H_INCLUDED
136