<commit_before>/*
 * Copyright (C) 2009 <NAME> <<EMAIL>>
 * Copyright (C) 2010-2012 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

/**
 * SECTION:champlain-map-source-factory
 * @short_description: Manages #ChamplainMapSource instances
 *
 * This factory manages the create of #ChamplainMapSource. It contains names
 * and constructor functions for each available map sources in libchamplain.
 * You can add your own with #champlain_map_source_factory_register.
 *
 * To get the wanted map source, use #champlain_map_source_factory_create. It
 * will return a ready to use #ChamplainMapSource.
 *
 * To get the list of registered map sources, use
 * #champlain_map_source_factory_get_registered.
 *
 */
#include "config.h"

#include "champlain-map-source-factory.h"

#define DEBUG_FLAG CHAMPLAIN_DEBUG_NETWORK
#include "champlain-debug.h"

#include "champlain.h"
#ifdef CHAMPLAIN_HAS_MEMPHIS
#include "champlain-memphis-renderer.h"
#endif
#include "champlain-file-cache.h"
#include "champlain-defines.h"
#include "champlain-enum-types.h"
#include "champlain-map-source.h"
#include "champlain-marshal.h"
#include "champlain-private.h"
#include "champlain-network-tile-source.h"
#include "champlain-map-source-chain.h"
#include "champlain-error-tile-renderer.h"
#include "champlain-image-renderer.h"
#include "champlain-file-tile-source.h"

#include <glib.h>
#include <string.h>

enum
{
  /* normal signals */
  LAST_SIGNAL
};

enum
{
  PROP_0,
};

/* static guint champlain_map_source_factory_signals[LAST_SIGNAL] = { 0, }; */
static ChamplainMapSourceFactory *instance = NULL;

G_DEFINE_TYPE (ChamplainMapSourceFactory, champlain_map_source_factory, G_TYPE_OBJECT);

#define GET_PRIVATE(obj) \
  (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CHAMPLAIN_TYPE_MAP_SOURCE_FACTORY, ChamplainMapSourceFactoryPrivate))

struct _ChamplainMapSourceFactoryPrivate
{
  GSList *registered_sources;
};

static ChamplainMapSource *champlain_map_source_new_generic (
    ChamplainMapSourceDesc *desc);

#ifdef CHAMPLAIN_HAS_MEMPHIS
static ChamplainMapSource *champlain_map_source_new_memphis (
    ChamplainMapSourceDesc *desc);
#endif


static void
champlain_map_source_factory_finalize (GObject *object)
{
  ChamplainMapSourceFactory *factory = CHAMPLAIN_MAP_SOURCE_FACTORY (object);

  g_slist_free (factory->priv->registered_sources);

  G_OBJECT_CLASS (champlain_map_source_factory_parent_class)->finalize (object);
}


static GObject *
champlain_map_source_factory_constructor (GType type,
    guint n_construct_params,
    GObjectConstructParam *construct_params)
{
  GObject *retval;

  if (instance == NULL)
    {
      retval = G_OBJECT_CLASS (champlain_map_source_factory_parent_class)->constructor
          (type, n_construct_params, construct_params);

      instance = CHAMPLAIN_MAP_SOURCE_FACTORY (retval);
      g_object_add_weak_pointer (retval, (gpointer *) &instance);
    }
  else
    {
      retval = g_object_ref (instance);
    }

  return retval;
}


static void
champlain_map_source_factory_class_init (ChamplainMapSourceFactoryClass *klass)
{
  g_type_class_add_private (klass, sizeof (ChamplainMapSourceFactoryPrivate));

  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->constructor = champlain_map_source_factory_constructor;
  object_class->finalize = champlain_map_source_factory_finalize;
}


static void
champlain_map_source_factory_init (ChamplainMapSourceFactory *factory)
{
  ChamplainMapSourceFactoryPrivate *priv = GET_PRIVATE (factory);
  ChamplainMapSourceDesc *desc;

  factory->priv = priv;
  priv->registered_sources = NULL;

  desc = champlain_map_source_desc_new_full (
        CHAMPLAIN_MAP_SOURCE_OSM_MAPNIK,
        "OpenStreetMap Mapnik",
        "Map data is CC-BY-SA 2.0 OpenStreetMap contributors",
        "http://creativecommons.org/licenses/by-sa/2.0/",
        0,
        18,
        256,
        CHAMPLAIN_MAP_PROJECTION_MERCATOR,
        "http://tile.openstreetmap.org/#Z#/#X#/#Y#.png",
        champlain_map_source_new_generic,
        NULL);
  champlain_map_source_factory_register (factory, desc);

  desc = champlain_map_source_desc_new_full (
        CHAMPLAIN_MAP_SOURCE_OSM_OSMARENDER,
        "OpenStreetMap Osmarender",
        "Map data is CC-BY-SA 2.0 OpenStreetMap contributors",
        "http://creativecommons.org/licenses/by-sa/2.0/",
        0,
        17,
        256,
        CHAMPLAIN_MAP_PROJECTION_MERCATOR,
        "http://tah.openstreetmap.org/Tiles/tile/#Z#/#X#/#Y#.png",
        champlain_map_source_new_generic,
        NULL);
  champlain_map_source_factory_register (factory, desc);

  desc = champlain_map_source_desc_new_full (
        CHAMPLAIN_MAP_SOURCE_OSM_MAPQUEST,
        "MapQuest OSM",
        "Data, imagery and map information provided by MapQuest, Open Street Map and contributors",
        "http://creativecommons.org/licenses/by-sa/2.0/",
        0,
        17,
        256,
        CHAMPLAIN_MAP_PROJECTION_MERCATOR,
        "http://otile1.mqcdn.com/tiles/1.0.0/osm/#Z#/#X#/#Y#.png",
        champlain_map_source_new_generic,
        NULL);
  champlain_map_source_factory_register (factory, desc);

  desc = champlain_map_source_desc_new_full (
        CHAMPLAIN_MAP_SOURCE_OSM_CYCLE_MAP,
        "OpenStreetMap Cycle Map",
        "Map data is CC-BY-SA 2.0 OpenStreetMap contributors",
        "http://creativecommons.org/licenses/by-sa/2.0/",
        0,
        18,
        256,
        CHAMPLAIN_MAP_PROJECTION_MERCATOR,
        "http://andy.sandbox.cloudmade.com/tiles/cycle/#Z#/#X#/#Y#.png",
        champlain_map_source_new_generic,
        NULL);
  champlain_map_source_factory_register (factory, desc);<commit_msg>fix osm cycle map source<commit_after>/*
 * Copyright (C) 2009 <NAME> <<EMAIL>>
 * Copyright (C) 2010-2012 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

/**
 * SECTION:champlain-map-source-factory
 * @short_description: Manages #ChamplainMapSource instances
 *
 * This factory manages the create of #ChamplainMapSource. It contains names
 * and constructor functions for each available map sources in libchamplain.
 * You can add your own with #champlain_map_source_factory_register.
 *
 * To get the wanted map source, use #champlain_map_source_factory_create. It
 * will return a ready to use #ChamplainMapSource.
 *
 * To get the list of registered map sources, use
 * #champlain_map_source_factory_get_registered.
 *
 */
#include "config.h"

#include "champlain-map-source-factory.h"

#define DEBUG_FLAG CHAMPLAIN_DEBUG_NETWORK
#include "champlain-debug.h"

#include "champlain.h"
#ifdef CHAMPLAIN_HAS_MEMPHIS
#include "champlain-memphis-renderer.h"
#endif
#include "champlain-file-cache.h"
#include "champlain-defines.h"
#include "champlain-enum-types.h"
#include "champlain-map-source.h"
#include "champlain-marshal.h"
#include "champlain-private.h"
#include "champlain-network-tile-source.h"
#include "champlain-map-source-chain.h"
#include "champlain-error-tile-renderer.h"
#include "champlain-image-renderer.h"
#include "champlain-file-tile-source.h"

#include <glib.h>
#include <string.h>

enum
{
  /* normal signals */
  LAST_SIGNAL
};

enum
{
  PROP_0,
};

/* static guint champlain_map_source_factory_signals[LAST_SIGNAL] = { 0, }; */
static ChamplainMapSourceFactory *instance = NULL;

G_DEFINE_TYPE (ChamplainMapSourceFactory, champlain_map_source_factory, G_TYPE_OBJECT);

#define GET_PRIVATE(obj) \
  (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CHAMPLAIN_TYPE_MAP_SOURCE_FACTORY, ChamplainMapSourceFactoryPrivate))

struct _ChamplainMapSourceFactoryPrivate
{
  GSList *registered_sources;
};

static ChamplainMapSource *champlain_map_source_new_generic (
    ChamplainMapSourceDesc *desc);

#ifdef CHAMPLAIN_HAS_MEMPHIS
static ChamplainMapSource *champlain_map_source_new_memphis (
    ChamplainMapSourceDesc *desc);
#endif


static void
champlain_map_source_factory_finalize (GObject *object)
{
  ChamplainMapSourceFactory *factory = CHAMPLAIN_MAP_SOURCE_FACTORY (object);

  g_slist_free (factory->priv->registered_sources);

  G_OBJECT_CLASS (champlain_map_source_factory_parent_class)->finalize (object);
}


static GObject *
champlain_map_source_factory_constructor (GType type,
    guint n_construct_params,
    GObjectConstructParam *construct_params)
{
  GObject *retval;

  if (instance == NULL)
    {
      retval = G_OBJECT_CLASS (champlain_map_source_factory_parent_class)->constructor
          (type, n_construct_params, construct_params);

      instance = CHAMPLAIN_MAP_SOURCE_FACTORY (retval);
      g_object_add_weak_pointer (retval, (gpointer *) &instance);
    }
  else
    {
      retval = g_object_ref (instance);
    }

  return retval;
}


static void
champlain_map_source_factory_class_init (ChamplainMapSourceFactoryClass *klass)
{
  g_type_class_add_private (klass, sizeof (ChamplainMapSourceFactoryPrivate));

  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->constructor = champlain_map_source_factory_constructor;
  object_class->finalize = champlain_map_source_factory_finalize;
}


static void
champlain_map_source_factory_init (ChamplainMapSourceFactory *factory)
{
  ChamplainMapSourceFactoryPrivate *priv = GET_PRIVATE (factory);
  ChamplainMapSourceDesc *desc;

  factory->priv = priv;
  priv->registered_sources = NULL;

  desc = champlain_map_source_desc_new_full (
        CHAMPLAIN_MAP_SOURCE_OSM_MAPNIK,
        "OpenStreetMap Mapnik",
        "Map data is CC-BY-SA 2.0 OpenStreetMap contributors",
        "http://creativecommons.org/licenses/by-sa/2.0/",
        0,
        18,
        256,
        CHAMPLAIN_MAP_PROJECTION_MERCATOR,
        "http://tile.openstreetmap.org/#Z#/#X#/#Y#.png",
        champlain_map_source_new_generic,
        NULL);
  champlain_map_source_factory_register (factory, desc);

  desc = champlain_map_source_desc_new_full (
        CHAMPLAIN_MAP_SOURCE_OSM_OSMARENDER,
        "OpenStreetMap Osmarender",
        "Map data is CC-BY-SA 2.0 OpenStreetMap contributors",
        "http://creativecommons.org/licenses/by-sa/2.0/",
        0,
        17,
        256,
        CHAMPLAIN_MAP_PROJECTION_MERCATOR,
        "http://a.tah.openstreetmap.org/Tiles/tile/#Z#/#X#/#Y#.png",
        champlain_map_source_new_generic,
        NULL);
  champlain_map_source_factory_register (factory, desc);

  desc = champlain_map_source_desc_new_full (
        CHAMPLAIN_MAP_SOURCE_OSM_MAPQUEST,
        "MapQuest OSM",
        "Data, imagery and map information provided by MapQuest, Open Street Map and contributors",
        "http://creativecommons.org/licenses/by-sa/2.0/",
        0,
        17,
        256,
        CHAMPLAIN_MAP_PROJECTION_MERCATOR,
        "http://otile1.mqcdn.com/tiles/1.0.0/osm/#Z#/#X#/#Y#.png",
        champlain_map_source_new_generic,
        NULL);
  champlain_map_source_factory_register (factory, desc);

  desc = champlain_map_source_desc_new_full (
        CHAMPLAIN_MAP_SOURCE_OSM_CYCLE_MAP,
        "OpenStreetMap Cycle Map",
        "Map data is CC-BY-SA 2.0 OpenStreetMap contributors",
        "http://creativecommons.org/licenses/by-sa/2.0/",
        0,
        18,
        256,
        CHAMPLAIN_MAP_PROJECTION_MERCATOR,
        "http://tile.opencyclemap.org/cycle/#Z#/#X#/#Y#.png",
        champlain_map_source_new_generic,
        NULL);
  champlain_map_source_factory_register (factory, desc);
{'fraction_non_alphanumeric': 0.09441552295314719, 'fraction_numerical': 0.010884997633696167, 'mean_word_length': 4.124898949070332, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1069920', 'n_tokens_mistral': 4399, 'n_tokens_neox': 4198, 'n_words': 895}