MongoDB C++ Driver legacy-1.1.2
Loading...
Searching...
No Matches
multipoint.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 <boost/scoped_ptr.hpp>
21#include <vector>
22
23#include "mongo/db/jsobj.h"
25#include "mongo/geo/constants.h"
26#include "mongo/geo/geometry.h"
27#include "mongo/geo/geoobj.h"
28#include "mongo/geo/point.h"
29
30namespace mongo {
31namespace geo {
32
33template <typename TCoordinates>
34class MultiPoint : public Geometry<TCoordinates> {
35public:
41 explicit MultiPoint(const BSONObj& bson);
42
48 virtual BSONObj toBSON() const {
49 return _bson;
50 }
51
58
64 virtual GeoObjType getType() const {
65 return GeoObjType_MultiPoint;
66 }
67
73 std::vector<Point<TCoordinates> > getPoints() const {
74 return _points;
75 }
76
77private:
78 BSONObj _bson;
79 std::vector<Point<TCoordinates> > _points;
80 mutable boost::scoped_ptr<BoundingBox<TCoordinates> > _boundingBox;
81
88 BoundingBox<TCoordinates>* computeBoundingBox() const;
89};
90
91template <typename TCoordinates>
93 : _bson(GeoObj<TCoordinates>::validateType(bson, kMultiPointTypeStr)),
94 _points(Geometry<TCoordinates>::parseAllPoints(bson)),
95 _boundingBox(Geometry<TCoordinates>::parseBoundingBox(bson)) {}
96
97template <typename TCoordinates>
99 if (!_boundingBox)
100 _boundingBox.reset(computeBoundingBox());
101 return *_boundingBox.get();
102}
103
104template <typename TCoordinates>
107}
108
109} // namespace geo
110} // 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 bounding box.
Definition boundingbox.h:67
Definition geoobj.h:34
Definition geometry.h:39
static BoundingBox< TCoordinates > * computeBoundingBox(const std::vector< Point< TCoordinates > > &points)
Compute the bounding box around the given points.
Definition geometry.h:137
Definition multipoint.h:34
virtual BSONObj toBSON() const
Obtain a BSON representation of the MultiPoint.
Definition multipoint.h:48
virtual BoundingBox< TCoordinates > getBoundingBox() const
Obtain the bounding box surrounding this MultiPoint.
Definition multipoint.h:98
MultiPoint(const BSONObj &bson)
MultiPoint constructor.
Definition multipoint.h:92
virtual GeoObjType getType() const
Get the geometry type of this object.
Definition multipoint.h:64
std::vector< Point< TCoordinates > > getPoints() const
Obtain the points that make up this MultiPoint.
Definition multipoint.h:73
GeoObjType
An enum to represent the type of geometry of a Geo object.
Definition constants.h:45
BSON classes.
Utility functions for parsing numbers from strings.
Definition compare_numbers.h:20