[gnome-maps/wip/mlundblad/transit-plugin-gtfs-local: 1/3] WIP: Add class representing a stop time in a GTFS feed
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/transit-plugin-gtfs-local: 1/3] WIP: Add class representing a stop time in a GTFS feed
- Date: Mon, 2 Mar 2020 21:40:39 +0000 (UTC)
commit 6d02ab75746ac280c7df13bfe1633563b2eed8d2
Author: Marcus Lundblad <ml update uu se>
Date: Sat Feb 29 22:12:43 2020 +0100
WIP: Add class representing a stop time in a GTFS feed
lib/maps-gtfs-stop-time.c | 189 ++++++++++++++++++++++++++++++++++++++++++++++
lib/maps-gtfs-stop-time.h | 53 +++++++++++++
lib/maps-gtfs-trip.c | 66 ++++++++++++----
lib/maps.h | 1 +
lib/meson.build | 2 +
5 files changed, 295 insertions(+), 16 deletions(-)
---
diff --git a/lib/maps-gtfs-stop-time.c b/lib/maps-gtfs-stop-time.c
new file mode 100644
index 00000000..9ea75408
--- /dev/null
+++ b/lib/maps-gtfs-stop-time.c
@@ -0,0 +1,189 @@
+/*
+ * Copyright (c) 2020 Marcus Lundblad
+ *
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, see <http://www.gnu.org/licenses/>
+ *
+ * Author: Marcus Lundblad <ml update uu se>
+ */
+
+#include "maps-gtfs-stop-time.h"
+#include "maps-enum-types.h"
+
+#include <math.h>
+
+struct _MapsGTFSStopTime
+{
+ GObject parent_instance;
+};
+
+typedef struct
+{
+ guint32 arrival_time:24;
+ guint16 departure_time_diff;
+ guint16 stop_sequence;
+ gchar *stop_headsign;
+ MapsGTFSStopTimePickupDropOffType pickup_type:2;
+ MapsGTFSStopTimePickupDropOffType drop_off_type:2;
+ gfloat shape_dist_travelled;
+} MapsGTFSStopTimePrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (MapsGTFSStopTime, maps_gtfs_stop_time, G_TYPE_OBJECT)
+
+enum {
+ PROP_0,
+ PROP_ARRIVAL_TIME,
+ PROP_DEPARTURE_TIME,
+ PROP_STOP_SEQUENCE,
+ PROP_STOP_HEADSIGN,
+ PROP_PICKUP_TYPE,
+ PROP_DROP_OFF_TYPE,
+ PROP_SHAPE_DIST_TRAVELLED,
+ N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+MapsGTFSStopTime *
+maps_gtfs_stop_time_new (guint32 arrival_time, guint32 departure_time,
+ guint16 stop_sequence, gchar *stop_headsign,
+ MapsGTFSStopTimePickupDropOffType pickup_type,
+ MapsGTFSStopTimePickupDropOffType drop_off_type,
+ gfloat shape_dist_travelled)
+{
+ MapsGTFSStopTime *stop_time =
+ MAPS_GTFS_STOP_TIME (g_object_new (MAPS_TYPE_GTFS_STOP_TIME, NULL));
+ MapsGTFSStopTimePrivate *priv =
+ maps_gtfs_stop_time_get_instance_private (stop_time);
+
+ priv->arrival_time = arrival_time;
+ priv->departure_time_diff = departure_time - arrival_time;
+ priv->stop_sequence = stop_sequence;
+ priv->stop_headsign = g_strdup (stop_headsign);
+ priv->pickup_type = pickup_type;
+ priv->drop_off_type = drop_off_type;
+ priv->shape_dist_travelled = shape_dist_travelled;
+
+ return stop_time;
+}
+
+static void
+maps_gtfs_stop_time_finalize (GObject *object)
+{
+ MapsGTFSStopTime *self = (MapsGTFSStopTime *)object;
+ MapsGTFSStopTimePrivate *priv = maps_gtfs_stop_time_get_instance_private (self);
+
+ g_clear_pointer (&priv->stop_headsign, g_free);
+
+ G_OBJECT_CLASS (maps_gtfs_stop_time_parent_class)->finalize (object);
+}
+
+static void
+maps_gtfs_stop_time_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ MapsGTFSStopTime *self = MAPS_GTFS_STOP_TIME (object);
+ MapsGTFSStopTimePrivate *priv = maps_gtfs_stop_time_get_instance_private (self);
+
+ switch (prop_id)
+ {
+ case PROP_ARRIVAL_TIME:
+ g_value_set_uint (value, priv->arrival_time);
+ break;
+ case PROP_DEPARTURE_TIME:
+ g_value_set_uint (value, priv->arrival_time + priv->departure_time_diff);
+ break;
+ case PROP_STOP_SEQUENCE:
+ g_value_set_uint (value, priv->stop_sequence);
+ break;
+ case PROP_STOP_HEADSIGN:
+ g_value_set_string (value, priv->stop_headsign);
+ break;
+ case PROP_PICKUP_TYPE:
+ g_value_set_enum (value, priv->pickup_type);
+ break;
+ case PROP_DROP_OFF_TYPE:
+ g_value_set_enum (value, priv->drop_off_type);
+ break;
+ case PROP_SHAPE_DIST_TRAVELLED:
+ g_value_set_float (value, priv->shape_dist_travelled);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+maps_gtfs_stop_time_class_init (MapsGTFSStopTimeClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = maps_gtfs_stop_time_finalize;
+ object_class->get_property = maps_gtfs_stop_time_get_property;
+
+ properties[PROP_ARRIVAL_TIME] =
+ g_param_spec_uint ("arrival_time",
+ "Arrival time",
+ "Arrival time, in seconds since start of service day",
+ 0, G_MAXUINT32, 0,
+ G_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+ properties[PROP_DEPARTURE_TIME] =
+ g_param_spec_uint ("departue_time",
+ "Departure time",
+ "Departure time, in seconds since start of service day",
+ 0, G_MAXUINT32, 0,
+ G_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+ properties[PROP_STOP_SEQUENCE] =
+ g_param_spec_uint ("stop_sequence",
+ "Stop sequence",
+ "Order of stops for a particular trip. The values must increase along the trip but do
not need to be consecutive.",
+ 0, G_MAXUINT16, 0,
+ G_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+ properties[PROP_STOP_HEADSIGN] =
+ g_param_spec_string ("stop_headsign",
+ "Stop headsign",
+ "Text that appears on signage identifying the trip's destination to riders. This
field overrides the default in Trips",
+ NULL,
+ G_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+ properties[PROP_PICKUP_TYPE] =
+ g_param_spec_enum ("pickup_type",
+ "Pickup type",
+ "Indicates pickup method",
+ MAPS_TYPE_GTFS_STOP_TIME_PICKUP_DROP_OFF_TYPE,
+ MAPS_GTFS_STOP_TIME_REGULAR,
+ G_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+ properties[PROP_DROP_OFF_TYPE] =
+ g_param_spec_enum ("drop_off_type",
+ "Drop-off type",
+ "Indicates drop-off method",
+ MAPS_TYPE_GTFS_STOP_TIME_PICKUP_DROP_OFF_TYPE,
+ MAPS_GTFS_STOP_TIME_REGULAR,
+ G_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+ properties[PROP_SHAPE_DIST_TRAVELLED] =
+ g_param_spec_float ("shape_dist_travelled",
+ "Shape distance travelled",
+ "Actual distance traveled along the associated shape, from the first stop to the
stop specified in this record",
+ G_MINFLOAT,
+ G_MAXFLOAT,
+ G_MINFLOAT,
+ G_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+maps_gtfs_stop_time_init (MapsGTFSStopTime *self)
+{
+}
diff --git a/lib/maps-gtfs-stop-time.h b/lib/maps-gtfs-stop-time.h
new file mode 100644
index 00000000..ac16be69
--- /dev/null
+++ b/lib/maps-gtfs-stop-time.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2020 Marcus Lundblad
+ *
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, see <http://www.gnu.org/licenses/>
+ *
+ * Author: Marcus Lundblad <ml update uu se>
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/**
+ * MapsGTFSStopTimePickupDropOffType:
+ * @MAPS_GTFS_STOP_TIME_REGULAR: Regularly scheduled pickup/drop-off
+ * @MAPS_GTFS_STOP_TIME_NO: No pickup/drop-off available
+ * @MAPS_GTFS_STOP_TIME_PHONE: Must phone agency to arrange pickup/drop-off
+ * @MAPS_GTFS_STOP_TIME_COORDINATE: Must coordinate with driver to arrange pickup/drop-off
+ */
+typedef enum
+{
+ MAPS_GTFS_STOP_TIME_REGULAR,
+ MAPS_GTFS_STOP_TIME_NO,
+ MAPS_GTFS_STOP_TIME_PHONE,
+ MAPS_GTFS_STOP_TIME_COORDINATE
+} MapsGTFSStopTimePickupDropOffType;
+
+#define MAPS_TYPE_GTFS_STOP_TIME (maps_gtfs_stop_time_get_type())
+
+G_DECLARE_FINAL_TYPE (MapsGTFSStopTime, maps_gtfs_stop_time, MAPS, GTFS_STOP_TIME, GObject)
+
+MapsGTFSStopTime *maps_gtfs_stop_time_new (guint32 arrival_time,
+ guint32 departure_time,
+ guint16 stop_sequence,
+ gchar *stop_headsign,
+ MapsGTFSStopTimePickupDropOffType pickup_type,
+ MapsGTFSStopTimePickupDropOffType drop_off_type,
+ gfloat shape_dist_travelled);
+
+G_END_DECLS
diff --git a/lib/maps-gtfs-trip.c b/lib/maps-gtfs-trip.c
index cb79959f..70798ce4 100644
--- a/lib/maps-gtfs-trip.c
+++ b/lib/maps-gtfs-trip.c
@@ -37,6 +37,11 @@ G_DEFINE_TYPE_WITH_PRIVATE (MapsGTFSTrip, maps_gtfs_trip, G_TYPE_OBJECT)
enum {
PROP_0,
+ PROP_ROUTE_ID,
+ PROP_SERVICE_ID,
+ PROP_ID,
+ PROP_HEADSIGN,
+ PROP_SHORT_NAME,
N_PROPS
};
@@ -87,24 +92,25 @@ maps_gtfs_trip_get_property (GObject *object,
GParamSpec *pspec)
{
MapsGTFSTrip *self = MAPS_GTFS_TRIP (object);
+ MapsGTFSTripPrivate *priv = maps_gtfs_trip_get_instance_private (self);
switch (prop_id)
{
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-maps_gtfs_trip_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MapsGTFSTrip *self = MAPS_GTFS_TRIP (object);
-
- switch (prop_id)
- {
+ case PROP_ROUTE_ID:
+ g_value_set_string (value, priv->route_id);
+ break;
+ case PROP_SERVICE_ID:
+ g_value_set_string (value, priv->service_id);
+ break;
+ case PROP_ID:
+ g_value_set_string (value, priv->id);
+ break;
+ case PROP_HEADSIGN:
+ g_value_set_string (value, priv->headsign);
+ break;
+ case PROP_SHORT_NAME:
+ g_value_set_string (value, priv->short_name);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -117,7 +123,35 @@ maps_gtfs_trip_class_init (MapsGTFSTripClass *klass)
object_class->finalize = maps_gtfs_trip_finalize;
object_class->get_property = maps_gtfs_trip_get_property;
- object_class->set_property = maps_gtfs_trip_set_property;
+
+ properties[PROP_ROUTE_ID] =
+ g_param_spec_string ("route_id",
+ "Route ID", "Reference to the route",
+ NULL,
+ G_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+ properties[PROP_SERVICE_ID] =
+ g_param_spec_string ("service_id",
+ "Service ID", "Reference to calendar or calendar_date",
+ NULL,
+ G_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+ properties[PROP_ID] =
+ g_param_spec_string ("id",
+ "ID", "Unique identifier",
+ NULL,
+ G_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+ properties[PROP_HEADSIGN] =
+ g_param_spec_string ("headsign",
+ "Headsign",
+ "Destination sign for the trip, can be overridden in a StopTime",
+ NULL,
+ G_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+ properties[PROP_SHORT_NAME] =
+ g_param_spec_string ("short_name",
+ "Short name", "Identifier for the trip (e.g. a train number)",
+ NULL,
+ G_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
diff --git a/lib/maps.h b/lib/maps.h
index 949840a4..834d8a18 100644
--- a/lib/maps.h
+++ b/lib/maps.h
@@ -22,5 +22,6 @@
#include "maps-contact-store.h"
#include "maps-contact.h"
#include "maps-gtfs-stop.h"
+#include "maps-gtfs-stop-time.h"
#endif
diff --git a/lib/meson.build b/lib/meson.build
index ba8a918c..61011aed 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -7,6 +7,7 @@ headers_private = files(
'maps-gtfs-agency.h',
'maps-gtfs-route.h',
'maps-gtfs-stop.h',
+ 'maps-gtfs-stop-time.h',
'maps-gtfs-trip.h',
'maps-osm.h',
'maps-osm-changeset.h',
@@ -24,6 +25,7 @@ sources = files(
'maps-gtfs-agency.c',
'maps-gtfs-route.c',
'maps-gtfs-stop.c',
+ 'maps-gtfs-stop-time.c',
'maps-gtfs-trip.c',
'maps-osm.c',
'maps-osm-changeset.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]