Skip to content

Commit

Permalink
Make geocache a real class. (GPSBabel#968)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteven4 authored Jan 2, 2023
1 parent 1a38301 commit 70e7f1a
Show file tree
Hide file tree
Showing 24 changed files with 644 additions and 550 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ set(ALL_FMTS ${MINIMAL_FMTS}
garmin_txt.cc
garmin_xt.cc
gdb.cc
geocache.cc
geojson.cc
globalsat_sport.cc
gpssim.cc
Expand Down Expand Up @@ -221,6 +222,7 @@ set(HEADERS
gbser.h
gbser_private.h
gdb.h
geocache.h
geojson.h
globalsat_sport.h
gpx.h
Expand Down
102 changes: 5 additions & 97 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <Qt> // for CaseInsensitive
#include <QtGlobal> // for QForeachContainer, qMakeForeachContainer, foreach, qint64

#include "geocache.h" // for Geocache
#include "formspec.h" // for FormatSpecificData
#include "inifile.h" // for inifile_t
#include "session.h" // for session_t
Expand Down Expand Up @@ -198,93 +199,6 @@ enum fix_type {
fix_pps
};

enum status_type {
status_unknown=0,
status_true,
status_false
};

/*
* Extended data if waypoint happens to represent a geocache. This is
* totally voluntary data...
*/

enum geocache_type {
gt_unknown = 0,
gt_traditional,
gt_multi,
gt_virtual,
gt_letterbox,
gt_event,
gt_surprise,
gt_webcam,
gt_earth,
gt_locationless,
gt_benchmark, /* Extension to Groundspeak for GSAK */
gt_cito,
gt_ape,
gt_mega,
gt_wherigo
};

enum geocache_container {
gc_unknown = 0,
gc_micro,
gc_other,
gc_regular,
gc_large,
gc_virtual,
gc_small
};

class utf_string
{
public:
utf_string() = default;
utf_string(bool html, QString str) :
is_html{html},
utfstring{std::move(str)}
{}
bool is_html{false};
QString utfstring;
};

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

class gb_color
{
public:
Expand Down Expand Up @@ -422,7 +336,7 @@ struct bounds {
class Waypoint
{
private:
static geocache_data empty_gc_data;
static Geocache empty_gc_data;

public:

Expand Down Expand Up @@ -501,7 +415,7 @@ class Waypoint
float power; /* watts, as measured by cyclists */
float temperature; /* Degrees celsius */
float odometer_distance; /* Meters */
geocache_data* gc_data;
Geocache* gc_data;
FormatSpecificDataList fs;
const session_t* session; /* pointer to a session struct */
void* extra_data; /* Extra data added by, say, a filter. */
Expand All @@ -519,7 +433,7 @@ class Waypoint
gpsbabel::DateTime GetCreationTime() const;
void SetCreationTime(const gpsbabel::DateTime& t);
void SetCreationTime(qint64 t, qint64 ms = 0);
geocache_data* AllocGCData();
Geocache* AllocGCData();
int EmptyGCData() const;
};

Expand Down Expand Up @@ -893,9 +807,6 @@ using ff_exit = void (*)();
using ff_writeposn = void (*)(Waypoint*);
using ff_readposn = Waypoint* (*)(posn_status*);

geocache_type gs_mktype(const QString& t);
geocache_container gs_mkcont(const QString& t);

/*
* All shortname functions take a shortname handle as the first arg.
* This is an opaque pointer. Callers must not fondle the contents of it.
Expand Down Expand Up @@ -1072,10 +983,7 @@ time_t mkgmtime(struct tm* t);
bool gpsbabel_testmode();
gpsbabel::DateTime current_time();
QDateTime dotnet_time_to_qdatetime(long long dotnet);
QString get_cache_icon(const Waypoint* waypointp);
QString gs_get_cachetype(geocache_type t);
QString gs_get_container(geocache_container t);
QString strip_html(const utf_string*);
QString strip_html(const QString& utfstring);
QString strip_nastyhtml(const QString& in);
QString convert_human_date_format(const char* human_datef); /* "MM,YYYY,DD" -> "%m,%Y,%d" */
QString convert_human_time_format(const char* human_timef); /* "HH+mm+ss" -> "%H+%M+%S" */
Expand Down
15 changes: 8 additions & 7 deletions duplicate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
*/

#include <algorithm> // for stable_sort
#include <cstdio> // for snprintf
#include <cstring> // for memset, strncpy
#include "duplicate.h"

#include <algorithm> // for stable_sort
#include <cstdio> // for snprintf
#include <cstring> // for memset, strncpy

#include <QDateTime> // for QDateTime
#include <QtGlobal> // for foreach
#include <QDateTime> // for QDateTime

#include "defs.h"
#include "duplicate.h"
#include "src/core/datetime.h" // for DateTime
#include "geocache.h" // for Geocache
#include "src/core/datetime.h" // for DateTime


#if FILTERS_ENABLED
Expand Down
3 changes: 2 additions & 1 deletion duplicate.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
#ifndef DUPLICATE_H_INCLUDED_
#define DUPLICATE_H_INCLUDED_

#include <QVector> // for QVector
#include <QString> // for QString
#include <QVector> // for QVector

#include "defs.h" // for ARGTYPE_BOOL, ARG_NOMINMAX, Waypoint (ptr only)
#include "filter.h" // for Filter
Expand Down
76 changes: 43 additions & 33 deletions garmin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,42 @@
*/

#include <cctype> // for isalpha, toupper
#include <climits> // for INT_MAX
#include <cmath> // for atan2, floor, sqrt
#include <csetjmp> // for setjmp
#include <cstdio> // for fprintf, fflush, snprintf, snprintf
#include <cstdlib> // for strtol
#include <cstring> // for memcpy, strlen, strncpy, strchr
#include <ctime> // for time_t

#include <QByteArray> // for QByteArray
#include <QChar> // for QChar
#include <QString> // for QString
#include <Qt> // for CaseInsensitive
#include <QtGlobal> // for qPrintable, foreach
#include <cctype> // for isalpha, toupper
#include <climits> // for INT_MAX
#include <cmath> // for atan2, floor, sqrt
#include <csetjmp> // for setjmp
#include <cstdio> // for fprintf, fflush, snprintf, snprintf
#include <cstdlib> // for strtol
#include <cstring> // for memcpy, strlen, strncpy, strchr
#include <ctime> // for time_t

#include <QByteArray> // for QByteArray
#include <QChar> // for QChar
#include <QString> // for QString
#include <QVector> // for QVector
#include <Qt> // for CaseInsensitive
#include <QtGlobal> // for qPrintable, foreach

#include "defs.h"
#include "cet_util.h" // for cet_convert_init, cet_cs_vec_utf8
#include "format.h" // for Format
#include "garmin_device_xml.h" // for gdx_get_info, gdx_info, gdx_file, gdx_jmp_buf
#include "garmin_fs.h" // for garmin_fs_garmin_after_read, garmin_fs_garmin_before_write
#include "garmin_tables.h" // for gt_find_icon_number_from_desc, PCX, gt_find_desc_from_icon_number
#include "grtcirc.h" // for DEG
#include "jeeps/gps.h"
#include "jeeps/gpsserial.h"
#include "src/core/datetime.h" // for DateTime
#include "vecs.h" // for Vecs
#include "cet_util.h" // for cet_convert_init, cet_cs_vec_utf8
#include "format.h" // for Format
#include "garmin_device_xml.h" // for gdx_get_info, gdx_info, gdx_file, gdx_jmp_buf
#include "garmin_fs.h" // for garmin_fs_garmin_after_read, garmin_fs_garmin_before_write
#include "garmin_tables.h" // for gt_find_icon_number_from_desc, PCX, gt_find_desc_from_icon_number
#include "geocache.h" // for Geocache, Geocache::type_t, Geocache...
#include "grtcirc.h" // for DEG
#include "jeeps/gpsapp.h" // for GPS_Set_Baud_Rate, GPS_Init, GPS_Pre...
#include "jeeps/gpscom.h" // for GPS_Command_Get_Lap, GPS_Command_Get...
#include "jeeps/gpsdevice.h" // for gpsdevh
#include "jeeps/gpsmem.h" // for GPS_Track_Del, GPS_Way_Del, GPS_Pvt_Del
#include "jeeps/gpsport.h" // for int32
#include "jeeps/gpsprot.h" // for gps_waypt_type, gps_category_type
#include "jeeps/gpssend.h" // for GPS_SWay, GPS_PWay, GPS_STrack, GPS_...
#include "jeeps/gpsserial.h" // for DEFAULT_BAUD
#include "jeeps/gpsutil.h" // for GPS_User, GPS_Enable_Diagnose, GPS_E...
#include "src/core/datetime.h" // for DateTime
#include "vecs.h" // for Vecs


#define MYNAME "GARMIN"
static const char* portname;
Expand Down Expand Up @@ -798,25 +808,25 @@ static const char*
get_gc_info(const Waypoint* wpt)
{
if (global_opts.smart_names) {
if (wpt->gc_data->type == gt_virtual) {
if (wpt->gc_data->type == Geocache::type_t::gt_virtual) {
return "V ";
}
if (wpt->gc_data->type == gt_unknown) {
if (wpt->gc_data->type == Geocache::type_t::gt_unknown) {
return "? ";
}
if (wpt->gc_data->type == gt_multi) {
if (wpt->gc_data->type == Geocache::type_t::gt_multi) {
return "Mlt ";
}
if (wpt->gc_data->type == gt_earth) {
if (wpt->gc_data->type == Geocache::type_t::gt_earth) {
return "EC ";
}
if (wpt->gc_data->type == gt_event) {
if (wpt->gc_data->type == Geocache::type_t::gt_event) {
return "Ev ";
}
if (wpt->gc_data->container == gc_micro) {
if (wpt->gc_data->container == Geocache::container_t::gc_micro) {
return "M ";
}
if (wpt->gc_data->container == gc_small) {
if (wpt->gc_data->container == Geocache::container_t::gc_small) {
return "S ";
}
}
Expand Down Expand Up @@ -895,8 +905,8 @@ waypoint_prepare()
if (deficon) {
icon = gt_find_icon_number_from_desc(deficon, PCX);
} else {
if (!get_cache_icon(wpt).isEmpty()) {
icon = gt_find_icon_number_from_desc(get_cache_icon(wpt), PCX);
if (!wpt->gc_data->get_icon().isEmpty()) {
icon = gt_find_icon_number_from_desc(wpt->gc_data->get_icon(), PCX);
} else {
icon = gt_find_icon_number_from_desc(wpt->icon_descr, PCX);
}
Expand Down
Loading

0 comments on commit 70e7f1a

Please sign in to comment.