[gnome-maps/wip/mlundblad/transit-plugin-gtfs-local: 13/16] WIP: Add class representing a stop time in a GTFS feed



commit 3046797087ce0c5fb7dd5633b8347712543bd5a2
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 | 58 +++++++++++++++++++++++++++++++++++++++++
 lib/maps-gtfs-stop-time.h | 52 +++++++++++++++++++++++++++++++++++++
 lib/maps-gtfs-trip.c      | 66 +++++++++++++++++++++++++++++++++++------------
 lib/maps.h                |  1 +
 lib/meson.build           |  2 ++
 5 files changed, 163 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..b8c77e80
--- /dev/null
+++ b/lib/maps-gtfs-stop-time.c
@@ -0,0 +1,58 @@
+/*
+ * 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
+{
+  gchar *stop_headsign;
+  guint arrival_time : 20;
+  guint departure_time_diff : 10;
+  guint stop_sequence       : 10;
+  MapsGTFSStopTimePickupDropOffType pickup_type:2;
+  MapsGTFSStopTimePickupDropOffType drop_off_type:2;
+};
+
+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)
+{
+  MapsGTFSStopTime *stop_time = g_malloc (sizeof (MapsGTFSStopTime));
+
+  stop_time->arrival_time = arrival_time;
+  stop_time->departure_time_diff = departure_time - arrival_time;
+  stop_time->stop_sequence = stop_sequence;
+  stop_time->stop_headsign = g_strdup (stop_headsign);
+  stop_time->pickup_type = pickup_type;
+  stop_time->drop_off_type = drop_off_type;
+
+  return stop_time;
+}
+
+void
+maps_gtfs_stop_time_destroy (MapsGTFSStopTime *self)
+{
+  g_clear_pointer (&self->stop_headsign, g_free);
+}
+
diff --git a/lib/maps-gtfs-stop-time.h b/lib/maps-gtfs-stop-time.h
new file mode 100644
index 00000000..bf9e1b6b
--- /dev/null
+++ b/lib/maps-gtfs-stop-time.h
@@ -0,0 +1,52 @@
+/*
+ * 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.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;
+
+typedef struct _MapsGTFSStopTime MapsGTFSStopTime;
+
+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);
+
+void maps_gtfs_stop_time_destroy (MapsGTFSStopTime *self);
+
+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]