diff options
author | ADAM David Alan Martin <adam.martin@10gen.com> | 2017-03-10 18:34:08 -0500 |
---|---|---|
committer | ADAM David Alan Martin <adam.martin@10gen.com> | 2017-03-10 18:34:08 -0500 |
commit | 04b8ed12d08affcb06e88c8a2b4398628ae0aa62 (patch) | |
tree | 3e1a43aa762a2136422b4fa66f70ee89222d29a1 /src/mongo/db/geo | |
parent | 56810e6acb3a0425284189d852eaefb391e5f800 (diff) | |
download | mongo-04b8ed12d08affcb06e88c8a2b4398628ae0aa62.tar.gz |
SERVER-27975 Remove many uses of `OwnedPointerVector`
This removes many of the remaining uses of the deprecated
`OwnedPointerVector` type.
Diffstat (limited to 'src/mongo/db/geo')
-rw-r--r-- | src/mongo/db/geo/big_polygon.cpp | 15 | ||||
-rw-r--r-- | src/mongo/db/geo/geometry_container.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/geo/geoparser.cpp | 20 |
3 files changed, 28 insertions, 13 deletions
diff --git a/src/mongo/db/geo/big_polygon.cpp b/src/mongo/db/geo/big_polygon.cpp index f50bdf1ae37..a83a59dd41c 100644 --- a/src/mongo/db/geo/big_polygon.cpp +++ b/src/mongo/db/geo/big_polygon.cpp @@ -31,7 +31,9 @@ #include <map> #include "mongo/base/owned_pointer_vector.h" +#include "mongo/stdx/memory.h" #include "mongo/util/assert_util.h" +#include "mongo/util/transitional_tools_do_not_use/vector_spooling.h" namespace mongo { @@ -90,16 +92,19 @@ bool BigSimplePolygon::Contains(const S2Polyline& line) const { // const S2Polygon& polyBorder = GetPolygonBorder(); - OwnedPointerVector<S2Polyline> clippedOwned; - vector<S2Polyline*>& clipped = clippedOwned.mutableVector(); + std::vector<S2Polyline*> clipped; if (_isNormalized) { // Polygon border is the same as the loop polyBorder.SubtractFromPolyline(&line, &clipped); + const std::vector<std::unique_ptr<S2Polyline>> clippedOwned = + transitional_tools_do_not_use::spool_vector(clipped); return clipped.size() == 0; } else { // Polygon border is the complement of the loop polyBorder.IntersectWithPolyline(&line, &clipped); + const std::vector<std::unique_ptr<S2Polyline>> clippedOwned = + transitional_tools_do_not_use::spool_vector(clipped); return clipped.size() == 0; } } @@ -164,9 +169,9 @@ const S2Polygon& BigSimplePolygon::GetPolygonBorder() const { // Any loop in polygon should be than a hemisphere (2*Pi). cloned->Normalize(); - OwnedPointerVector<S2Loop> loops; - loops.mutableVector().push_back(cloned.release()); - _borderPoly.reset(new S2Polygon(&loops.mutableVector())); + std::vector<S2Loop*> loops; + loops.push_back(cloned.release()); + _borderPoly = stdx::make_unique<S2Polygon>(&loops); return *_borderPoly; } diff --git a/src/mongo/db/geo/geometry_container.cpp b/src/mongo/db/geo/geometry_container.cpp index 3ae63e40690..2b571f1b9f0 100644 --- a/src/mongo/db/geo/geometry_container.cpp +++ b/src/mongo/db/geo/geometry_container.cpp @@ -31,6 +31,7 @@ #include "mongo/db/geo/geoconstants.h" #include "mongo/db/geo/geoparser.h" #include "mongo/util/mongoutils/str.h" +#include "mongo/util/transitional_tools_do_not_use/vector_spooling.h" namespace mongo { @@ -422,10 +423,11 @@ bool containsLine(const S2Polygon& poly, const S2Polyline& otherLine) { // Kind of a mess. We get a function for clipping the line to the // polygon. We do this and make sure the line is the same as the // line we're clipping against. - OwnedPointerVector<S2Polyline> clippedOwned; - vector<S2Polyline*>& clipped = clippedOwned.mutableVector(); + std::vector<S2Polyline*> clipped; poly.IntersectWithPolyline(&otherLine, &clipped); + const std::vector<std::unique_ptr<S2Polyline>> clippedOwned = + transitional_tools_do_not_use::spool_vector(clipped); if (1 != clipped.size()) { return false; } diff --git a/src/mongo/db/geo/geoparser.cpp b/src/mongo/db/geo/geoparser.cpp index 2be29d1dd7a..e5b09077bd5 100644 --- a/src/mongo/db/geo/geoparser.cpp +++ b/src/mongo/db/geo/geoparser.cpp @@ -31,14 +31,17 @@ #include "mongo/db/geo/geoparser.h" #include <cmath> +#include <memory> #include <string> #include <vector> #include "mongo/db/bson/dotted_path_support.h" #include "mongo/db/geo/shapes.h" #include "mongo/db/jsobj.h" +#include "mongo/stdx/memory.h" #include "mongo/util/log.h" #include "mongo/util/mongoutils/str.h" +#include "mongo/util/transitional_tools_do_not_use/vector_spooling.h" #include "third_party/s2/s2polygonbuilder.h" #define BAD_VALUE(error) Status(ErrorCodes::BadValue, ::mongoutils::str::stream() << error) @@ -180,7 +183,7 @@ static Status parseGeoJSONPolygonCoordinates(const BSONElement& elem, return BAD_VALUE("Polygon coordinates must be an array"); } - OwnedPointerVector<S2Loop> loops; + std::vector<std::unique_ptr<S2Loop>> loops; Status status = Status::OK(); string err; @@ -209,8 +212,8 @@ static Status parseGeoJSONPolygonCoordinates(const BSONElement& elem, "Loop must have at least 3 different vertices: " << coordinateElt.toString(false)); } - S2Loop* loop = new S2Loop(points); - loops.push_back(loop); + loops.push_back(stdx::make_unique<S2Loop>(points)); + S2Loop* loop = loops.back().get(); // Check whether this loop is valid. // 1. At least 3 vertices. @@ -239,18 +242,23 @@ static Status parseGeoJSONPolygonCoordinates(const BSONElement& elem, return BAD_VALUE("Polygon has no loops."); } + // Check if the given loops form a valid polygon. // 1. If a loop contains an edge AB, then no other loop may contain AB or BA. // 2. No loop covers more than half of the sphere. // 3. No two loops cross. - if (!skipValidation && !S2Polygon::IsValid(loops.vector(), &err)) + if (!skipValidation && + !S2Polygon::IsValid(transitional_tools_do_not_use::unspool_vector(loops), &err)) return BAD_VALUE("Polygon isn't valid: " << err << " " << elem.toString(false)); // Given all loops are valid / normalized and S2Polygon::IsValid() above returns true. // The polygon must be valid. See S2Polygon member function IsValid(). - // Transfer ownership of the loops and clears loop vector. - out->Init(&loops.mutableVector()); + { + // Transfer ownership of the loops and clears loop vector. + std::vector<S2Loop*> rawLoops = transitional_tools_do_not_use::leak_vector(loops); + out->Init(&rawLoops); + } if (skipValidation) return Status::OK(); |