From 2182167b533b4c71dc64747d4d761cd780cfbde2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salvador=20Cu=C3=B1at?= Date: Sat, 2 Dec 2017 11:28:00 +0100 Subject: [PATCH] applying gps fixes: group repetitive code under a macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Title is self explanatory. [Dirk Hohndel: small edits to remove typo / improve readability] Signed-off-by: Salvador Cuñat Signed-off-by: Dirk Hohndel --- desktop-widgets/subsurfacewebservices.cpp | 27 ++++++++++------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp index 0537723b8..b11a910f1 100644 --- a/desktop-widgets/subsurfacewebservices.cpp +++ b/desktop-widgets/subsurfacewebservices.cpp @@ -55,6 +55,13 @@ static void copy_gps_location(struct dive *from, struct dive *to) } #define SAME_GROUP 6 * 3600 // six hours +#define SET_LOCATION(_dive, _gpsfix, _mark) \ +{ \ + copy_gps_location(_gpsfix, _dive); \ + changed ++; \ + tracer = _mark; \ +} + //TODO: C Code. static functions are not good if we plan to have a test for them. static bool merge_locations_into_dives(void) { @@ -79,9 +86,7 @@ static bool merge_locations_into_dives(void) if (time_during_dive_with_offset(dive, gpsfix->when, 0)) { if (verbose) qDebug() << "gpsfix is during the dive, pick that one"; - copy_gps_location(gpsfix, dive); - changed++; - tracer = j; + SET_LOCATION(dive, gpsfix, j); break; } else { /* @@ -101,25 +106,19 @@ static bool merge_locations_into_dives(void) } else if (gpsfix->when > dive_endtime(dive)) { if (verbose) qDebug() << "which is even later after the end of the dive, so pick the previous one"; - copy_gps_location(gpsfix, dive); - changed++; - tracer = j; + SET_LOCATION(dive, gpsfix, j); break; } else { /* ok, gpsfix is before, nextgpsfix is after */ if (dive->when - gpsfix->when <= nextgpsfix->when - dive_endtime(dive)) { if (verbose) qDebug() << "pick the one before as it's closer to the start"; - copy_gps_location(gpsfix, dive); - changed++; - tracer = j; + SET_LOCATION(dive, gpsfix, j); break; } else { if (verbose) qDebug() << "pick the one after as it's closer to the start"; - copy_gps_location(nextgpsfix, dive); - changed++; - tracer = j + 1; + SET_LOCATION(dive, nextgpsfix, j + 1); break; } } @@ -129,9 +128,7 @@ static bool merge_locations_into_dives(void) } else { if (verbose) qDebug() << "which seems to be the best one for this dive, so pick it"; - copy_gps_location(gpsfix, dive); - changed++; - tracer = j; + SET_LOCATION(dive, gpsfix, j); break; } }