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



commit bcac1fa13486de3bb12f6fb640418f43a671b9a9
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 | 111 ++++++++++++++++++++++++++++++++++++++++++++++
 lib/maps-gtfs-stop-time.h |  32 +++++++++++++
 lib/maps-gtfs-trip.c      |  66 ++++++++++++++++++++-------
 lib/meson.build           |   2 +
 4 files changed, 195 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..204b2321
--- /dev/null
+++ b/lib/maps-gtfs-stop-time.c
@@ -0,0 +1,111 @@
+/*
+ * 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"
+
+struct _MapsGTFSStopTime
+{
+  GObject parent_instance;
+};
+
+typedef struct
+{
+  guint16 arrival_time_mins;
+  guint8 arrival_time_secs;
+  guint16 departure_time_diff;
+  guint16 stop_sequence;
+  gchar *stop_headsign;
+  guint8 pickup_dropoff;
+  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 (void)
+{
+  return g_object_new (MAPS_TYPE_GTFS_STOP_TIME, NULL);
+}
+
+static void
+maps_gtfs_stop_time_finalize (GObject *object)
+{
+  MapsGTFSStopTime *self = (MapsGTFSStopTime *)object;
+
+  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);
+
+  switch (prop_id)
+    {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+maps_gtfs_stop_time_set_property (GObject      *object,
+                                  guint         prop_id,
+                                  const GValue *value,
+                                  GParamSpec   *pspec)
+{
+  MapsGTFSStopTime *self = MAPS_GTFS_STOP_TIME (object);
+
+  switch (prop_id)
+    {
+    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;
+  object_class->set_property = maps_gtfs_stop_time_set_property;
+}
+
+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..a05ce238
--- /dev/null
+++ b/lib/maps-gtfs-stop-time.h
@@ -0,0 +1,32 @@
+/*
+ * 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
+
+#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 (void);
+
+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/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]