30 #include <boost/scoped_ptr.hpp>
32 #include "mongo/client/export_macros.h"
51 template <
typename TCoordinates>
52 class Point :
public Geometry<TCoordinates> {
65 explicit Point(
const BSONObj& bson);
77 explicit Point(
const TCoordinates& coords);
79 Point(
const Point<TCoordinates>& other);
80 Point& operator=(Point<TCoordinates> other);
134 return GeoObjType_Point;
171 return _coords[dimension];
175 static BSONObj createBSON(
const TCoordinates& coords);
178 TCoordinates _coords;
179 mutable boost::scoped_ptr<BoundingBox<TCoordinates> > _boundingBox;
184 template <
typename TCoordinates>
186 : _bson(
GeoObj<TCoordinates>::validateType(bson, kPointTypeStr)),
187 _coords(
Geometry<TCoordinates>::parseCoords(bson)),
188 _boundingBox(
Geometry<TCoordinates>::parseBoundingBox(bson)) {}
190 template <
typename TCoordinates>
192 : _bson(createBSON(coords)), _coords(coords) {}
194 template <
typename TCoordinates>
196 : _bson(other._bson), _coords(other._coords) {
202 if (other._boundingBox)
206 template <
typename TCoordinates>
207 Point<TCoordinates>& Point<TCoordinates>::operator=(Point<TCoordinates> other) {
209 swap(_bson, other._bson);
210 swap(_coords, other._coords);
211 swap(_boundingBox, other._boundingBox);
215 template <
typename TCoordinates>
218 _boundingBox.reset(computeBoundingBox());
219 return *_boundingBox.get();
222 template <
typename TCoordinates>
228 template <
typename TCoordinates>
229 BoundingBox<TCoordinates>* Point<TCoordinates>::computeBoundingBox()
const {
230 return new BoundingBox<TCoordinates>(_coords, _coords);
double operator[](size_t dimension) const
Get the position of this point in the given dimension.
Definition: point.h:170
Point(const BSONObj &bson)
Point constructor.
Definition: point.h:185
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
virtual BSONObj toBSON() const
Obtain a BSON representation of this point.
Definition: point.h:96
BSONObjBuilder & append(const BSONElement &e)
append element to the object we are building
Definition: bsonobjbuilder.h:124
virtual BoundingBox< TCoordinates > getBoundingBox() const
Get the bounding box of this point.
Definition: point.h:216
Utility for creating a BSONObj.
Definition: bsonobjbuilder.h:53
virtual GeoObjType getType() const
Get the geometry type of this object.
Definition: point.h:133
Represents a Point.
Definition: geometry.h:36
BSONObjBuilder & appendElements(BSONObj x)
add all the fields from the object specified to this object
Definition: geometry.h:39
TCoordinates getCoordinates() const
Get the coordinates of this point.
Definition: point.h:151
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary represent...
Definition: bsonobj.h:78
Represents a bounding box.
Definition: boundingbox.h:67