[gnome-maps/wip/mlundblad/transit-plugin-gtfs-local: 1/3] WIP: Add class representing a GTFS route



commit 3d4c9bee069d63282f4d74cfe9d48e028c72f3b0
Author: Marcus Lundblad <ml update uu se>
Date:   Wed Feb 26 23:30:21 2020 +0100

    WIP: Add class representing a GTFS route

 lib/maps-gtfs-route.c | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/maps-gtfs-route.h |  21 +++++++
 lib/meson.build       |   2 +
 3 files changed, 184 insertions(+)
---
diff --git a/lib/maps-gtfs-route.c b/lib/maps-gtfs-route.c
new file mode 100644
index 00000000..8cd40aaf
--- /dev/null
+++ b/lib/maps-gtfs-route.c
@@ -0,0 +1,161 @@
+#include "maps-gtfs-route.h"
+
+typedef struct
+{
+  gchar *id;
+  gchar *agency_id;
+  gchar *short_name;
+  gchar *long_name;
+  guint16 *type;
+  gchar *color;
+  gchar *text_color;
+} MapsGTFSRoutePrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (MapsGTFSRoute, maps_gtfs_route, G_TYPE_OBJECT)
+
+enum {
+  PROP_0,
+  PROP_ID,
+  PROP_AGENCY_ID,
+  PROP_SHORT_NAME,
+  PROP_LONG_NAME,
+  PROP_TYPE,
+  PROP_COLOR,
+  PROP_TEXT_COLOR,
+  N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+/**
+ * maps_gtfs_route_new:
+ *
+ * Create a new #MapsGTFSRoute.
+ *
+ * Returns: (transfer full): a newly created #MapsGTFSRoute
+ */
+MapsGTFSRoute *
+maps_gtfs_route_new (gchar *id, gchar *agency_id, gchar *short_name,
+                     gchar *long_name, guint16 type, gchar *color, gchar *text_color)
+{
+  MapsGTFSRoute *route =
+    MAPS_GTFS_ROUTE (g_object_new (MAPS_TYPE_GTFS_ROUTE, NULL));
+  MapsGTFSRoutePrivate *priv = maps_gtfs_route_get_instance_private (route);
+
+  priv->id = g_strdup (id);
+  priv->agency_id = g_strdup (agency_id);
+  priv->short_name = g_strdup (short_name);
+  priv->long_name = g_strdup (long_name);
+  priv->type = type;
+  priv->color = g_strdup (color);
+  priv->text_color = g_strdup (color);
+
+  return route;
+}
+
+static void
+maps_gtfs_route_finalize (GObject *object)
+{
+  MapsGTFSRoute *self = (MapsGTFSRoute *)object;
+  MapsGTFSRoutePrivate *priv = maps_gtfs_route_get_instance_private (self);
+
+  g_clear_pointer (&priv->id, g_free);
+  g_clear_pointer (&priv->agency_id, g_free);
+  g_clear_pointer (&priv->short_name, g_free);
+  g_clear_pointer (&priv->long_name, g_free);
+  g_clear_pointer (&priv->color, g_free);
+  g_clear_pointer (&priv->text_color, g_free);
+
+  G_OBJECT_CLASS (maps_gtfs_route_parent_class)->finalize (object);
+}
+
+static void
+maps_gtfs_route_get_property (GObject    *object,
+                              guint       prop_id,
+                              GValue     *value,
+                              GParamSpec *pspec)
+{
+  MapsGTFSRoute *self = MAPS_GTFS_ROUTE (object);
+
+  switch (prop_id)
+    {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+maps_gtfs_route_set_property (GObject      *object,
+                              guint         prop_id,
+                              const GValue *value,
+                              GParamSpec   *pspec)
+{
+  MapsGTFSRoute *self = MAPS_GTFS_ROUTE (object);
+
+  switch (prop_id)
+    {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+maps_gtfs_route_class_init (MapsGTFSRouteClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = maps_gtfs_route_finalize;
+  object_class->get_property = maps_gtfs_route_get_property;
+
+  properties[PROP_ID] =
+    g_param_spec_string ("id",
+                         "ID", "Unique identifier for stop",
+                         NULL,
+                         G_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+  properties[PROP_AGENCY_ID] =
+    g_param_spec_string ("agency_id",
+                         "Agency ID", "Reference to agency ID",
+                         NULL,
+                         G_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+  properties[PROP_SHORT_NAME] =
+    g_param_spec_string ("short_name",
+                         "Short name", "Short name, like 32, 100X, or Green",
+                         NULL,
+                         G_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+  properties[PROP_LONG_NAME] =
+    g_param_spec_string ("long_name",
+                         "Long name", "Long name",
+                         NULL,
+                         G_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+  properties[PROP_TYPE] =
+    g_param_spec_uint ("type",
+                       "Type", "Route type, GTFS or HVT route type code",
+                       0, 65535, 0,
+                       G_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+  properties[PROP_COLOR] =
+    g_param_spec_string ("color",
+                         "Color", "Color for the route",
+                         NULL,
+                         G_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+  properties[PROP_TEXT_COLOR] =
+    g_param_spec_string ("text_color",
+                         "Text color", "Text color for the route",
+                         NULL,
+                         G_PARAM_READABLE|G_PARAM_EXPLICIT_NOTIFY);
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+maps_gtfs_route_init (MapsGTFSRoute *self)
+{
+  MapsGTFSRoutePrivate *priv = maps_gtfs_route_get_instance_private (self);
+
+  priv->id = NULL;
+  priv->agency_id = NULL;
+  priv->short_name = NULL;
+  priv->long_name = NULL;
+  priv->type = 0;
+  priv->color = NULL;
+  priv->text_color = NULL;
+}
diff --git a/lib/maps-gtfs-route.h b/lib/maps-gtfs-route.h
new file mode 100644
index 00000000..f2b2f57f
--- /dev/null
+++ b/lib/maps-gtfs-route.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define MAPS_TYPE_GTFS_ROUTE (maps_gtfs_route_get_type())
+
+G_DECLARE_DERIVABLE_TYPE (MapsGTFSRoute, maps_gtfs_route, MAPS, GTFS_ROUTE, GObject)
+
+struct _MapsGTFSRouteClass
+{
+  GObjectClass parent_class;
+};
+
+MapsGTFSRoute *maps_gtfs_route_new (gchar *id, gchar *agency_id,
+                                    gchar *short_name,
+                                    gchar *long_name, guint16 type, gchar *color,
+                                    gchar *text_color);
+
+G_END_DECLS
diff --git a/lib/meson.build b/lib/meson.build
index 170d43d9..3ef5a3fe 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -5,6 +5,7 @@ headers_private = files(
        'maps-contact-store.h',
        'maps-file-tile-source.h',
        'maps-gtfs-agency.h',
+       'maps-gtfs-route.h',
        'maps-gtfs-stop.h',
        'maps-osm.h',
        'maps-osm-changeset.h',
@@ -20,6 +21,7 @@ sources = files(
        'maps-contact-store.c',
        'maps-file-tile-source.c',
        'maps-gtfs-agency.c',
+       'maps-gtfs-route.c',
        'maps-gtfs-stop.c',
        'maps-osm.c',
        'maps-osm-changeset.c',


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