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



commit f35fd059aed1475d54add9cafef9548b8f37cff7
Author: Marcus Lundblad <ml update uu se>
Date:   Thu Feb 27 23:50:12 2020 +0100

    WIP: Add class representing a trip in a GTFS feed

 lib/maps-gtfs-route.c |  19 ++++++++
 lib/maps-gtfs-route.h |  19 ++++++++
 lib/maps-gtfs-trip.c  | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/maps-gtfs-trip.h  |  39 ++++++++++++++++
 lib/meson.build       |   2 +
 5 files changed, 205 insertions(+)
---
diff --git a/lib/maps-gtfs-route.c b/lib/maps-gtfs-route.c
index 6beaf278..241d119b 100644
--- a/lib/maps-gtfs-route.c
+++ b/lib/maps-gtfs-route.c
@@ -1,3 +1,22 @@
+/*
+ * 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-route.h"
 
 struct _MapsGTFSRoute
diff --git a/lib/maps-gtfs-route.h b/lib/maps-gtfs-route.h
index 5e55d590..385a7a47 100644
--- a/lib/maps-gtfs-route.h
+++ b/lib/maps-gtfs-route.h
@@ -1,3 +1,22 @@
+/*
+ * 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>
diff --git a/lib/maps-gtfs-trip.c b/lib/maps-gtfs-trip.c
new file mode 100644
index 00000000..cb79959f
--- /dev/null
+++ b/lib/maps-gtfs-trip.c
@@ -0,0 +1,126 @@
+/*
+ * 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-trip.h"
+
+struct _MapsGTFSTrip
+{
+  GObject parent_instance;
+};
+
+typedef struct
+{
+  gchar *route_id;
+  gchar *service_id;
+  gchar *id;
+  gchar *headsign;
+  gchar *short_name;
+} MapsGTFSTripPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (MapsGTFSTrip, maps_gtfs_trip, G_TYPE_OBJECT)
+
+enum {
+  PROP_0,
+  N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+/**
+ * maps_gtfs_trip_new:
+ *
+ * Create a new #MapsGTFSTrip.
+ *
+ * Returns: (transfer full): a newly created #MapsGTFSTrip
+ */
+MapsGTFSTrip *
+maps_gtfs_trip_new (gchar *route_id, gchar *service_id, gchar *id,
+                    gchar *headsign, gchar *short_name, gchar *shape_id)
+{
+  MapsGTFSTrip *trip = MAPS_GTFS_TRIP (g_object_new (MAPS_TYPE_GTFS_TRIP, NULL));
+  MapsGTFSTripPrivate *priv = maps_gtfs_trip_get_instance_private (trip);
+
+  priv->route_id = g_strdup (route_id);
+  priv->service_id = g_strdup (service_id);
+  priv->id = g_strdup (id);
+  priv->headsign = g_strdup (headsign);
+  priv->short_name = g_strdup (short_name);
+
+  return trip;
+}
+
+static void
+maps_gtfs_trip_finalize (GObject *object)
+{
+  MapsGTFSTrip *self = (MapsGTFSTrip *)object;
+  MapsGTFSTripPrivate *priv = maps_gtfs_trip_get_instance_private (self);
+
+  g_clear_pointer (&priv->route_id, g_free);
+  g_clear_pointer (&priv->service_id, g_free);
+  g_clear_pointer (&priv->id, g_free);
+  g_clear_pointer (&priv->headsign, g_free);
+  g_clear_pointer (&priv->short_name, g_free);
+
+  G_OBJECT_CLASS (maps_gtfs_trip_parent_class)->finalize (object);
+}
+
+static void
+maps_gtfs_trip_get_property (GObject    *object,
+                             guint       prop_id,
+                             GValue     *value,
+                             GParamSpec *pspec)
+{
+  MapsGTFSTrip *self = MAPS_GTFS_TRIP (object);
+
+  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)
+    {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+maps_gtfs_trip_class_init (MapsGTFSTripClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (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;
+}
+
+static void
+maps_gtfs_trip_init (MapsGTFSTrip *self)
+{
+}
diff --git a/lib/maps-gtfs-trip.h b/lib/maps-gtfs-trip.h
new file mode 100644
index 00000000..2b4ec32b
--- /dev/null
+++ b/lib/maps-gtfs-trip.h
@@ -0,0 +1,39 @@
+/*
+ * 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_TRIP (maps_gtfs_trip_get_type())
+
+G_DECLARE_FINAL_TYPE (MapsGTFSTrip, maps_gtfs_trip, MAPS, GTFS_TRIP, GObject)
+
+struct _MapsGTFSTripClass
+{
+  GObjectClass parent_class;
+};
+
+MapsGTFSTrip *maps_gtfs_trip_new (gchar *route_id, gchar *service_id, gchar *id,
+                                  gchar *headsign, gchar *short_name,
+                                  gchar *shape_id);
+
+G_END_DECLS
diff --git a/lib/meson.build b/lib/meson.build
index 3ef5a3fe..ba8a918c 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-trip.h',
        'maps-osm.h',
        'maps-osm-changeset.h',
        'maps-osm-node.h',
@@ -23,6 +24,7 @@ sources = files(
        'maps-gtfs-agency.c',
        'maps-gtfs-route.c',
        'maps-gtfs-stop.c',
+       'maps-gtfs-trip.c',
        'maps-osm.c',
        'maps-osm-changeset.c',
        'maps-osm-node.c',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]