MongoDB C++ Driver  legacy-1.1.2
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"
25 #include "mongo/geo/coordinates.h"
26 
27 namespace mongo {
28 namespace geo {
29 
40 class MONGO_CLIENT_API Coordinates2DGeographic : public Coordinates {
41 public:
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 
131 private:
132  double _longitude;
133  double _latitude;
134 };
135 
136 } // namespace geo
137 } // namespace mongo
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
BSON classes.
Represents a 2D geographic position (longitude, latitude).
Definition: coordinates2dgeographic.h:40
Definition: coordinates.h:28
double getLatitude() const
Get the latitude.
Definition: coordinates2dgeographic.h:82
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary represent...
Definition: bsonobj.h:78
double getLongitude() const
Get the longitude.
Definition: coordinates2dgeographic.h:73
static size_t MONGO_CLIENT_FUNC dimensionality()
Get the dimensionality of this coordinate type.
Definition: coordinates2dgeographic.h:127