diff --git a/map/gps_track.cpp b/map/gps_track.cpp index 07698f6e02..a1823d7333 100644 --- a/map/gps_track.cpp +++ b/map/gps_track.cpp @@ -29,15 +29,20 @@ size_t constexpr kItemBlockSize = 1000; size_t const GpsTrack::kInvalidId = GpsTrackCollection::kInvalidId; -GpsTrack::GpsTrack(string const & filePath, size_t maxItemCount, hours duration) +GpsTrack::GpsTrack(string const & filePath, size_t maxItemCount, hours duration, + unique_ptr && filter) : m_maxItemCount(maxItemCount) , m_filePath(filePath) , m_duration(duration) , m_needClear(false) , m_needSendSnapshop(false) + , m_filter(move(filter)) , m_threadExit(false) , m_threadWakeup(false) { + if (!m_filter) + m_filter = make_unique(); + ASSERT_GREATER(m_maxItemCount, 0, ()); ASSERT(!m_filePath.empty(), ()); ASSERT_GREATER(m_duration.count(), 0, ()); @@ -179,7 +184,7 @@ void GpsTrack::InitCollection(hours duration) if (originPoints.size() == originPoints.capacity()) { vector points; - m_filter.Process(originPoints, points); + m_filter->Process(originPoints, points); pair evictedIds; m_collection->Add(points, evictedIds); @@ -192,7 +197,7 @@ void GpsTrack::InitCollection(hours duration) if (!originPoints.empty()) { vector points; - m_filter.Process(originPoints, points); + m_filter->Process(originPoints, points); pair evictedIds; m_collection->Add(points, evictedIds); @@ -233,7 +238,7 @@ void GpsTrack::ProcessPoints() return; vector points; - m_filter.Process(originPoints, points); + m_filter->Process(originPoints, points); pair addedIds; pair evictedIds; diff --git a/map/gps_track.hpp b/map/gps_track.hpp index ddc2c33acd..1ad2c38d45 100644 --- a/map/gps_track.hpp +++ b/map/gps_track.hpp @@ -17,7 +17,9 @@ public: /// @param filePath - path to the file on disk to persist track /// @param maxItemCount - number of points to store on disk /// @param duration - initial value of track duration - GpsTrack(string const & filePath, size_t maxItemCount, hours duration); + /// @param filter - filter object used for filtering points, GpsTrackNullFilter is created by default + GpsTrack(string const & filePath, size_t maxItemCount, hours duration, + unique_ptr && filter = unique_ptr()); ~GpsTrack(); /// Adds point or collection of points to gps tracking @@ -82,7 +84,7 @@ private: unique_ptr m_storage; // used in the worker thread unique_ptr m_collection; // used in the worker thread - GpsTrackFilter m_filter; + unique_ptr m_filter; // used in the worker thread mutex m_threadGuard; thread m_thread; diff --git a/map/gps_track_filter.cpp b/map/gps_track_filter.cpp index ec0a679792..f0e2b68563 100644 --- a/map/gps_track_filter.cpp +++ b/map/gps_track_filter.cpp @@ -4,6 +4,8 @@ #include "platform/settings.hpp" +#include "std/algorithm.hpp" + namespace { @@ -17,6 +19,13 @@ double constexpr kClosePointDistanceMeters = 15; } // namespace +void GpsTrackNullFilter::Process(vector const & inPoints, + vector & outPoints) +{ + outPoints.reserve(inPoints.size()); + copy(inPoints.begin(), inPoints.end(), back_inserter(outPoints)); +} + void GpsTrackFilter::StoreMinHorizontalAccuracy(double value) { Settings::Set(kMinHorizontalAccuracyKey, value); diff --git a/map/gps_track_filter.hpp b/map/gps_track_filter.hpp index 5e9c8c253f..7c89c65b5a 100644 --- a/map/gps_track_filter.hpp +++ b/map/gps_track_filter.hpp @@ -6,7 +6,24 @@ #include "std/vector.hpp" -class GpsTrackFilter +class IGpsTrackFilter +{ +public: + virtual ~IGpsTrackFilter() = default; + + virtual void Process(vector const & inPoints, + vector & outPoints) = 0; +}; + +class GpsTrackNullFilter : public IGpsTrackFilter +{ +public: + // IGpsTrackFilter overrides + void Process(vector const & inPoints, + vector & outPoints) override; +}; + +class GpsTrackFilter : public IGpsTrackFilter { public: /// Store setting for minimal horizontal accuracy @@ -14,8 +31,9 @@ public: GpsTrackFilter(); + // IGpsTrackFilter overrides void Process(vector const & inPoints, - vector & outPoints); + vector & outPoints) override; private: double m_minAccuracy; diff --git a/map/gps_tracker.cpp b/map/gps_tracker.cpp index a90b08e5f5..97de3cc9a0 100644 --- a/map/gps_tracker.cpp +++ b/map/gps_tracker.cpp @@ -58,7 +58,7 @@ GpsTracker & GpsTracker::Instance() GpsTracker::GpsTracker() : m_enabled(GetSettingsIsEnabled()) - , m_track(GetFilePath(), kMaxItemCount, GetSettingsDuration()) + , m_track(GetFilePath(), kMaxItemCount, GetSettingsDuration(), make_unique()) { }