From 74f5a64035784a75fdaf66163771fd3a8bedf138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Wed, 1 Apr 2020 00:24:59 -0700 Subject: [PATCH] [ios, macos] Wrap map in unique pointer Also removed unused method declarations. --- platform/ios/src/MGLMapView.mm | 23 ++++++++++------------- platform/macos/src/MGLMapView.mm | 13 +++---------- platform/macos/src/MGLMapView_Private.h | 2 -- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 56ede0bb9..ab0eba259 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -280,13 +280,11 @@ public: @property (nonatomic, assign) UIEdgeInsets safeMapViewContentInsets; @property (nonatomic, strong) NSNumber *automaticallyAdjustContentInsetHolder; -- (mbgl::Map &)mbglMap; - @end @implementation MGLMapView { - mbgl::Map *_mbglMap; + std::unique_ptr _mbglMap; std::unique_ptr _mbglView; std::unique_ptr _rendererFrontend; @@ -499,7 +497,7 @@ public: .withAssetPath([NSBundle mainBundle].resourceURL.path.UTF8String); NSAssert(!_mbglMap, @"_mbglMap should be NULL"); - _mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, mapOptions, resourceOptions); + _mbglMap = std::make_unique(*_rendererFrontend, *_mbglView, mapOptions, resourceOptions); // start paused if in IB if (background) { @@ -716,8 +714,7 @@ public: // Tear down C++ objects, insuring worker threads correctly terminate. // Because of how _mbglMap is constructed, we need to destroy it first. - delete _mbglMap; - _mbglMap = nullptr; + _mbglMap.reset(); _mbglView.reset(); @@ -2807,12 +2804,12 @@ public: - (void)setPrefetchesTiles:(BOOL)prefetchesTiles { - _mbglMap->setPrefetchZoomDelta(prefetchesTiles ? mbgl::util::DEFAULT_PREFETCH_ZOOM_DELTA : 0); + self.mbglMap.setPrefetchZoomDelta(prefetchesTiles ? mbgl::util::DEFAULT_PREFETCH_ZOOM_DELTA : 0); } - (BOOL)prefetchesTiles { - return _mbglMap->getPrefetchZoomDelta() > 0 ? YES : NO; + return self.mbglMap.getPrefetchZoomDelta() > 0 ? YES : NO; } #pragma mark - Accessibility - @@ -3527,24 +3524,24 @@ public: - (CGFloat)minimumPitch { - return *_mbglMap->getBounds().minPitch; + return *self.mbglMap.getBounds().minPitch; } - (void)setMinimumPitch:(CGFloat)minimumPitch { MGLLogDebug(@"Setting minimumPitch: %f", minimumPitch); - _mbglMap->setBounds(mbgl::BoundOptions().withMinPitch(minimumPitch)); + self.mbglMap.setBounds(mbgl::BoundOptions().withMinPitch(minimumPitch)); } - (CGFloat)maximumPitch { - return *_mbglMap->getBounds().maxPitch; + return *self.mbglMap.getBounds().maxPitch; } - (void)setMaximumPitch:(CGFloat)maximumPitch { MGLLogDebug(@"Setting maximumPitch: %f", maximumPitch); - _mbglMap->setBounds(mbgl::BoundOptions().withMaxPitch(maximumPitch)); + self.mbglMap.setBounds(mbgl::BoundOptions().withMaxPitch(maximumPitch)); } - (MGLCoordinateBounds)visibleCoordinateBounds @@ -6476,7 +6473,7 @@ public: MGLImage *imageToLoad = [self.delegate mapView:self didFailToLoadImage:imageName]; if (imageToLoad) { auto image = [imageToLoad mgl_styleImageWithIdentifier:imageName]; - _mbglMap->getStyle().addImage(std::move(image)); + self.mbglMap.getStyle().addImage(std::move(image)); } } } diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index a234199d4..61f49c08f 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -154,7 +154,7 @@ public: @implementation MGLMapView { /// Cross-platform map view controller. - mbgl::Map *_mbglMap; + std::unique_ptr _mbglMap; std::unique_ptr _mbglView; std::unique_ptr _rendererFrontend; @@ -295,7 +295,7 @@ public: resourceOptions.withCachePath([[MGLOfflineStorage sharedOfflineStorage] mbglCachePath]) .withAssetPath([NSBundle mainBundle].resourceURL.path.UTF8String); - _mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, mapOptions, resourceOptions); + _mbglMap = std::make_unique(*_rendererFrontend, *_mbglView, mapOptions, resourceOptions); // Notify map object when network reachability status changes. _reachability = [MGLReachability reachabilityForInternetConnection]; @@ -539,10 +539,7 @@ public: // Removing the annotations unregisters any outstanding KVO observers. [self removeAnnotations:self.annotations]; - if (_mbglMap) { - delete _mbglMap; - _mbglMap = nullptr; - } + _mbglMap.reset(); _mbglView.reset(); } @@ -662,10 +659,6 @@ public: _mbglMap->setPrefetchZoomDelta(prefetchesTiles ? mbgl::util::DEFAULT_PREFETCH_ZOOM_DELTA : 0); } -- (mbgl::Map *)mbglMap { - return _mbglMap; -} - - (mbgl::Renderer *)renderer { return _rendererFrontend->getRenderer(); } diff --git a/platform/macos/src/MGLMapView_Private.h b/platform/macos/src/MGLMapView_Private.h index 3d9b36c30..05e932d84 100644 --- a/platform/macos/src/MGLMapView_Private.h +++ b/platform/macos/src/MGLMapView_Private.h @@ -55,8 +55,6 @@ namespace mbgl { - (BOOL)isTargetingInterfaceBuilder; -- (nonnull mbgl::Map *)mbglMap; - - (nonnull mbgl::Renderer *)renderer; @end