~ubuntu-branches/ubuntu/trusty/qgis/trusty

« back to all changes in this revision

Viewing changes to src/core/spatialindex/include/SpatialIndex.h

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Spatial Index Library
 
2
//
 
3
// Copyright (C) 2003 Navel Ltd.
 
4
//
 
5
// This library is free software; you can redistribute it and/or
 
6
// modify it under the terms of the GNU Lesser General Public
 
7
// License as published by the Free Software Foundation; either
 
8
// version 2.1 of the License, or (at your option) any later version.
 
9
//
 
10
// This library is distributed in the hope that it will be useful,
 
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
// Lesser General Public License for more details.
 
14
//
 
15
// You should have received a copy of the GNU Lesser General Public
 
16
// License along with this library; if not, write to the Free Software
 
17
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
//
 
19
//  Email:
 
20
//    mhadji@gmail.com
 
21
 
 
22
#ifndef __spatialindex_h
 
23
#define __spatialindex_h
 
24
 
 
25
#include <assert.h>
 
26
#include <iostream>
 
27
#include <vector>
 
28
#include <map>
 
29
#include <limits>
 
30
#include <stack>
 
31
#include <queue>
 
32
#include <set>
 
33
#include <cmath>
 
34
#include <cstring>
 
35
#include <sstream>
 
36
 
 
37
#include "Tools.h"
 
38
 
 
39
using namespace Tools::Geometry;
 
40
 
 
41
# if !HAVE_BZERO
 
42
#  define bzero(d, n) memset((d), 0, (n))
 
43
# endif
 
44
 
 
45
namespace SpatialIndex
 
46
{
 
47
  //const std::string VERSION;
 
48
  //const std::string DATE;
 
49
 
 
50
  enum CommandType
 
51
  {
 
52
    CT_NODEREAD = 0x0,
 
53
    CT_NODEDELETE,
 
54
    CT_NODEWRITE
 
55
  };
 
56
 
 
57
  //
 
58
  // Interfaces
 
59
  //
 
60
interface IEntry : public Tools::IObject
 
61
  {
 
62
  public:
 
63
    virtual long getIdentifier() const = 0;
 
64
    virtual void getShape( IShape** out ) const = 0;
 
65
    virtual ~IEntry() {}
 
66
  }; // IEntry
 
67
 
 
68
interface INode : public IEntry, public Tools::ISerializable
 
69
  {
 
70
  public:
 
71
    virtual unsigned long getChildrenCount() const = 0;
 
72
    virtual long getChildIdentifier( unsigned long index ) const = 0;
 
73
    virtual void getChildShape( unsigned long index, IShape** out ) const = 0;
 
74
    virtual unsigned long getLevel() const = 0;
 
75
    virtual bool isIndex() const = 0;
 
76
    virtual bool isLeaf() const = 0;
 
77
    virtual ~INode() {}
 
78
  }; // INode
 
79
 
 
80
interface IData : public IEntry
 
81
  {
 
82
  public:
 
83
    virtual void getData( unsigned long& len, byte** data ) const = 0;
 
84
    virtual ~IData() {}
 
85
  }; // IData
 
86
 
 
87
interface IDataStream : public Tools::IObjectStream
 
88
  {
 
89
  public:
 
90
    virtual IData* getNext() = 0;
 
91
    virtual ~IDataStream() {}
 
92
  }; // IDataStream
 
93
 
 
94
  interface ICommand
 
95
  {
 
96
  public:
 
97
    virtual void execute( const INode& in ) = 0;
 
98
    virtual ~ICommand() {}
 
99
  }; // ICommand
 
100
 
 
101
  interface INearestNeighborComparator
 
102
  {
 
103
  public:
 
104
    virtual double getMinimumDistance( const IShape& query, const IShape& entry ) = 0;
 
105
    virtual double getMinimumDistance( const IShape& query, const IData& data ) = 0;
 
106
    virtual ~INearestNeighborComparator() {}
 
107
  }; // INearestNeighborComparator
 
108
 
 
109
  interface IStorageManager
 
110
  {
 
111
  public:
 
112
    virtual void loadByteArray( const long id, unsigned long& len, byte** data ) = 0;
 
113
    virtual void storeByteArray( long& id, const unsigned long len, const byte* const data ) = 0;
 
114
    virtual void deleteByteArray( const long id ) = 0;
 
115
    virtual ~IStorageManager() {}
 
116
  }; // IStorageManager
 
117
 
 
118
  interface IVisitor
 
119
  {
 
120
  public:
 
121
    virtual void visitNode( const INode& in ) = 0;
 
122
    virtual void visitData( const IData& in ) = 0;
 
123
    virtual void visitData( std::vector<const IData*>& v ) = 0;
 
124
    virtual ~IVisitor() {}
 
125
  }; // IVisitor
 
126
 
 
127
  interface IQueryStrategy
 
128
  {
 
129
  public:
 
130
    virtual void getNextEntry( const IEntry& previouslyFetched, long& nextEntryToFetch, bool& bFetchNextEntry ) = 0;
 
131
    virtual ~IQueryStrategy() {}
 
132
  }; // IQueryStrategy
 
133
 
 
134
  interface IStatistics
 
135
  {
 
136
  public:
 
137
    virtual unsigned long getReads() const = 0;
 
138
    virtual unsigned long getWrites() const = 0;
 
139
    virtual unsigned long getNumberOfNodes() const = 0;
 
140
    virtual unsigned long getNumberOfData() const = 0;
 
141
    virtual ~IStatistics() {}
 
142
  }; // IStatistics
 
143
 
 
144
  interface ISpatialIndex
 
145
  {
 
146
  public:
 
147
    virtual void insertData( unsigned long len, const byte* pData, const IShape& shape, long shapeIdentifier ) = 0;
 
148
    virtual bool deleteData( const IShape& shape, long shapeIdentifier ) = 0;
 
149
    virtual void containsWhatQuery( const IShape& query, IVisitor& v )  = 0;
 
150
    virtual void intersectsWithQuery( const IShape& query, IVisitor& v ) = 0;
 
151
    virtual void pointLocationQuery( const Tools::Geometry::Point& query, IVisitor& v ) = 0;
 
152
    virtual void nearestNeighborQuery( long k, const IShape& query, IVisitor& v, INearestNeighborComparator& nnc ) = 0;
 
153
    virtual void nearestNeighborQuery( long k, const IShape& query, IVisitor& v ) = 0;
 
154
    virtual void selfJoinQuery( const IShape& s, IVisitor& v ) = 0;
 
155
    virtual void queryStrategy( IQueryStrategy& qs ) = 0;
 
156
    virtual void getIndexProperties( Tools::PropertySet& out ) const = 0;
 
157
    virtual void addCommand( ICommand* in, CommandType ct ) = 0;
 
158
    virtual bool isIndexValid() = 0;
 
159
    virtual void getStatistics( IStatistics** out ) const = 0;
 
160
    virtual ~ISpatialIndex() {}
 
161
  }; // ISpatialIndex
 
162
 
 
163
  namespace StorageManager
 
164
  {
 
165
    enum StorageManagerConstants
 
166
    {
 
167
      EmptyPage = -0x1,
 
168
      NewPage = -0x1
 
169
    };
 
170
 
 
171
  interface IBuffer : public IStorageManager
 
172
    {
 
173
    public:
 
174
      virtual unsigned long getHits() = 0;
 
175
      virtual void clear() = 0;
 
176
      virtual ~IBuffer() {}
 
177
    }; // IBuffer
 
178
 
 
179
    extern IStorageManager* returnMemoryStorageManager( Tools::PropertySet& in );
 
180
    extern IStorageManager* createNewMemoryStorageManager();
 
181
 
 
182
    extern IStorageManager* returnDiskStorageManager( Tools::PropertySet& in );
 
183
    extern IStorageManager* createNewDiskStorageManager( std::string& baseName, unsigned long pageSize );
 
184
    extern IStorageManager* loadDiskStorageManager( std::string& baseName );
 
185
 
 
186
#ifdef _MSC_VER
 
187
    // MSVC didn't like the difference in parameter names between declaration
 
188
    // definition
 
189
    extern IBuffer* returnRandomEvictionsBuffer( IStorageManager& sm, Tools::PropertySet& ps );
 
190
#else
 
191
    extern IBuffer* returnRandomEvictionsBuffer( IStorageManager& in0, Tools::PropertySet& in1 );
 
192
#endif//_MSC_VER
 
193
    extern IBuffer* createNewRandomEvictionsBuffer( IStorageManager& in, unsigned int capacity, bool bWriteThrough );
 
194
  }
 
195
 
 
196
  //
 
197
  // Global functions
 
198
  //
 
199
  extern std::ostream& operator<<( std::ostream&, const ISpatialIndex& );
 
200
  extern std::ostream& operator<<( std::ostream&, const IStatistics& );
 
201
}
 
202
 
 
203
//#include "TimePoint.h"
 
204
//#include "TimeRegion.h"
 
205
//#include "MovingPoint.h"
 
206
//#include "MovingRegion.h"
 
207
#include "RTree.h"
 
208
//#include "MVRTree.h"
 
209
//#include "TPRTree.h"
 
210
 
 
211
#endif /*__spatialindex_h*/