MongoDB C++ Driver legacy-1.1.2
Loading...
Searching...
No Matches
queryutils.h
1/* Copyright 2014 MongoDB Inc.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#pragma once
17
18#include "mongo/client/export_macros.h"
19#include "mongo/db/jsobj.h"
21#include "mongo/geo/constants.h"
22#include "mongo/geo/geoobj.h"
23
24namespace mongo {
25namespace geo {
26
27template <typename TCoordinates>
28inline BSONObj GEOQUERY(const char* op, const GeoObj<TCoordinates>& geoObj) {
29 return BSON(op << BSON("$geometry" << geoObj.toBSON()));
30}
31
32template <typename TCoordinates>
33inline BSONObj WITHINQUERY(const GeoObj<TCoordinates>& geoObj) {
34 return GEOQUERY("$geoWithin", geoObj);
35}
36
37template <typename TCoordinates>
38inline BSONObj WITHINQUERY(const BoundingBox<TCoordinates>& geoBB) {
39 return BSON("$geoWithin" << BSON("$box" << geoBB.toNestedBSONArray()));
40}
41
42template <typename TCoordinates>
43inline BSONObj INTERSECTSQUERY(const GeoObj<TCoordinates>& geoObj) {
44 return GEOQUERY("$geoIntersects", geoObj);
45}
46
47template <typename TCoordinates>
48inline BSONObj NEARQUERY(const GeoObj<TCoordinates>& geoObj) {
49 return GEOQUERY("$near", geoObj);
50}
51
52template <typename TCoordinates>
53inline BSONObj NEARQUERY(const GeoObj<TCoordinates>& geoObj, double maxDistance) {
54 uassert(0, "$maxDistance param to $near query must be non-negative.", maxDistance >= 0.0);
55 return BSON("$near" << BSON("$geometry" << geoObj.toBSON() << "$maxDistance" << maxDistance));
56}
57
58template <typename TCoordinates>
59inline BSONObj NEARSPHEREQUERY(const GeoObj<TCoordinates>& geoObj) {
60 return GEOQUERY("$nearSphere", geoObj);
61}
62
63template <typename TCoordinates>
64inline BSONObj NEARSPHEREQUERY(const GeoObj<TCoordinates>& geoObj, double maxDistance) {
65 uassert(0, "$maxDistance param to $nearSphere query must be non-negative.", maxDistance >= 0.0);
66 return BSON(
67 "$nearSphere" << BSON("$geometry" << geoObj.toBSON() << "$maxDistance" << maxDistance));
68}
69
70} // namespace geo
71} // namespace mongo
BSON classes.
Utility functions for parsing numbers from strings.
Definition compare_numbers.h:20