Skip to content

Commit

Permalink
wip on common waypt deleters.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteven4 committed Aug 1, 2023
1 parent ba10853 commit 3aa5485
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 249 deletions.
10 changes: 8 additions & 2 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ class Waypoint
};

using waypt_cb = void (*)(const Waypoint*);
using wpt_evaluator_t = bool (*)(const Waypoint*);
inline bool wpt_extra_data_evaluator(const Waypoint* wpt) {return wpt->extra_data != nullptr;}


// TODO: Consider using composition instead of private inheritance.
class WaypointList : private QList<Waypoint*>
Expand All @@ -479,6 +482,7 @@ class WaypointList : private QList<Waypoint*>
// FIXME: Generally it is inefficient to use an element pointer or reference to define the element to be deleted, use iterator instead,
// and/or implement pop_back() a.k.a. removeLast(), and/or pop_front() a.k.a. removeFirst().
void waypt_del(Waypoint* wpt); // a.k.a. erase()
void del_wpts(wpt_evaluator_t ev);
// FIXME: Generally it is inefficient to use an element pointer or reference to define the element to be deleted, use iterator instead,
// and/or implement pop_back() a.k.a. removeLast(), and/or pop_front() a.k.a. removeFirst().
void del_rte_waypt(Waypoint* wpt);
Expand Down Expand Up @@ -521,6 +525,7 @@ void waypt_init();
//void update_common_traits(const Waypoint* wpt);
void waypt_add(Waypoint* wpt);
void waypt_del(Waypoint* wpt);
void del_wpts(wpt_evaluator_t ev);
unsigned int waypt_count();
void waypt_status_disp(int total_ct, int myct);
//void waypt_disp_all(waypt_cb); /* template */
Expand Down Expand Up @@ -658,6 +663,7 @@ class RouteList : private QList<route_head*>
void add_wpt(route_head* rte, Waypoint* wpt, bool synth, QStringView namepart, int number_digits);
// FIXME: Generally it is inefficient to use an element pointer or reference to define the insertion point, use iterator instead.
void del_wpt(route_head* rte, Waypoint* wpt);
void del_wpts(route_head* rte, wpt_evaluator_t ev);
void common_disp_session(const session_t* se, route_hdr rh, route_trl rt, waypt_cb wc);
void flush(); // a.k.a. clear()
void copy(RouteList** dst) const;
Expand Down Expand Up @@ -718,8 +724,8 @@ void route_add_wpt(route_head* rte, Waypoint* wpt, QStringView namepart = u"RPT"
void track_add_wpt(route_head* rte, Waypoint* wpt, QStringView namepart = u"RPT", int number_digits = 3);
void route_del_wpt(route_head* rte, Waypoint* wpt);
void track_del_wpt(route_head* rte, Waypoint* wpt);
void route_swap_wpts(route_head* rte, WaypointList& other);
void track_swap_wpts(route_head* rte, WaypointList& other);
void route_del_wpts(route_head* rte, wpt_evaluator_t ev);
void track_del_wpts(route_head* rte, wpt_evaluator_t ev);
//void route_disp(const route_head* rte, waypt_cb); /* template */
void route_disp(const route_head* rte, std::nullptr_t /* waypt_cb */); /* override to catch nullptr */
//void route_disp_all(route_hdr, route_trl, waypt_cb); /* template */
Expand Down
72 changes: 26 additions & 46 deletions discard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include <cstdlib> // for strtod

#include "defs.h" // for Waypoint, fatal, route_del_wpt, route_disp_all, track_del_wpt, track_disp_all, waypt_del, waypt_disp_all, route_head, rtedata, trkdata, wptdata, fix_none, fix_unknown
#include "defs.h" // for Waypoint, fatal, route_head (ptr only), xstrtoi, wpt_extra_data_evaluator, del_wpts, route_del_wpts, route_disp_all, track_del_wpts, track_disp_all, waypt_disp_all, fix_none, fix_unknown
#include "src/core/logging.h" // for FatalMsg


Expand All @@ -41,12 +41,10 @@ void DiscardFilter::fix_process_wpt(const Waypoint* wpt)
bool delh = false;
bool delv = false;

auto* waypointp = const_cast<Waypoint*>(wpt);

if ((hdopf >= 0.0) && (waypointp->hdop > hdopf)) {
if ((hdopf >= 0.0) && (wpt->hdop > hdopf)) {
delh = true;
}
if ((vdopf >= 0.0) && (waypointp->vdop > vdopf)) {
if ((vdopf >= 0.0) && (wpt->vdop > vdopf)) {
delv = true;
}

Expand All @@ -56,81 +54,63 @@ void DiscardFilter::fix_process_wpt(const Waypoint* wpt)
del = delh || delv;
}

if ((satpf >= 0) && (waypointp->sat < satpf)) {
if ((satpf >= 0) && (wpt->sat < satpf)) {
del = true;
}

if ((fixnoneopt) && (waypointp->fix == fix_none)) {
if ((fixnoneopt) && (wpt->fix == fix_none)) {
del = true;
}

if ((fixunknownopt) && (waypointp->fix == fix_unknown)) {
if ((fixunknownopt) && (wpt->fix == fix_unknown)) {
del = true;
}

if ((eleminopt) && (waypointp->altitude < eleminpf)) {
if ((eleminopt) && (wpt->altitude < eleminpf)) {
del = true;
}

if ((elemaxopt) && (waypointp->altitude > elemaxpf)) {
if ((elemaxopt) && (wpt->altitude > elemaxpf)) {
del = true;
}

if (nameopt && name_regex.match(waypointp->shortname).hasMatch()) {
if (nameopt && name_regex.match(wpt->shortname).hasMatch()) {
del = true;
}
if (descopt && desc_regex.match(waypointp->description).hasMatch()) {
if (descopt && desc_regex.match(wpt->description).hasMatch()) {
del = true;
}
if (cmtopt && cmt_regex.match(waypointp->notes).hasMatch()) {
if (cmtopt && cmt_regex.match(wpt->notes).hasMatch()) {
del = true;
}
if (iconopt && icon_regex.match(waypointp->icon_descr).hasMatch()) {
if (iconopt && icon_regex.match(wpt->icon_descr).hasMatch()) {
del = true;
}

if (del) {
switch (what) {
case wptdata:
waypt_del(waypointp);
delete waypointp;
break;
case trkdata:
track_del_wpt(head, waypointp);
delete waypointp;
break;
case rtedata:
route_del_wpt(head, waypointp);
delete waypointp;
break;
default:
return;
}
}
}

void DiscardFilter::fix_process_head(const route_head* trk)
{
head = const_cast<route_head*>(trk);
const_cast<Waypoint*>(wpt)->extra_data = del? &delete_flag : nullptr;
}

void DiscardFilter::process()
{
WayptFunctor<DiscardFilter> fix_process_wpt_f(this, &DiscardFilter::fix_process_wpt);
RteHdFunctor<DiscardFilter> fix_process_head_f(this, &DiscardFilter::fix_process_head);
auto waypoint_cb_lambda = [this](const Waypoint* wpt) -> void {
fix_process_wpt(wpt);
};

// Filter waypoints.
what = wptdata;
waypt_disp_all(fix_process_wpt_f);
waypt_disp_all(waypoint_cb_lambda);
del_wpts(wpt_extra_data_evaluator);

// Filter tracks
what = trkdata;
track_disp_all(fix_process_head_f, nullptr, fix_process_wpt_f);
auto track_tlr_lambda = [](const route_head* rte)->void {
track_del_wpts(const_cast<route_head*>(rte), wpt_extra_data_evaluator);
};
track_disp_all(nullptr, track_tlr_lambda, waypoint_cb_lambda);

// And routes
what = rtedata;
route_disp_all(fix_process_head_f, nullptr, fix_process_wpt_f);

auto route_tlr_lambda = [](const route_head* rte)->void {
route_del_wpts(const_cast<route_head*>(rte), wpt_extra_data_evaluator);
};
route_disp_all(nullptr, route_tlr_lambda, waypoint_cb_lambda);
}

QRegularExpression DiscardFilter::generateRegExp(const QString& glob_pattern)
Expand Down
12 changes: 6 additions & 6 deletions discard.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ class DiscardFilter:public Filter
void process() override;

private:
/* Member Functions */

void fix_process_wpt(const Waypoint* wpt);
static QRegularExpression generateRegExp(const QString& glob_pattern);

private:
/* Data Members */

int delete_flag{}; // delete_flag != nullptr
char* hdopopt = nullptr;
char* vdopopt = nullptr;
char* andopt = nullptr;
Expand All @@ -66,8 +71,6 @@ class DiscardFilter:public Filter
int satpf{};
int eleminpf{};
int elemaxpf{};
gpsdata_type what{};
route_head* head{};

QVector<arglist_t> args = {
{
Expand Down Expand Up @@ -124,9 +127,6 @@ class DiscardFilter:public Filter
},
};

void fix_process_wpt(const Waypoint* wpt);
void fix_process_head(const route_head* trk);

};

#endif
Expand Down
Loading

0 comments on commit 3aa5485

Please sign in to comment.