]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/utilities/geo_db.h
build: use dgit for download target
[ceph.git] / ceph / src / rocksdb / include / rocksdb / utilities / geo_db.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
5 //
6
7 #ifndef ROCKSDB_LITE
8 #pragma once
9 #include <string>
10 #include <vector>
11
12 #include "rocksdb/utilities/stackable_db.h"
13 #include "rocksdb/status.h"
14
15 namespace rocksdb {
16
17 //
18 // Configurable options needed for setting up a Geo database
19 //
20 struct GeoDBOptions {
21 // Backup info and error messages will be written to info_log
22 // if non-nullptr.
23 // Default: nullptr
24 Logger* info_log;
25
26 explicit GeoDBOptions(Logger* _info_log = nullptr):info_log(_info_log) { }
27 };
28
29 //
30 // A position in the earth's geoid
31 //
32 class GeoPosition {
33 public:
34 double latitude;
35 double longitude;
36
37 explicit GeoPosition(double la = 0, double lo = 0) :
38 latitude(la), longitude(lo) {
39 }
40 };
41
42 //
43 // Description of an object on the Geoid. It is located by a GPS location,
44 // and is identified by the id. The value associated with this object is
45 // an opaque string 'value'. Different objects identified by unique id's
46 // can have the same gps-location associated with them.
47 //
48 class GeoObject {
49 public:
50 GeoPosition position;
51 std::string id;
52 std::string value;
53
54 GeoObject() {}
55
56 GeoObject(const GeoPosition& pos, const std::string& i,
57 const std::string& val) :
58 position(pos), id(i), value(val) {
59 }
60 };
61
62 class GeoIterator {
63 public:
64 GeoIterator() = default;
65 virtual ~GeoIterator() {}
66 virtual void Next() = 0;
67 virtual bool Valid() const = 0;
68 virtual const GeoObject& geo_object() = 0;
69 virtual Status status() const = 0;
70 };
71
72 //
73 // Stack your DB with GeoDB to be able to get geo-spatial support
74 //
75 class GeoDB : public StackableDB {
76 public:
77 // GeoDBOptions have to be the same as the ones used in a previous
78 // incarnation of the DB
79 //
80 // GeoDB owns the pointer `DB* db` now. You should not delete it or
81 // use it after the invocation of GeoDB
82 // GeoDB(DB* db, const GeoDBOptions& options) : StackableDB(db) {}
83 GeoDB(DB* db, const GeoDBOptions& /*options*/) : StackableDB(db) {}
84 virtual ~GeoDB() {}
85
86 // Insert a new object into the location database. The object is
87 // uniquely identified by the id. If an object with the same id already
88 // exists in the db, then the old one is overwritten by the new
89 // object being inserted here.
90 virtual Status Insert(const GeoObject& object) = 0;
91
92 // Retrieve the value of the object located at the specified GPS
93 // location and is identified by the 'id'.
94 virtual Status GetByPosition(const GeoPosition& pos,
95 const Slice& id, std::string* value) = 0;
96
97 // Retrieve the value of the object identified by the 'id'. This method
98 // could be potentially slower than GetByPosition
99 virtual Status GetById(const Slice& id, GeoObject* object) = 0;
100
101 // Delete the specified object
102 virtual Status Remove(const Slice& id) = 0;
103
104 // Returns an iterator for the items within a circular radius from the
105 // specified gps location. If 'number_of_values' is specified,
106 // then the iterator is capped to that number of objects.
107 // The radius is specified in 'meters'.
108 virtual GeoIterator* SearchRadial(const GeoPosition& pos,
109 double radius,
110 int number_of_values = INT_MAX) = 0;
111 };
112
113 } // namespace rocksdb
114 #endif // ROCKSDB_LITE