evolution-3.6.4/widgets/table/e-table-memory.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-table-memory.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-table-memory.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /*
  2  * This program is free software; you can redistribute it and/or
  3  * modify it under the terms of the GNU Lesser General Public
  4  * License as published by the Free Software Foundation; either
  5  * version 2 of the License, or (at your option) version 3.
  6  *
  7  * This program is distributed in the hope that it will be useful,
  8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 10  * Lesser General Public License for more details.
 11  *
 12  * You should have received a copy of the GNU Lesser General Public
 13  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 14  *
 15  *
 16  * Authors:
 17  *		Chris Lahey <clahey@ximian.com>
 18  *
 19  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 20  *
 21  */
 22 
 23 #ifdef HAVE_CONFIG_H
 24 #include <config.h>
 25 #endif
 26 
 27 #include <stdio.h>
 28 #include <errno.h>
 29 #include <stdlib.h>
 30 #include <unistd.h>
 31 #include <fcntl.h>
 32 #include <string.h>
 33 
 34 #include <libxml/parser.h>
 35 #include <libxml/xmlmemory.h>
 36 
 37 #include "e-util/e-util.h"
 38 #include "libevolution-utils/e-xml-utils.h"
 39 
 40 #include "e-table-memory.h"
 41 
 42 #define E_TABLE_MEMORY_GET_PRIVATE(obj) \
 43 	(G_TYPE_INSTANCE_GET_PRIVATE \
 44 	((obj), E_TYPE_TABLE_MEMORY, ETableMemoryPrivate))
 45 
 46 G_DEFINE_TYPE (ETableMemory, e_table_memory, E_TYPE_TABLE_MODEL)
 47 
 48 struct _ETableMemoryPrivate {
 49 	gpointer *data;
 50 	gint num_rows;
 51 	gint frozen;
 52 };
 53 
 54 static void
 55 etmm_finalize (GObject *object)
 56 {
 57 	ETableMemoryPrivate *priv;
 58 
 59 	priv = E_TABLE_MEMORY_GET_PRIVATE (object);
 60 
 61 	g_free (priv->data);
 62 
 63 	/* Chain up to parent's finalize() method. */
 64 	G_OBJECT_CLASS (e_table_memory_parent_class)->finalize (object);
 65 }
 66 
 67 static gint
 68 etmm_row_count (ETableModel *etm)
 69 {
 70 	ETableMemory *etmm = E_TABLE_MEMORY (etm);
 71 
 72 	return etmm->priv->num_rows;
 73 }
 74 
 75 static void
 76 e_table_memory_class_init (ETableMemoryClass *class)
 77 {
 78 	GObjectClass *object_class;
 79 	ETableModelClass *table_model_class;
 80 
 81 	g_type_class_add_private (class, sizeof (ETableMemoryPrivate));
 82 
 83 	object_class = G_OBJECT_CLASS (class);
 84 	object_class->finalize = etmm_finalize;
 85 
 86 	table_model_class = E_TABLE_MODEL_CLASS (class);
 87 	table_model_class->row_count = etmm_row_count;
 88 }
 89 
 90 static void
 91 e_table_memory_init (ETableMemory *etmm)
 92 {
 93 	etmm->priv = E_TABLE_MEMORY_GET_PRIVATE (etmm);
 94 }
 95 
 96 /**
 97  * e_table_memory_new
 98  *
 99  * XXX docs here.
100  *
101  * return values: a newly constructed ETableMemory.
102  */
103 ETableMemory *
104 e_table_memory_new (void)
105 {
106 	return g_object_new (E_TYPE_TABLE_MEMORY, NULL);
107 }
108 
109 /**
110  * e_table_memory_get_data:
111  * @etmm:
112  * @row:
113  *
114  *
115  *
116  * Return value:
117  **/
118 gpointer
119 e_table_memory_get_data (ETableMemory *etmm,
120                          gint row)
121 {
122 	g_return_val_if_fail (row >= 0, NULL);
123 	g_return_val_if_fail (row < etmm->priv->num_rows, NULL);
124 
125 	return etmm->priv->data[row];
126 }
127 
128 /**
129  * e_table_memory_set_data:
130  * @etmm:
131  * @row:
132  * @data:
133  *
134  *
135  **/
136 void
137 e_table_memory_set_data (ETableMemory *etmm,
138                          gint row,
139                          gpointer data)
140 {
141 	g_return_if_fail (row >= 0);
142 	g_return_if_fail (row < etmm->priv->num_rows);
143 
144 	etmm->priv->data[row] = data;
145 }
146 
147 /**
148  * e_table_memory_insert:
149  * @table_model:
150  * @parent_path:
151  * @position:
152  * @data:
153  *
154  *
155  *
156  * Return value:
157  **/
158 void
159 e_table_memory_insert (ETableMemory *etmm,
160                        gint row,
161                        gpointer data)
162 {
163 	g_return_if_fail (row >= -1);
164 	g_return_if_fail (row <= etmm->priv->num_rows);
165 
166 	if (!etmm->priv->frozen)
167 		e_table_model_pre_change (E_TABLE_MODEL (etmm));
168 
169 	if (row == -1)
170 		row = etmm->priv->num_rows;
171 	etmm->priv->data = g_renew (gpointer, etmm->priv->data, etmm->priv->num_rows + 1);
172 	memmove (
173 		etmm->priv->data + row + 1,
174 		etmm->priv->data + row,
175 		(etmm->priv->num_rows - row) * sizeof (gpointer));
176 	etmm->priv->data[row] = data;
177 	etmm->priv->num_rows++;
178 	if (!etmm->priv->frozen)
179 		e_table_model_row_inserted (E_TABLE_MODEL (etmm), row);
180 }
181 
182 /**
183  * e_table_memory_remove:
184  * @etable:
185  * @path:
186  *
187  *
188  *
189  * Return value:
190  **/
191 gpointer
192 e_table_memory_remove (ETableMemory *etmm,
193                        gint row)
194 {
195 	gpointer ret;
196 
197 	g_return_val_if_fail (row >= 0, NULL);
198 	g_return_val_if_fail (row < etmm->priv->num_rows, NULL);
199 
200 	if (!etmm->priv->frozen)
201 		e_table_model_pre_change (E_TABLE_MODEL (etmm));
202 	ret = etmm->priv->data[row];
203 	memmove (
204 		etmm->priv->data + row,
205 		etmm->priv->data + row + 1,
206 		(etmm->priv->num_rows - row - 1) * sizeof (gpointer));
207 	etmm->priv->num_rows--;
208 	if (!etmm->priv->frozen)
209 		e_table_model_row_deleted (E_TABLE_MODEL (etmm), row);
210 	return ret;
211 }
212 
213 /**
214  * e_table_memory_clear:
215  * @etable:
216  * @path:
217  *
218  *
219  *
220  * Return value:
221  **/
222 void
223 e_table_memory_clear (ETableMemory *etmm)
224 {
225 	if (!etmm->priv->frozen)
226 		e_table_model_pre_change (E_TABLE_MODEL (etmm));
227 	g_free (etmm->priv->data);
228 	etmm->priv->data = NULL;
229 	etmm->priv->num_rows = 0;
230 	if (!etmm->priv->frozen)
231 		e_table_model_changed (E_TABLE_MODEL (etmm));
232 }
233 
234 /**
235  * e_table_memory_freeze:
236  * @etmm: the ETableModel to freeze.
237  *
238  * This function prepares an ETableModel for a period of much change.
239  * All signals regarding changes to the table are deferred until we
240  * thaw the table.
241  *
242  **/
243 void
244 e_table_memory_freeze (ETableMemory *etmm)
245 {
246 	ETableMemoryPrivate *priv = etmm->priv;
247 
248 	if (priv->frozen == 0)
249 		e_table_model_pre_change (E_TABLE_MODEL (etmm));
250 
251 	priv->frozen++;
252 }
253 
254 /**
255  * e_table_memory_thaw:
256  * @etmm: the ETableMemory to thaw.
257  *
258  * This function thaws an ETableMemory.  All the defered signals can add
259  * up to a lot, we don't know - so we just emit a model_changed
260  * signal.
261  *
262  **/
263 void
264 e_table_memory_thaw (ETableMemory *etmm)
265 {
266 	ETableMemoryPrivate *priv = etmm->priv;
267 
268 	if (priv->frozen > 0)
269 		priv->frozen--;
270 	if (priv->frozen == 0) {
271 		e_table_model_changed (E_TABLE_MODEL (etmm));
272 	}
273 }