MongoDB C++ Driver legacy-1.1.1
Loading...
Searching...
No Matches
coordinates2dgeographic.h
Go to the documentation of this file.
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
18#pragma once
19
20#include <utility>
21#include <vector>
22
23#include "mongo/client/export_macros.h"
24#include "mongo/db/jsobj.h"
26
27namespace mongo {
28namespace geo {
29
40class MONGO_CLIENT_API Coordinates2DGeographic : public Coordinates {
41public:
42 Coordinates2DGeographic() : _longitude(0), _latitude(0) {}
43
51 explicit Coordinates2DGeographic(const std::vector<double>& coords);
52
58 explicit Coordinates2DGeographic(const std::pair<double, double>& coords);
59
66 Coordinates2DGeographic(double longitude, double latitude);
67
73 double getLongitude() const {
74 return _longitude;
75 }
76
82 double getLatitude() const {
83 return _latitude;
84 }
85
92 virtual std::vector<double> getValues() const;
93
100 virtual std::pair<double, double> getValuesAsPair() const;
101
108 virtual BSONObj toBSON() const;
109
120 virtual double operator[](size_t dimension) const;
121
127 static size_t MONGO_CLIENT_FUNC dimensionality() {
128 return 2;
129 }
130
131private:
132 double _longitude;
133 double _latitude;
134};
135
136} // namespace geo
137} // namespace mongo
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary representa...
Definition bsonobj.h:78
Represents a 2D geographic position (longitude, latitude).
Definition coordinates2dgeographic.h:40
virtual double operator[](size_t dimension) const
Get the value of this coordinate at the given dimension.
double getLongitude() const
Get the longitude.
Definition coordinates2dgeographic.h:73
double getLatitude() const
Get the latitude.
Definition coordinates2dgeographic.h:82
Coordinates2DGeographic(const std::vector< double > &coords)
Coordinates2DGeographic constructor.
virtual std::vector< double > getValues() const
Get the longitude and latitude values as a vector.
virtual BSONObj toBSON() const
Get a BSON representation of the coordinates.
virtual std::pair< double, double > getValuesAsPair() const
Get the longitude and latitude values as a pair.
static size_t MONGO_CLIENT_FUNC dimensionality()
Get the dimensionality of this coordinate type.
Definition coordinates2dgeographic.h:127
Coordinates2DGeographic(double longitude, double latitude)
Coordinates2DGeographic constructor.
Coordinates2DGeographic(const std::pair< double, double > &coords)
Coordinates2DGeographic constructor.
Definition coordinates.h:28
BSON classes.
Utility functions for parsing numbers from strings.
Definition compare_numbers.h:32