source: branches/client-library-split/memphis-data-pool.c @ 97

Last change on this file since 97 was 97, checked in by simon, 5 years ago

use finalizers everywhere, some code cleanup

File size: 2.9 KB
Line 
1/*
2 * Memphis - Cairo Rederer for OSM in C
3 * Copyright (C) 2009  Simon Wenner <simon@wenner.ch>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19
20#include "memphis-data-pool.h"
21#include "mlib.h"
22
23G_DEFINE_TYPE (MemphisDataPool, memphis_data_pool, G_TYPE_OBJECT)
24
25#define GET_PRIVATE(o) \
26  (G_TYPE_INSTANCE_GET_PRIVATE ((o), MEMPHIS_TYPE_DATA_POOL, MemphisDataPoolPrivate))
27
28typedef struct _MemphisDataPoolPrivate MemphisDataPoolPrivate;
29
30struct _MemphisDataPoolPrivate {
31    int dummy;
32};
33
34static MemphisDataPool *instance = NULL;
35
36static void
37memphis_data_pool_get_property (GObject *object, guint property_id,
38                              GValue *value, GParamSpec *pspec)
39{
40  switch (property_id) {
41  default:
42    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
43  }
44}
45
46static void
47memphis_data_pool_set_property (GObject *object, guint property_id,
48                              const GValue *value, GParamSpec *pspec)
49{
50  switch (property_id) {
51  default:
52    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
53  }
54}
55
56static void
57memphis_data_pool_dispose (GObject *object)
58{
59  G_OBJECT_CLASS (memphis_data_pool_parent_class)->dispose (object);
60}
61
62static void
63memphis_data_pool_finalize (GObject *object)
64{
65  MemphisDataPool *self = (MemphisDataPool *) object;
66  g_tree_destroy (self->stringTree);
67  g_string_chunk_free (self->stringChunk);
68 
69  G_OBJECT_CLASS (memphis_data_pool_parent_class)->finalize (object);
70}
71
72static void
73memphis_data_pool_class_init (MemphisDataPoolClass *klass)
74{
75  GObjectClass *object_class = G_OBJECT_CLASS (klass);
76
77  g_type_class_add_private (klass, sizeof (MemphisDataPoolPrivate));
78
79  object_class->get_property = memphis_data_pool_get_property;
80  object_class->set_property = memphis_data_pool_set_property;
81  object_class->dispose = memphis_data_pool_dispose;
82  object_class->finalize = memphis_data_pool_finalize;
83}
84
85static void
86memphis_data_pool_init (MemphisDataPool *self)
87{
88  self->stringChunk = g_string_chunk_new (265);
89  self->stringTree = g_tree_new (m_tree_strcmp);
90}
91
92MemphisDataPool*
93memphis_data_pool_new (void)
94{
95  MemphisDataPool *pool;
96 
97  if (instance == NULL)
98    {
99      pool = g_object_new (MEMPHIS_TYPE_DATA_POOL, NULL);
100      instance = pool;
101    }
102  else
103    {
104      pool = g_object_ref (instance);
105    }
106
107  return pool;
108}
Note: See TracBrowser for help on using the repository browser.