MongoDB C++ Driver  legacy-1.1.2
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"
24 #include "mongo/geo/boundingbox.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 
30 namespace mongo {
31 namespace geo {
32 
33 template <typename TCoordinates>
34 class MultiPoint : public Geometry<TCoordinates> {
35 public:
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 
77 private:
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 
91 template <typename TCoordinates>
93  : _bson(GeoObj<TCoordinates>::validateType(bson, kMultiPointTypeStr)),
94  _points(Geometry<TCoordinates>::parseAllPoints(bson)),
95  _boundingBox(Geometry<TCoordinates>::parseBoundingBox(bson)) {}
96 
97 template <typename TCoordinates>
99  if (!_boundingBox)
100  _boundingBox.reset(computeBoundingBox());
101  return *_boundingBox.get();
102 }
103 
104 template <typename TCoordinates>
107 }
108 
109 } // namespace geo
110 } // namespace mongo
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
BSON classes.
MultiPoint(const BSONObj &bson)
MultiPoint constructor.
Definition: multipoint.h:92
Definition: geoobj.h:34
virtual BSONObj toBSON() const
Obtain a BSON representation of the MultiPoint.
Definition: multipoint.h:48
virtual GeoObjType getType() const
Get the geometry type of this object.
Definition: multipoint.h:64
Definition: multipoint.h:34
std::vector< Point< TCoordinates > > getPoints() const
Obtain the points that make up this MultiPoint.
Definition: multipoint.h:73
Definition: geometry.h:39
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary represent...
Definition: bsonobj.h:78
static BoundingBox< TCoordinates > * computeBoundingBox(const std::vector< Point< TCoordinates > > &points)
Compute the bounding box around the given points.
Definition: geometry.h:137
Represents a bounding box.
Definition: boundingbox.h:67
virtual BoundingBox< TCoordinates > getBoundingBox() const
Obtain the bounding box surrounding this MultiPoint.
Definition: multipoint.h:98