diff options
author | vng <viktor.govako@gmail.com> | 2013-10-29 14:23:54 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:04:17 +0300 |
commit | ed59cfa77b60fc1e19f9a4709fc38d406a91172c (patch) | |
tree | 637eebaaafe02eaccc032a3c9e3b4c709993e828 /map/bookmark.cpp | |
parent | 47d6a7ce4a71ffef41a4ec133cd55d2baf481ef4 (diff) |
[tracks] Code cleanup.
Diffstat (limited to 'map/bookmark.cpp')
-rw-r--r-- | map/bookmark.cpp | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/map/bookmark.cpp b/map/bookmark.cpp index bb2ab1f369..fa968eafd5 100644 --- a/map/bookmark.cpp +++ b/map/bookmark.cpp @@ -22,7 +22,7 @@ void BookmarkCategory::AddTrack(Track & track) m_tracks.push_back(track.CreatePersistent()); } -Track * BookmarkCategory::GetTrack(size_t index) const +Track const * BookmarkCategory::GetTrack(size_t index) const { return (index < m_tracks.size() ? m_tracks[index] : 0); } @@ -75,37 +75,42 @@ void BookmarkCategory::ClearTracks() m_tracks.clear(); } -void BookmarkCategory::DeleteBookmark(size_t index) +namespace { - if (index < m_bookmarks.size()) + +template <class T> void DeleteItem(vector<T> & v, size_t i) +{ + if (i < v.size()) { - delete m_bookmarks[index]; - m_bookmarks.erase(m_bookmarks.begin() + index); + delete v[i]; + v.erase(v.begin() + i); } else { - LOG(LWARNING, ("Trying to delete non-existing bookmark in category", GetName(), "at index", index)); + LOG(LWARNING, ("Trying to delete non-existing item at index", i)); } } -Bookmark const * BookmarkCategory::GetBookmark(size_t index) const +} + +void BookmarkCategory::DeleteBookmark(size_t index) { - return (index < m_bookmarks.size() ? m_bookmarks[index] : 0); + DeleteItem(m_bookmarks, index); } -Bookmark * BookmarkCategory::GetBookmark(size_t index) +void BookmarkCategory::DeleteTrack(size_t index) +{ + DeleteItem(m_tracks, index); +} + +Bookmark const * BookmarkCategory::GetBookmark(size_t index) const { return (index < m_bookmarks.size() ? m_bookmarks[index] : 0); } -int BookmarkCategory::GetBookmark(m2::PointD const org, double const squareDistance) const +Bookmark * BookmarkCategory::GetBookmark(size_t index) { - for (size_t i = 0; i < m_bookmarks.size(); ++i) - { - if (squareDistance >= org.SquareLength(m_bookmarks[i]->GetOrg())) - return static_cast<int>(i); - } - return -1; + return (index < m_bookmarks.size() ? m_bookmarks[index] : 0); } namespace |