Skip to content

Commit

Permalink
Eliminiate redundant route_head data member (GPSBabel#764)
Browse files Browse the repository at this point in the history
eliminate redundant route_head data member rte_waypt_ct, replacing it with a member function rte_waypt_ct() that gets the count from the waypoint_list container.
  • Loading branch information
tsteven4 authored Nov 17, 2021
1 parent 0beebdd commit 2504d97
Show file tree
Hide file tree
Showing 29 changed files with 70 additions and 73 deletions.
2 changes: 1 addition & 1 deletion bcr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ bcr_data_read()
}

/* remove empty route */
if (route->rte_waypt_ct == 0) {
if (route->rte_waypt_ct() == 0) {
route_del_head(route);
} else {
bcr_create_waypts_from_route(route);
Expand Down
3 changes: 2 additions & 1 deletion defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,6 @@ class route_head
QString rte_desc;
UrlList rte_urls;
int rte_num;
int rte_waypt_ct; /* # waypoints in waypoint list */
FormatSpecificDataList fs;
gb_color line_color; /* Optional line color for rendering */
int line_width; /* in pixels (sigh). < 0 is unknown. */
Expand All @@ -716,6 +715,8 @@ class route_head
route_head(const route_head& other) = delete;
route_head& operator=(const route_head& rhs) = delete;
~route_head();

int rte_waypt_ct() const {return waypoint_list.count();} /* # waypoints in waypoint list */
};

using route_hdr = void (*)(const route_head*);
Expand Down
4 changes: 2 additions & 2 deletions garmin_txt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ route_disp_hdr_cb(const route_head* rte)
cur_info = &route_info[route_idx];
cur_info->prev_wpt = nullptr;
cur_info->total = 0;
if (rte->rte_waypt_ct <= 0) {
if (rte->rte_waypt_ct() <= 0) {
return;
}

Expand Down Expand Up @@ -675,7 +675,7 @@ track_disp_hdr_cb(const route_head* track)
cur_info = &route_info[route_idx];
cur_info->prev_wpt = nullptr;
cur_info->total = 0;
if (track->rte_waypt_ct <= 0) {
if (track->rte_waypt_ct() <= 0) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion gdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static int trk_ct; /* informational: total number of tracks in/out */

/*******************************************************************************/

#define ELEMENTS(a) a->rte_waypt_ct
#define ELEMENTS(a) a->rte_waypt_ct()
#define NOT_EMPTY(a) (a && *a)

static void
Expand Down
4 changes: 2 additions & 2 deletions ggv_ovl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ waypt_disp_cb(const Waypoint* wpt)
static void
track_disp_cb(const route_head* trk)
{
int waypt_ct = trk->rte_waypt_ct;
int waypt_ct = trk->rte_waypt_ct();

if (waypt_ct <= 0) {
return;
Expand Down Expand Up @@ -294,7 +294,7 @@ track_disp_cb(const route_head* trk)
static void
route_disp_cb(const route_head* rte)
{
int waypt_ct = rte->rte_waypt_ct;
int waypt_ct = rte->rte_waypt_ct();

if (waypt_ct <= 0) {
return;
Expand Down
4 changes: 2 additions & 2 deletions gtm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ gtm_rd_deinit()

static void count_track_styles(const route_head* rte)
{
if (rte->rte_waypt_ct > 0) {
if (rte->rte_waypt_ct() > 0) {
ts_count++;
}
}
Expand Down Expand Up @@ -670,7 +670,7 @@ static void write_trk_waypt(const Waypoint* wpt)

static void write_trk_style(const route_head* trk)
{
if (trk->rte_waypt_ct > 0) {
if (trk->rte_waypt_ct() > 0) {
fwrite_string(file_out, trk->rte_name);
fwrite_byte(file_out, 1);
fwrite_long(file_out, 0);
Expand Down
4 changes: 2 additions & 2 deletions humminbird.cc
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ humminbird_track_head(const route_head* trk)

trk_head = nullptr;
last_time = 0;
if (trk->rte_waypt_ct > 0) {
if (trk->rte_waypt_ct() > 0) {
trk_head = (humminbird_trk_header_t*) xcalloc(1, sizeof(humminbird_trk_header_t));
trk_points = (humminbird_trk_point_t*) xcalloc(max_points, sizeof(humminbird_trk_point_t));

Expand Down Expand Up @@ -852,7 +852,7 @@ static void
humminbird_rte_head(const route_head* rte)
{
humrte = nullptr;
if (rte->rte_waypt_ct > 0) {
if (rte->rte_waypt_ct() > 0) {
humrte = (humminbird_rte_t*) xcalloc(1, sizeof(*humrte));
}
}
Expand Down
6 changes: 3 additions & 3 deletions igc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,12 @@ static void detect_other_track(const route_head* rh)
max_waypt_ct = 0;
}
// Find other track with the most waypoints
if (rh->rte_waypt_ct > max_waypt_ct &&
if (rh->rte_waypt_ct() > max_waypt_ct &&
(rh->rte_name.isEmpty() ||
(!rh->rte_name.startsWith(PRESTRKNAME) &&
!rh->rte_name.startsWith(GNSSTRKNAME)))) {
head = rh;
max_waypt_ct = rh->rte_waypt_ct;
max_waypt_ct = rh->rte_waypt_ct();
}
}

Expand Down Expand Up @@ -651,7 +651,7 @@ static void wr_task_hdr(const route_head* rte)
unsigned char have_takeoff = 0;
char flight_date[7] = "000000";
char task_desc[MAXRECLEN] = "";
int num_tps = rte->rte_waypt_ct - 2;
int num_tps = rte->rte_waypt_ct() - 2;
struct tm* tm;
time_t rte_time;
static unsigned int task_num = 1;
Expand Down
2 changes: 1 addition & 1 deletion ignrando.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ ignr_write_track_hdr(const route_head* track_hdr)
}

gbfprintf(fout, "\t<INFORMATIONS>\n");
gbfprintf(fout, "\t\t<NB_ETAPES>%d</NB_ETAPES>\n", track_hdr->rte_waypt_ct);
gbfprintf(fout, "\t\t<NB_ETAPES>%d</NB_ETAPES>\n", track_hdr->rte_waypt_ct());
if (!track_hdr->rte_desc.isEmpty()) {
gbfprintf(fout, "\t\t<DESCRIPTION>%s</DESCRIPTION>\n", STRFROMUNICODE(track_hdr->rte_desc));
}
Expand Down
20 changes: 10 additions & 10 deletions kml.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,12 @@ void KmlFormat::trk_coord(xg_string args, const QXmlStreamAttributes* /*attrs*/)
if (wpt_timespan_begin.isValid() && wpt_timespan_end.isValid()) {

// If there are some Waypoints, then distribute the TimeSpan to all Waypoints
if (trk_head->rte_waypt_ct > 0) {
if (trk_head->rte_waypt_ct() > 0) {
qint64 timespan_ms = wpt_timespan_begin.msecsTo(wpt_timespan_end);
if (trk_head->rte_waypt_ct < 2) {
if (trk_head->rte_waypt_ct() < 2) {
fatal(MYNAME ": attempt to interpolate TimeSpan with too few points.");
}
qint64 ms_per_waypoint = timespan_ms / (trk_head->rte_waypt_ct - 1);
qint64 ms_per_waypoint = timespan_ms / (trk_head->rte_waypt_ct() - 1);
foreach (Waypoint* trackpoint, trk_head->waypoint_list) {
trackpoint->SetCreationTime(wpt_timespan_begin);
wpt_timespan_begin = wpt_timespan_begin.addMSecs(ms_per_waypoint);
Expand Down Expand Up @@ -315,7 +315,7 @@ void KmlFormat::gx_trk_e(xg_string /*args*/, const QXmlStreamAttributes* /*attrs
}
}

if (!gx_trk_head->rte_waypt_ct) {
if (!gx_trk_head->rte_waypt_ct()) {
track_del_head(gx_trk_head);
}
delete gx_trk_times;
Expand Down Expand Up @@ -662,7 +662,7 @@ void KmlFormat::kml_output_header(const route_head* header, const computed_trkda
writer->writeOptionalTextElement(QStringLiteral("name"), header->rte_name);
kml_output_trkdescription(header, td);

if (export_points && header->rte_waypt_ct > 0) {
if (export_points && header->rte_waypt_ct() > 0) {
// Put the points in a subfolder
writer->writeStartElement(QStringLiteral("Folder"));
writer->writeTextElement(QStringLiteral("name"), QStringLiteral("Points"));
Expand Down Expand Up @@ -880,12 +880,12 @@ void KmlFormat::kml_output_point(const Waypoint* waypointp, kml_point_type pt_ty
void KmlFormat::kml_output_tailer(const route_head* header)
{

if (export_points && header->rte_waypt_ct > 0) {
if (export_points && header->rte_waypt_ct() > 0) {
writer->writeEndElement(); // Close Folder tag
}

// Add a linestring for this track?
if (export_lines && header->rte_waypt_ct > 0) {
if (export_lines && header->rte_waypt_ct() > 0) {
int needs_multigeometry = 0;

foreach (const Waypoint* tpt, header->waypoint_list) {
Expand Down Expand Up @@ -1459,7 +1459,7 @@ void KmlFormat::kml_waypt_pr(const Waypoint* waypointp) const
void KmlFormat::kml_track_hdr(const route_head* header) const
{
computed_trkdata td = track_recompute(header);
if (header->rte_waypt_ct > 0 && (export_lines || export_points)) {
if (header->rte_waypt_ct() > 0 && (export_lines || export_points)) {
kml_output_header(header, &td);
}
}
Expand All @@ -1471,7 +1471,7 @@ void KmlFormat::kml_track_disp(const Waypoint* waypointp) const

void KmlFormat::kml_track_tlr(const route_head* header)
{
if (header->rte_waypt_ct > 0 && (export_lines || export_points)) {
if (header->rte_waypt_ct() > 0 && (export_lines || export_points)) {
kml_output_tailer(header);
}
}
Expand Down Expand Up @@ -2002,7 +2002,7 @@ void KmlFormat::wr_position(Waypoint* wpt)
* head here.
*/
while (max_position_points &&
(posn_trk_head->rte_waypt_ct >= max_position_points)) {
(posn_trk_head->rte_waypt_ct() >= max_position_points)) {
Waypoint* tonuke = posn_trk_head->waypoint_list.front();
track_del_wpt(posn_trk_head, tonuke);
}
Expand Down
14 changes: 7 additions & 7 deletions lowranceusr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,7 @@ LowranceusrFormat::lowranceusr_trail_hdr(const route_head* trk)
gbfputint32(text_len, file_out);
gbfwrite(CSTR(name), 1, text_len, file_out);

auto num_trail_points = (short) trk->rte_waypt_ct;
auto num_trail_points = (short) trk->rte_waypt_ct();
short max_trail_size = MAX_TRAIL_POINTS;
if (num_trail_points > max_trail_size) {
num_trail_points = max_trail_size;
Expand Down Expand Up @@ -1602,7 +1602,7 @@ LowranceusrFormat::lowranceusr_route_hdr(const route_head* rte)
gbfputs(name, file_out);

/* num legs */
auto num_legs = (short) rte->rte_waypt_ct;
auto num_legs = (short) rte->rte_waypt_ct();
gbfputint16(num_legs, file_out);
char route_reversed=0;
gbfwrite(&route_reversed, 1, 1, file_out);
Expand All @@ -1617,7 +1617,7 @@ LowranceusrFormat::lowranceusr4_route_hdr(const route_head* rte)
{
if (global_opts.debug_level >= 1) {
printf(MYNAME " writing route #%d (%s) with %d waypts\n",
route_uid, qPrintable(rte->rte_name), rte->rte_waypt_ct);
route_uid, qPrintable(rte->rte_name), rte->rte_waypt_ct());
}

const auto* fs = reinterpret_cast<lowranceusr4_fsdata*>(rte->fs.FsChainFind(kFsLowranceusr4));
Expand All @@ -1642,7 +1642,7 @@ LowranceusrFormat::lowranceusr4_route_hdr(const route_head* rte)
lowranceusr4_writestr(rte->rte_name, file_out, 2);

/* Num Legs */
gbfputint32(rte->rte_waypt_ct, file_out);
gbfputint32(rte->rte_waypt_ct(), file_out);
}

void
Expand Down Expand Up @@ -1720,7 +1720,7 @@ LowranceusrFormat::lowranceusr_merge_trail_hdr(const route_head* trk)
}
}

trail_point_count += (short) trk->rte_waypt_ct;
trail_point_count += (short) trk->rte_waypt_ct();
}

void
Expand Down Expand Up @@ -1756,7 +1756,7 @@ LowranceusrFormat::lowranceusr4_trail_hdr(const route_head* trail)
{
if (global_opts.debug_level >= 1) {
printf(MYNAME " writing trail %d (%s) with %d trailpoints\n",
trail_uid, qPrintable(trail->rte_name), trail->rte_waypt_ct);
trail_uid, qPrintable(trail->rte_name), trail->rte_waypt_ct());
}

/* UID unit number */
Expand Down Expand Up @@ -1803,7 +1803,7 @@ LowranceusrFormat::lowranceusr4_trail_hdr(const route_head* trail)
// }

/* Trackpoint count */
gbfputint32(trail->rte_waypt_ct, file_out);
gbfputint32(trail->rte_waypt_ct(), file_out);
}

void
Expand Down
2 changes: 1 addition & 1 deletion magproto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@ mag_route_trl(const route_head* rte)
QString icon_token;

/* count waypoints for this route */
int i = rte->rte_waypt_ct;
int i = rte->rte_waypt_ct();

/* number of output PMGNRTE messages at 2 points per line */
int numlines = (i / 2) + (i % 2);
Expand Down
2 changes: 1 addition & 1 deletion mapsend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ mapsend_route_hdr(const route_head* rte)
gbfputint32(rte->rte_num, mapsend_file_out);

/* # of waypoints to follow... */
gbfputint32(rte->rte_waypt_ct, mapsend_file_out);
gbfputint32(rte->rte_waypt_ct(), mapsend_file_out);
}

static void
Expand Down
20 changes: 10 additions & 10 deletions mmo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ mmo_end_of_route(mmo_data_t* data)
DBG((sobj, "for \"%s\" \n", data->name));
}

if (rte->rte_waypt_ct == 0) { /* don't keep empty routes */
if (rte->rte_waypt_ct() == 0) { /* don't keep empty routes */
route_del_head(rte);
data->data = nullptr;
}
Expand Down Expand Up @@ -721,7 +721,7 @@ mmo_read_CObjTrack(mmo_data_t* data)
}
}

if (trk->rte_waypt_ct == 0) {
if (trk->rte_waypt_ct() == 0) {
track_del_head(trk);
data->data = nullptr;
}
Expand Down Expand Up @@ -1127,7 +1127,7 @@ mmo_enum_waypt_cb(const Waypoint*)
static void
mmo_enum_route_cb(const route_head* rte)
{
if (rte->rte_waypt_ct > 0) {
if (rte->rte_waypt_ct() > 0) {
mmo_obj_ct++;
}
}
Expand Down Expand Up @@ -1293,7 +1293,7 @@ mmo_write_rte_head_cb(const route_head* rte)
{
time_t time = 0x7FFFFFFF;

if (rte->rte_waypt_ct <= 0) {
if (rte->rte_waypt_ct() <= 0) {
return;
}

Expand All @@ -1313,18 +1313,18 @@ mmo_write_rte_head_cb(const route_head* rte)
mmo_register_object(objid, rte, rtedata);
mmo_write_category("CCategory", "Route");
gbfputc(0, fout); /* unknown */
gbfputuint16(rte->rte_waypt_ct, fout);
gbfputuint16(rte->rte_waypt_ct(), fout);
}


static void
mmo_write_rte_tail_cb(const route_head* rte)
{
if (rte->rte_waypt_ct <= 0) {
if (rte->rte_waypt_ct() <= 0) {
return;
}

DBG(("write", "route with %d point(s).\n", rte->rte_waypt_ct));
DBG(("write", "route with %d point(s).\n", rte->rte_waypt_ct()));

if (mmo_version >= 0x12) {
if (rte->line_color.bbggrr < 0) {
Expand All @@ -1350,14 +1350,14 @@ mmo_write_rte_tail_cb(const route_head* rte)
static void
mmo_write_trk_head_cb(const route_head* trk)
{
if (trk->rte_waypt_ct <= 0) {
if (trk->rte_waypt_ct() <= 0) {
return;
}
int objid = mmo_write_obj_head("CObjTrack",
trk->rte_name.isEmpty() ? "Track" : CSTR(trk->rte_name), gpsbabel_time, obj_type_trk);

mmo_write_category("CCategory", "Track");
gbfputuint16(trk->rte_waypt_ct, fout);
gbfputuint16(trk->rte_waypt_ct(), fout);

mmo_register_object(objid, trk, trkdata);
}
Expand All @@ -1366,7 +1366,7 @@ mmo_write_trk_head_cb(const route_head* trk)
static void
mmo_write_trk_tail_cb(const route_head* trk)
{
if (trk->rte_waypt_ct <= 0) {
if (trk->rte_waypt_ct() <= 0) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion navilink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ serial_read_routes(Waypoint** waypts)
static void
serial_write_route_start(const route_head* route)
{
route_ids = (unsigned int*) xmalloc(route->rte_waypt_ct * sizeof(unsigned));
route_ids = (unsigned int*) xmalloc(route->rte_waypt_ct() * sizeof(unsigned));
route_id_ptr = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion osm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ OsmFormat::osm_waypt_disp(const Waypoint* waypoint)
void
OsmFormat::osm_rte_disp_head(const route_head* route)
{
skip_rte = route->rte_waypt_ct <= 0;
skip_rte = route->rte_waypt_ct() <= 0;

if (skip_rte) {
return;
Expand Down
Loading

0 comments on commit 2504d97

Please sign in to comment.