MongoDB C++ Driver legacy-1.1.2
Loading...
Searching...
No Matches
coordinates2d.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 Coordinates2D : public Coordinates {
41public:
42 Coordinates2D() : _x(0), _y(0) {}
43
51 explicit Coordinates2D(const std::vector<double>& coords);
52
58 explicit Coordinates2D(const std::pair<double, double>& coords);
59
66 Coordinates2D(double x, double y) : _x(x), _y(y) {}
67
73 double getX() const {
74 return _x;
75 }
76
82 double getY() const {
83 return _y;
84 }
85
92 virtual std::vector<double> getValues() const;
93
100 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 _x;
133 double _y;
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 position (x, y).
Definition coordinates2d.h:40
Coordinates2D(double x, double y)
Coordinates2D constructor.
Definition coordinates2d.h:66
static size_t MONGO_CLIENT_FUNC dimensionality()
Get the dimensionality of this coordinate type.
Definition coordinates2d.h:127
virtual double operator[](size_t dimension) const
Get the value of this coordinate at the given dimension.
virtual BSONObj toBSON() const
Get a BSON representation of the coordinates.
double getY() const
Get the y coordinate.
Definition coordinates2d.h:82
Coordinates2D(const std::pair< double, double > &coords)
Coordinates2D constructor.
Coordinates2D(const std::vector< double > &coords)
Coordinates2D constructor.
virtual std::vector< double > getValues() const
Get the x and y coordinates.
std::pair< double, double > getValuesAsPair() const
Get the x and y coordinates as a std::pair.
double getX() const
Get the x coordinate.
Definition coordinates2d.h:73
Definition coordinates.h:28
BSON classes.
Utility functions for parsing numbers from strings.
Definition compare_numbers.h:20