MongoDB C++ Driver legacy-1.1.1
Loading...
Searching...
No Matches
geoobj.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 <string>
21#include <vector>
22
23#include "mongo/base/string_data.h"
24#include "mongo/client/export_macros.h"
25#include "mongo/db/jsobj.h"
27#include "mongo/geo/constants.h"
28#include "mongo/util/assert_util.h"
29
30namespace mongo {
31namespace geo {
32
33template <typename TCoordinates>
34class GeoObj {
35public:
36 virtual ~GeoObj() {}
37
43 virtual BSONObj toBSON() const = 0;
44
51
57 virtual GeoObjType getType() const = 0;
58
59protected:
60 static BSONObj validateType(const BSONObj& bson, const StringData& typeStr);
61};
62
63template <typename TCoordinates>
65 BSONElement typeField = bson.getField(kTypeFieldName);
66 uassert(0,
67 "bson must be a valid " + typeStr.toString() + " type",
68 !typeField.eoo() && ((typeField.type() == String) || (typeField.String() == typeStr)));
69 return bson;
70}
71
72} // namespace geo
73} // namespace mongo
BSONElement represents an "element" in a BSONObj.
Definition bsonelement.h:55
bool eoo() const
Indicates if it is the end-of-object element, which is present at the end of every BSON object.
Definition bsonelement.h:172
BSONType type() const
Returns the type of the element.
Definition bsonelement.h:154
std::string String() const
These functions, which start with a capital letter, throw a MsgAssertionException if the element is n...
Definition bsonelement.h:62
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary representa...
Definition bsonobj.h:78
BSONElement getField(const StringData &name) const
Get the field of the specified name.
A StringData object wraps a 'const string&' or a 'const char*' without copying its contents.
Definition string_data.h:43
Represents a bounding box.
Definition boundingbox.h:67
Definition geoobj.h:34
virtual BSONObj toBSON() const =0
Obtain a BSON representation of this GeoObj.
virtual BoundingBox< TCoordinates > getBoundingBox() const =0
Obtain the bounding box of this GeoObj.
virtual GeoObjType getType() const =0
Get the geometry type of this object.
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:32
@ String
character string, stored in utf8
Definition bsontypes.h:46