Skip to content

Commit

Permalink
move floor to C++20 (#1206)
Browse files Browse the repository at this point in the history
* move floor to c++20

drop Visual Studio 2017.
use default member intializers for bit-fields.

* use more bit-field default initializers

* try Xcod 14.3.1 on macOS 13.

* echo clang version

which can be useful with homebrew fails_with

* use std::numbers

* finish eradication of M_PI.

* fix some whitespace
  • Loading branch information
tsteven4 authored Aug 9, 2024
1 parent c8f8709 commit be1168b
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 140 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include(CheckIncludeFile)
include(gbversion.cmake)
project(gpsbabel LANGUAGES C CXX VERSION ${GB.VERSION})

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# Do this after we set up common variables but before creating other
Expand Down
45 changes: 12 additions & 33 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#ifndef DEFS_H_INCLUDED_
#define DEFS_H_INCLUDED_

#include <cmath> // for M_PI
#include <cstddef> // for NULL, nullptr_t, size_t
#include <cstdint> // for int32_t, uint32_t
#include <cstdio> // for NULL, fprintf, FILE, stdout
Expand All @@ -36,7 +35,6 @@
#include <QString> // for QString
#include <QStringView> // for QStringView
#include <QTextCodec> // for QTextCodec
#include <QVector> // for QVector
#include <Qt> // for CaseInsensitive
#include <QtGlobal> // for QForeachContainer, qMakeForeachContainer, foreach, qint64

Expand All @@ -50,12 +48,6 @@
#define CSTR(qstr) ((qstr).toUtf8().constData())
#define CSTRc(qstr) ((qstr).toLatin1().constData())

/*
* Amazingly, this constant is not specified in the standard...
*/
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif

/*
* The constants marked "exact in decimal notation" may be more accurately
Expand Down Expand Up @@ -235,17 +227,11 @@ class UrlList : public QList<UrlLink>
class wp_flags
{
public:
wp_flags() :
shortname_is_synthetic(0),
fmt_use(0),
is_split(0),
new_trkseg(0),
marked_for_deletion(0) {}
unsigned int shortname_is_synthetic:1;
unsigned int fmt_use:2; /* lightweight "extra data" */
unsigned int is_split:1; /* the waypoint represents a split */
unsigned int new_trkseg:1; /* True if first in new trkseg. */
unsigned int marked_for_deletion:1; /* True if schedulded for deletion. */
unsigned int shortname_is_synthetic:1{0};
unsigned int fmt_use:2{0}; /* lightweight "extra data" */
unsigned int is_split:1{0}; /* the waypoint represents a split */
unsigned int new_trkseg:1{0}; /* True if first in new trkseg. */
unsigned int marked_for_deletion:1{0}; /* True if schedulded for deletion. */
};

/*
Expand Down Expand Up @@ -275,21 +261,14 @@ class Waypoint
class op_flags
{
public:
op_flags() :
temperature(false),
proximity(false),
course(false),
speed(false),
geoidheight(false),
depth(false) {}
bool temperature:1; /* temperature field is set */
bool proximity:1; /* proximity field is set */
bool course:1; /* course field is set */
bool speed:1; /* speed field is set */
bool geoidheight:1; /* geoidheight field is set */
bool depth:1; /* depth field is set */
bool temperature:1{false}; /* temperature field is set */
bool proximity:1{false}; /* proximity field is set */
bool course:1{false}; /* course field is set */
bool speed:1{false}; /* speed field is set */
bool geoidheight:1{false}; /* geoidheight field is set */
bool depth:1{false}; /* depth field is set */
/* !ToDo!
unsigned int altitude:1; /+ altitude field is set +/
unsigned int altitude:1{false}; /+ altitude field is set +/
... and hdop,pdop,vdop,fix,sat,heartrate,cadence,power,
odometer_distance
*/
Expand Down
2 changes: 1 addition & 1 deletion garmin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ GarminFormat::route_write()
for (int i = 0; i < n; i++) {
GPS_Way_Del(&tx_routelist[i]);
}

xfree(tx_routelist);
}

Expand Down
60 changes: 19 additions & 41 deletions garmin_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,48 +50,26 @@ struct garmin_ilink_t {

struct garmin_fs_flags_t {
public:
garmin_fs_flags_t() :
icon(0),
wpt_class(0),
display(0),
category(0),
city(0),
state(0),
facility(0),
cc(0),
cross_road(0),
addr(0),
country(0),
phone_nr(0),
phone_nr2(0),
fax_nr(0),
postal_code(0),
email(0),
duration(0)
#ifdef GMSD_EXPERIMENTAL
, subclass(0)
#endif
{}

unsigned int icon:1;
unsigned int wpt_class:1;
unsigned int display:1;
unsigned int category:1;
unsigned int city:1;
unsigned int state:1;
unsigned int facility:1;
unsigned int cc:1;
unsigned int cross_road:1;
unsigned int addr:1;
unsigned int country:1;
unsigned int phone_nr:1;
unsigned int phone_nr2:1;
unsigned int fax_nr:1;
unsigned int postal_code:1;
unsigned int email:1;
unsigned int duration:1;

unsigned int icon:1{0};
unsigned int wpt_class:1{0};
unsigned int display:1{0};
unsigned int category:1{0};
unsigned int city:1{0};
unsigned int state:1{0};
unsigned int facility:1{0};
unsigned int cc:1{0};
unsigned int cross_road:1{0};
unsigned int addr:1{0};
unsigned int country:1{0};
unsigned int phone_nr:1{0};
unsigned int phone_nr2:1{0};
unsigned int fax_nr:1{0};
unsigned int postal_code:1{0};
unsigned int email:1{0};
unsigned int duration:1{0};
#ifdef GMSD_EXPERIMENTAL
unsigned int subclass:1;
unsigned int subclass:1{0};
#endif
};

Expand Down
38 changes: 11 additions & 27 deletions geocache.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,6 @@ class Geocache
QString utf_string;
};

/* Special Member Functions */

Geocache() :
id(0),
type(type_t::gt_unknown),
container(container_t::gc_unknown),
diff(0),
terr(0),
is_archived(status_t::gs_unknown),
is_available(status_t::gs_unknown),
is_memberonly(status_t::gs_unknown),
has_customcoords(status_t::gs_unknown),
placer_id(0),
favorite_points(0)
{}

/* Member Functions */

void set_type(const QString& type_name);
Expand All @@ -105,22 +89,22 @@ class Geocache

/* Data Members */

long long id; /* The decimal cache number */
type_t type:5;
container_t container:4;
unsigned int diff:6; /* (multiplied by ten internally) */
unsigned int terr:6; /* (likewise) */
status_t is_archived:2;
status_t is_available:2;
status_t is_memberonly:2;
status_t has_customcoords:2;
long long id{0}; /* The decimal cache number */
type_t type:5{type_t::gt_unknown};
container_t container:4{container_t::gc_unknown};
unsigned int diff:6{0}; /* (multiplied by ten internally) */
unsigned int terr:6{0}; /* (likewise) */
status_t is_archived:2{status_t::gs_unknown};
status_t is_available:2{status_t::gs_unknown};
status_t is_memberonly:2{status_t::gs_unknown};
status_t has_customcoords:2{status_t::gs_unknown};
gpsbabel::DateTime last_found;
QString placer; /* Placer name */
int placer_id; /* Placer id */
int placer_id{0}; /* Placer id */
QString hint; /* all these UTF8, XML entities removed, May be not HTML. */
UtfString desc_short;
UtfString desc_long;
int favorite_points;
int favorite_points{0};
QString personal_note;

private:
Expand Down
2 changes: 1 addition & 1 deletion googletakeout.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class GoogleTakeoutFormat : public Format
};

/* Member Functions */

static void takeout_fatal(const QString& message);
static void takeout_warning(const QString& message);
static Waypoint* takeout_waypoint(int lat_e7, int lon_e7, const QString* shortname, const QString* description, const QString* start_str);
Expand Down
3 changes: 2 additions & 1 deletion grtcirc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <cerrno>
#include <cmath>
#include <cstdio>
#include <numbers>
#include <tuple>

static constexpr double EARTH_RAD = 6378137.0;
Expand Down Expand Up @@ -276,7 +277,7 @@ double linedistprj(double lat1, double lon1,
}
} else {
/* lp is 0 when 3 is 90 degrees from the great circle */
return M_PI / 2;
return std::numbers::pi / 2;
}
} else {
/* la is 0 when 1 and 2 are either the same point or 180 degrees apart */
Expand Down
4 changes: 3 additions & 1 deletion grtcirc.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef GRTCIRC_H
#define GRTCIRC_H

#include <numbers> // for inv_pi

double gcdist(double lat1, double lon1, double lat2, double lon2);
double heading(double lat1, double lon1, double lat2, double lon2);
double heading_true_degrees(double lat1, double lon1, double lat2, double lon2);
Expand All @@ -45,7 +47,7 @@ void linepart(double lat1, double lon1,
double* reslat, double* reslon);

/* Degrees to radians */
constexpr double kDegreesPerRadian = 180.0 / M_PI;
constexpr double kDegreesPerRadian = 180.0 * std::numbers::inv_pi;
constexpr double DEG(double x) { return x * kDegreesPerRadian; }

/* Radians to degrees */
Expand Down
19 changes: 10 additions & 9 deletions humminbird.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
#include <Qt> // for CaseInsensitive
#include <QtGlobal> // for qRound

#include <cmath> // for atan, tan, M_PI, log, sinh
#include <cmath> // for atan, tan, log, sinh
#include <cstdio> // for snprintf, SEEK_SET
#include <cstring> // for strncpy, memcpy, memset
#include <numbers> // for inv_pi, pi

#include "defs.h" // for Waypoint, be_read32, be_read16, be_write32, fatal, xfree, be_write16, route_head, xcalloc, track_add_wpt, xstrndup
#include "mkshort.h" // for MakeShort
Expand Down Expand Up @@ -61,7 +62,7 @@ Still, they're useful in the code as a plain signature.
#define WPT_MAGIC2 0x02030024L // New for 2013. No visible diff?!
#define RTE_MAGIC 0x03030088L

#define EAST_SCALE 20038297.0 /* this is i1924_equ_axis*M_PI */
#define EAST_SCALE 20038297.0 /* this is i1924_equ_axis*pi */
#define i1924_equ_axis 6378388.0
#define i1924_polar_axis 6356911.946

Expand Down Expand Up @@ -173,9 +174,9 @@ HumminbirdBase::geodetic_to_geocentric_hwr(const double gd_lat)
{
constexpr double cos_ae = 0.9966349016452;
constexpr double cos2_ae = cos_ae * cos_ae;
const double gdr = gd_lat *M_PI / 180.0;
const double gdr = gd_lat * std::numbers::pi / 180.0;

return atan(cos2_ae * tan(gdr)) * 180.0/M_PI;
return atan(cos2_ae * tan(gdr)) * 180.0 * std::numbers::inv_pi;
}

/* Takes a latitude in degrees,
Expand All @@ -185,9 +186,9 @@ HumminbirdBase::geocentric_to_geodetic_hwr(const double gc_lat)
{
constexpr double cos_ae = 0.9966349016452;
constexpr double cos2_ae = cos_ae * cos_ae;
const double gcr = gc_lat *M_PI / 180.0;
const double gcr = gc_lat * std::numbers::pi / 180.0;

return atan(tan(gcr)/cos2_ae) * 180.0/M_PI;
return atan(tan(gcr)/cos2_ae) * 180.0 * std::numbers::inv_pi;
}

/* Takes a projected "north" value, returns latitude in degrees. */
Expand All @@ -196,15 +197,15 @@ HumminbirdBase::gudermannian_i1924(const double x)
{
const double norm_x = x/i1924_equ_axis;

return atan(sinh(norm_x)) * 180.0/M_PI;
return atan(sinh(norm_x)) * 180.0 * std::numbers::inv_pi;
}

/* Takes latitude in degrees, returns projected "north" value. */
double
HumminbirdBase::inverse_gudermannian_i1924(const double x)
{
const double x_r = x/180.0 * M_PI;
const double guder = log(tan(M_PI/4.0 + x_r/2.0));
const double x_r = x/180.0 * std::numbers::pi;
const double guder = log(tan(std::numbers::pi/4.0 + x_r/2.0));

return guder * i1924_equ_axis;
}
Expand Down
3 changes: 2 additions & 1 deletion jeeps/gpsmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

#include <cstdint> // for int32_t
#include <ctime> // for time_t
#include <numbers> // for pi

#include <QString> // for QString


constexpr double GPS_PI = 3.14159265358979323846;
constexpr double GPS_PI = std::numbers::pi;


double GPS_Math_Deg_To_Rad(double v);
Expand Down
7 changes: 4 additions & 3 deletions lowranceusr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@
#include "lowranceusr.h"

#include <cinttypes> // for PRId64
#include <cmath> // for M_PI, round, atan, exp, log, tan
#include <cmath> // for round, atan, exp, log, tan
#include <cstdio> // for printf, sprintf, SEEK_CUR
#include <cstdint> // for int64_t
#include <cstdlib> // for abs
#include <cstring> // for strcmp, strlen
#include <numbers> // for pi
#include <utility> // for as_const

#include <QByteArray> // for QByteArray
Expand Down Expand Up @@ -377,7 +378,7 @@ LowranceusrFormat::lon_mm_to_deg(double x)
double
LowranceusrFormat::lat_mm_to_deg(double x)
{
return (2.0 * atan(exp(x / SEMIMINOR)) - M_PI / 2.0) / DEGREESTORADIANS;
return (2.0 * atan(exp(x / SEMIMINOR)) - std::numbers::pi / 2.0) / DEGREESTORADIANS;
}

long
Expand All @@ -389,7 +390,7 @@ LowranceusrFormat::lon_deg_to_mm(double x)
long
LowranceusrFormat::lat_deg_to_mm(double x)
{
return round(SEMIMINOR * log(tan((x * DEGREESTORADIANS + M_PI / 2.0) / 2.0)));
return round(SEMIMINOR * log(tan((x * DEGREESTORADIANS + std::numbers::pi / 2.0) / 2.0)));
}

void
Expand Down
5 changes: 3 additions & 2 deletions lowranceusr.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@
#ifndef LOWRANCEUSR_H_INCLUDED_
#define LOWRANCEUSR_H_INCLUDED_

#include <cmath> // for M_PI, round, atan, exp, log, tan
#include <cmath> // for round, atan, exp, log, tan
#include <cstdint> // for int64_t
#include <numbers> // for pi

#include <QList> // for QList
#include <QString> // for QString
Expand Down Expand Up @@ -378,7 +379,7 @@ class LowranceusrFormat : public Format

static constexpr int MAXUSRSTRINGSIZE = 256;
static constexpr double SEMIMINOR = 6356752.3142;
static constexpr double DEGREESTORADIANS = M_PI/180.0;
static constexpr double DEGREESTORADIANS = std::numbers::pi/180.0;
static constexpr int MAX_TRAIL_POINTS = 9999;
static constexpr double UNKNOWN_USR_ALTITUDE = METERS_TO_FEET(-10000); /* -10000ft is how the unit stores unknown */
static constexpr int64_t base_time_secs = 946706400; /* Jan 1, 2000 00:00:00 */
Expand Down
Loading

0 comments on commit be1168b

Please sign in to comment.